feat(ECR-031): CrisisCare CrisisEvent 只读并 Closed

CrisisEvent catalog (000032) · Loop continuous.
This commit is contained in:
jackyu66git
2026-08-08 03:15:16 +08:00
parent 0d4bc5054e
commit 24a115297b
24 changed files with 453 additions and 1 deletions
@@ -0,0 +1,58 @@
package repository
import (
"context"
"errors"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
)
// CrisisEventRow is CrisisEvent catalog row.
type CrisisEventRow struct {
ID uuid.UUID `json:"id"`
Code string `json:"code"`
Title string `json:"title"`
Severity string `json:"severity"`
Active bool `json:"active"`
System bool `json:"system"`
UpdatedAt time.Time `json:"updated_at"`
}
// ListCrisisEvents returns CrisisEvent catalog.
func (r *AdminRepo) ListCrisisEvents(ctx context.Context) ([]CrisisEventRow, error) {
rows, err := r.Pool.Query(ctx, `
SELECT id, code, title, severity, active, system, updated_at
FROM crisis_events
ORDER BY active DESC, code ASC`)
if err != nil {
return nil, err
}
defer rows.Close()
var out []CrisisEventRow
for rows.Next() {
var row CrisisEventRow
if err := rows.Scan(&row.ID, &row.Code, &row.Title, &row.Severity, &row.Active, &row.System, &row.UpdatedAt); err != nil {
return nil, err
}
out = append(out, row)
}
return out, rows.Err()
}
// GetCrisisEvent loads one by id.
func (r *AdminRepo) GetCrisisEvent(ctx context.Context, id uuid.UUID) (*CrisisEventRow, error) {
var row CrisisEventRow
err := r.Pool.QueryRow(ctx, `
SELECT id, code, title, severity, active, system, updated_at
FROM crisis_events WHERE id=$1`, id,
).Scan(&row.ID, &row.Code, &row.Title, &row.Severity, &row.Active, &row.System, &row.UpdatedAt)
if errors.Is(err, pgx.ErrNoRows) {
return nil, err
}
if err != nil {
return nil, err
}
return &row, nil
}