fix: fix ui reports

This commit is contained in:
Krispire Admin
2026-06-16 19:03:06 +05:30
parent 1cde0c0544
commit a63ef672bb
6 changed files with 36 additions and 12 deletions
+13 -9
View File
@@ -219,6 +219,7 @@ func (r *AdminRepo) ListReports(ctx context.Context, reportType, q string, limit
SELECT r.id, r.category, r.reason, r.created_at, r.resolved_at,
ru.handle, ru.name,
r.post_id, p.caption, pu.handle,
r.resolution_note, COALESCE(p.deleted_at IS NOT NULL, false),
COUNT(*) OVER() AS total
FROM post_reports r
LEFT JOIN users ru ON ru.id = r.reporter_id
@@ -234,6 +235,7 @@ func (r *AdminRepo) ListReports(ctx context.Context, reportType, q string, limit
SELECT r.id, r.category, r.reason, r.created_at, r.resolved_at,
ru.handle, ru.name,
r.comment_id, c.body, cu.handle,
r.resolution_note, COALESCE(c.deleted_at IS NOT NULL, false),
COUNT(*) OVER() AS total
FROM comment_reports r
LEFT JOIN users ru ON ru.id = r.reporter_id
@@ -248,8 +250,9 @@ func (r *AdminRepo) ListReports(ctx context.Context, reportType, q string, limit
sql = `
SELECT r.id, r.category, r.reason, r.created_at, r.resolved_at,
ru.handle, ru.name,
r.reported_id, tu.handle, tu.handle
, COUNT(*) OVER() AS total
r.reported_id, tu.handle, tu.handle,
r.resolution_note, COALESCE(tu.banned_at IS NOT NULL, false),
COUNT(*) OVER() AS total
FROM user_reports r
LEFT JOIN users ru ON ru.id = r.reporter_id
LEFT JOIN users tu ON tu.id = r.reported_id
@@ -274,7 +277,8 @@ func (r *AdminRepo) ListReports(ctx context.Context, reportType, q string, limit
rep := model.AdminReport{Type: reportType}
if err := rows.Scan(&rep.ID, &rep.Category, &rep.Reason, &rep.CreatedAt, &rep.ResolvedAt,
&rep.ReporterHandle, &rep.ReporterName,
&rep.TargetID, &rep.TargetText, &rep.TargetAuthorHandle, &total); err != nil {
&rep.TargetID, &rep.TargetText, &rep.TargetAuthorHandle,
&rep.ResolutionNote, &rep.TargetRemoved, &total); err != nil {
return nil, 0, fmt.Errorf("scan admin report: %w", err)
}
out = append(out, rep)
@@ -282,10 +286,10 @@ func (r *AdminRepo) ListReports(ctx context.Context, reportType, q string, limit
return out, total, rows.Err()
}
// ResolveReport stamps resolved_at=now() on a still-open report of the given
// type. Idempotent and one-way (the WHERE guard). Returns true when this call
// is the one that resolved it.
func (r *AdminRepo) ResolveReport(ctx context.Context, reportType, id string) (bool, error) {
// ResolveReport stamps resolved_at=now() and stores the admin's note on a
// still-open report of the given type. Idempotent and one-way (the WHERE
// guard). Returns true when this call is the one that resolved it.
func (r *AdminRepo) ResolveReport(ctx context.Context, reportType, id, note string) (bool, error) {
var table string
switch reportType {
case "post":
@@ -299,8 +303,8 @@ func (r *AdminRepo) ResolveReport(ctx context.Context, reportType, id string) (b
}
// table is from a fixed whitelist above — safe to interpolate.
tag, err := r.pg.Pool.Exec(ctx,
fmt.Sprintf(`UPDATE %s SET resolved_at = now() WHERE id = $1 AND resolved_at IS NULL`, table),
id,
fmt.Sprintf(`UPDATE %s SET resolved_at = now(), resolution_note = $2 WHERE id = $1 AND resolved_at IS NULL`, table),
id, note,
)
if err != nil {
return false, fmt.Errorf("admin resolve %s report: %w", reportType, err)