feat(ECR-033): AskOperations HandoffCase 只读并 Closed

HandoffCase catalog (000034) · Loop continuous.
This commit is contained in:
jackyu66git
2026-08-08 03:15:45 +08:00
parent 01063208a1
commit 487bee78d1
25 changed files with 457 additions and 1 deletions
@@ -0,0 +1,58 @@
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`)
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
}