package repository import ( "context" "errors" "time" "github.com/google/uuid" "github.com/jackc/pgx/v5" ) // HandoffCaseRow is HandoffCase catalog row. type HandoffCaseRow 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"` } // ListHandoffCases returns HandoffCase catalog. func (r *AdminRepo) ListHandoffCases(ctx context.Context) ([]HandoffCaseRow, error) { rows, err := r.Pool.Query(ctx, ` SELECT id, code, title, status, active, system, updated_at FROM ask_handoff_cases ORDER BY active DESC, code ASC LIMIT 500`) if err != nil { return nil, err } defer rows.Close() var out []HandoffCaseRow for rows.Next() { var row HandoffCaseRow 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() } // GetHandoffCase loads one by id. func (r *AdminRepo) GetHandoffCase(ctx context.Context, id uuid.UUID) (*HandoffCaseRow, error) { var row HandoffCaseRow err := r.Pool.QueryRow(ctx, ` SELECT id, code, title, status, active, system, updated_at FROM ask_handoff_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 }