diff options
author | FChannel <> | 2022-04-30 11:00:55 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 1892327cee2c3fa1d3bea729bd08eb63c2189a96 (patch) | |
tree | 7b846f7d9caf46fba6c9d15ff81b9d89dcca9476 /db/report.go | |
parent | 5b52d269faa2ce2014d0feba603a2122361cf4eb (diff) |
restructured code base to prevent circular dependicies
Diffstat (limited to 'db/report.go')
-rw-r--r-- | db/report.go | 75 |
1 files changed, 11 insertions, 64 deletions
diff --git a/db/report.go b/db/report.go index a64c94f..4120d9a 100644 --- a/db/report.go +++ b/db/report.go @@ -1,5 +1,7 @@ package db +import "github.com/FChannel0/FChannel-Server/config" + type Report struct { ID string Count int @@ -12,65 +14,10 @@ type Removed struct { Board string } -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 -} - func CreateLocalDeleteDB(id string, _type string) error { query := `select id from removed where id=$1` - rows, err := db.Query(query, id) + rows, err := config.DB.Query(query, id) if err != nil { return err } @@ -86,14 +33,14 @@ func CreateLocalDeleteDB(id string, _type string) error { if i != "" { query := `update removed set type=$1 where id=$2` - if _, err := db.Exec(query, _type, id); err != nil { + if _, err := config.DB.Exec(query, _type, id); err != nil { return err } } } else { query := `insert into removed (id, type) values ($1, $2)` - if _, err := db.Exec(query, id, _type); err != nil { + if _, err := config.DB.Exec(query, id, _type); err != nil { return err } } @@ -106,7 +53,7 @@ func GetLocalDeleteDB() ([]Removed, error) { query := `select id, type from removed` - rows, err := db.Query(query) + rows, err := config.DB.Query(query) if err != nil { return deleted, err } @@ -129,7 +76,7 @@ func GetLocalDeleteDB() ([]Removed, error) { func CreateLocalReportDB(id string, board string, reason string) error { query := `select id, count from reported where id=$1 and board=$2` - rows, err := db.Query(query, id, board) + rows, err := config.DB.Query(query, id, board) if err != nil { return err } @@ -147,14 +94,14 @@ func CreateLocalReportDB(id string, board string, reason string) error { count = count + 1 query := `update reported set count=$1 where id=$2` - if _, err := db.Exec(query, count, id); err != nil { + if _, err := config.DB.Exec(query, count, id); err != nil { return err } } } else { query := `insert into reported (id, count, board, reason) values ($1, $2, $3, $4)` - if _, err := db.Exec(query, id, 1, board, reason); err != nil { + if _, err := config.DB.Exec(query, id, 1, board, reason); err != nil { return err } } @@ -167,7 +114,7 @@ func GetLocalReportDB(board string) ([]Report, error) { query := `select id, count, reason from reported where board=$1` - rows, err := db.Query(query, board) + rows, err := config.DB.Query(query, board) if err != nil { return reported, err } @@ -189,6 +136,6 @@ func GetLocalReportDB(board string) ([]Report, error) { func CloseLocalReportDB(id string, board string) error { query := `delete from reported where id=$1 and board=$2` - _, err := db.Exec(query, id, board) + _, err := config.DB.Exec(query, id, board) return err } |