feat(ECR-030): ContentSafety ModerationCase 只读并 Closed
ModerationCase catalog (000031) · Loop continuous.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
// ModerationCaseRow is ModerationCase catalog row.
|
||||
type ModerationCaseRow struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Title string `json:"title"`
|
||||
Status string `json:"status"`
|
||||
Active bool `json:"active"`
|
||||
System bool `json:"system"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// ListModerationCases returns ModerationCase catalog.
|
||||
func (r *AdminRepo) ListModerationCases(ctx context.Context) ([]ModerationCaseRow, error) {
|
||||
rows, err := r.Pool.Query(ctx, `
|
||||
SELECT id, code, title, status, active, system, updated_at
|
||||
FROM moderation_cases
|
||||
ORDER BY active DESC, code ASC`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []ModerationCaseRow
|
||||
for rows.Next() {
|
||||
var row ModerationCaseRow
|
||||
if err := rows.Scan(&row.ID, &row.Code, &row.Title, &row.Status, &row.Active, &row.System, &row.UpdatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, row)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// GetModerationCase loads one by id.
|
||||
func (r *AdminRepo) GetModerationCase(ctx context.Context, id uuid.UUID) (*ModerationCaseRow, error) {
|
||||
var row ModerationCaseRow
|
||||
err := r.Pool.QueryRow(ctx, `
|
||||
SELECT id, code, title, status, active, system, updated_at
|
||||
FROM moderation_cases WHERE id=$1`, id,
|
||||
).Scan(&row.ID, &row.Code, &row.Title, &row.Status, &row.Active, &row.System, &row.UpdatedAt)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, err
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &row, nil
|
||||
}
|
||||
Reference in New Issue
Block a user