start reports/moderation in backend
This commit is contained in:
parent
41edaee8ea
commit
33f903b07d
8 changed files with 136 additions and 2 deletions
47
backend/db/report.go
Normal file
47
backend/db/report.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"emperror.dev/errors"
|
||||
"github.com/georgysavva/scany/pgxscan"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
type Report struct {
|
||||
ID int64
|
||||
UserID xid.ID
|
||||
MemberID *xid.ID
|
||||
Reason string
|
||||
ReporterID xid.ID
|
||||
|
||||
CreatedAt time.Time
|
||||
ResolvedAt *time.Time
|
||||
AdminID *xid.ID
|
||||
AdminComment *string
|
||||
}
|
||||
|
||||
const reportPageSize = 100
|
||||
|
||||
func (db *DB) Reports(ctx context.Context, closed bool, page int) (rs []Report, err error) {
|
||||
builder := sq.Select("*").From("reports").Offset(uint64(reportPageSize * page)).Limit(reportPageSize).OrderBy("id ASC")
|
||||
if closed {
|
||||
builder = builder.Where("resolved_at IS NOT NULL")
|
||||
} else {
|
||||
builder = builder.Where("resolved_at IS NULL")
|
||||
}
|
||||
sql, args, err := builder.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "building sql")
|
||||
}
|
||||
|
||||
err = pgxscan.Select(ctx, db, &rs, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "executing query")
|
||||
}
|
||||
if len(rs) == 0 {
|
||||
return []Report{}, nil
|
||||
}
|
||||
return rs, nil
|
||||
}
|
|
@ -34,6 +34,7 @@ type User struct {
|
|||
FediverseInstance *string
|
||||
|
||||
MaxInvites int
|
||||
IsAdmin bool
|
||||
|
||||
DeletedAt *time.Time
|
||||
SelfDelete *bool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue