package repository import ( "context" "errors" "time" "github.com/google/uuid" "github.com/jackc/pgx/v5" ) // InterventionOutcomeRow is InterventionOutcome catalog row. type InterventionOutcomeRow struct { ID uuid.UUID `json:"id"` Code string `json:"code"` Title string `json:"title"` Outcome string `json:"outcome"` Active bool `json:"active"` System bool `json:"system"` UpdatedAt time.Time `json:"updated_at"` } // ListInterventionOutcomes returns InterventionOutcome catalog. func (r *AdminRepo) ListInterventionOutcomes(ctx context.Context) ([]InterventionOutcomeRow, error) { rows, err := r.Pool.Query(ctx, ` SELECT id, code, title, outcome, active, system, updated_at FROM intervention_outcomes ORDER BY active DESC, code ASC`) if err != nil { return nil, err } defer rows.Close() var out []InterventionOutcomeRow for rows.Next() { var row InterventionOutcomeRow if err := rows.Scan(&row.ID, &row.Code, &row.Title, &row.Outcome, &row.Active, &row.System, &row.UpdatedAt); err != nil { return nil, err } out = append(out, row) } return out, rows.Err() } // GetInterventionOutcome loads one by id. func (r *AdminRepo) GetInterventionOutcome(ctx context.Context, id uuid.UUID) (*InterventionOutcomeRow, error) { var row InterventionOutcomeRow err := r.Pool.QueryRow(ctx, ` SELECT id, code, title, outcome, active, system, updated_at FROM intervention_outcomes WHERE id=$1`, id, ).Scan(&row.ID, &row.Code, &row.Title, &row.Outcome, &row.Active, &row.System, &row.UpdatedAt) if errors.Is(err, pgx.ErrNoRows) { return nil, err } if err != nil { return nil, err } return &row, nil }