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