diff options
author | KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> | 2021-10-30 00:28:51 -0300 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 8040825daac4a5ba24e947c4c657d169d7763543 (patch) | |
tree | 667058707ab1c2b2af5dc01decda25cc7709f9df /db/report.go | |
parent | f76b8093b9ca69c7d4eca747d8c5d702d492e1fb (diff) |
restructuring, part 3 of many
Diffstat (limited to 'db/report.go')
-rw-r--r-- | db/report.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/db/report.go b/db/report.go new file mode 100644 index 0000000..4fcb806 --- /dev/null +++ b/db/report.go @@ -0,0 +1,56 @@ +package db + +func DeleteReportActivity(id string) error { + query := `delete from reported where id=$1` + + _, err := db.Exec(query, id) + return err +} + +func ReportActivity(id string, reason string) (bool, error) { + if res, err := IsIDLocal(id); err == nil && !res { + // TODO: not local error + return false, nil + } else if err != nil { + return false, err + } + + actor, err := GetActivityFromDB(id) + if err != nil { + return false, err + } + + query := `select count from reported where id=$1` + + rows, err := db.Query(query, id) + if err != nil { + return false, err + } + defer rows.Close() + + var count int + for rows.Next() { + if err := rows.Scan(&count); err != nil { + return false, err + } + } + + if count < 1 { + query = `insert into reported (id, count, board, reason) values ($1, $2, $3, $4)` + + _, err := db.Exec(query, id, 1, actor.Actor.Id, reason) + if err != nil { + return false, err + } + } else { + count = count + 1 + query = `update reported set count=$1 where id=$2` + + _, err := db.Exec(query, count, id) + if err != nil { + return false, err + } + } + + return true, nil +} |