package repository import ( "context" "errors" "time" "github.com/google/uuid" "github.com/jackc/pgx/v5" ) // PrivacyRequestRow is PrivacyRequest catalog row. type PrivacyRequestRow struct { ID uuid.UUID `json:"id"` Code string `json:"code"` Title string `json:"title"` Kind string `json:"kind"` Status string `json:"status"` Active bool `json:"active"` System bool `json:"system"` UpdatedAt time.Time `json:"updated_at"` } // ListPrivacyRequests returns PrivacyRequest catalog. func (r *AdminRepo) ListPrivacyRequests(ctx context.Context) ([]PrivacyRequestRow, error) { rows, err := r.Pool.Query(ctx, ` SELECT id, code, title, kind, status, active, system, updated_at FROM privacy_requests ORDER BY active DESC, code ASC LIMIT 500`) if err != nil { return nil, err } defer rows.Close() var out []PrivacyRequestRow for rows.Next() { var row PrivacyRequestRow if err := rows.Scan(&row.ID, &row.Code, &row.Title, &row.Kind, &row.Status, &row.Active, &row.System, &row.UpdatedAt); err != nil { return nil, err } out = append(out, row) } return out, rows.Err() } // GetPrivacyRequest loads one by id. func (r *AdminRepo) GetPrivacyRequest(ctx context.Context, id uuid.UUID) (*PrivacyRequestRow, error) { var row PrivacyRequestRow err := r.Pool.QueryRow(ctx, ` SELECT id, code, title, kind, status, active, system, updated_at FROM privacy_requests WHERE id=$1`, id, ).Scan(&row.ID, &row.Code, &row.Title, &row.Kind, &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 }