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