457 lines
10 KiB
Go
457 lines
10 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: admin.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const campaignSlugByID = `-- name: CampaignSlugByID :one
|
|
SELECT slug FROM campaigns WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) CampaignSlugByID(ctx context.Context, id string) (string, error) {
|
|
row := q.db.QueryRow(ctx, campaignSlugByID, id)
|
|
var slug string
|
|
err := row.Scan(&slug)
|
|
return slug, err
|
|
}
|
|
|
|
const countCampaignPledges = `-- name: CountCampaignPledges :one
|
|
SELECT COUNT(*)::int FROM pledges WHERE campaign_id = $1
|
|
`
|
|
|
|
func (q *Queries) CountCampaignPledges(ctx context.Context, campaignID string) (int, error) {
|
|
row := q.db.QueryRow(ctx, countCampaignPledges, campaignID)
|
|
var column_1 int
|
|
err := row.Scan(&column_1)
|
|
return column_1, err
|
|
}
|
|
|
|
const deleteCampaign = `-- name: DeleteCampaign :execrows
|
|
DELETE FROM campaigns WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteCampaign(ctx context.Context, id string) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteCampaign, id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const deleteStorySections = `-- name: DeleteStorySections :exec
|
|
DELETE FROM story_sections WHERE campaign_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteStorySections(ctx context.Context, campaignID string) error {
|
|
_, err := q.db.Exec(ctx, deleteStorySections, campaignID)
|
|
return err
|
|
}
|
|
|
|
const deleteTier = `-- name: DeleteTier :exec
|
|
DELETE FROM reward_tiers WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteTier(ctx context.Context, id string) error {
|
|
_, err := q.db.Exec(ctx, deleteTier, id)
|
|
return err
|
|
}
|
|
|
|
const getAdminCampaign = `-- name: GetAdminCampaign :one
|
|
SELECT id, slug, title, category, summary, art, goal_amount,
|
|
ends_at, status::text AS status, owner_id
|
|
FROM campaigns
|
|
WHERE slug = $1
|
|
`
|
|
|
|
type GetAdminCampaignRow struct {
|
|
ID string
|
|
Slug string
|
|
Title string
|
|
Category string
|
|
Summary string
|
|
Art string
|
|
GoalAmount int
|
|
EndsAt time.Time
|
|
Status string
|
|
OwnerID string
|
|
}
|
|
|
|
func (q *Queries) GetAdminCampaign(ctx context.Context, slug string) (GetAdminCampaignRow, error) {
|
|
row := q.db.QueryRow(ctx, getAdminCampaign, slug)
|
|
var i GetAdminCampaignRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Slug,
|
|
&i.Title,
|
|
&i.Category,
|
|
&i.Summary,
|
|
&i.Art,
|
|
&i.GoalAmount,
|
|
&i.EndsAt,
|
|
&i.Status,
|
|
&i.OwnerID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getTier = `-- name: GetTier :one
|
|
SELECT id, type::text AS type, price, list_price, title, includes,
|
|
inventory_limit, estimated_delivery, featured
|
|
FROM reward_tiers
|
|
WHERE id = $1
|
|
`
|
|
|
|
type GetTierRow struct {
|
|
ID string
|
|
Type string
|
|
Price int
|
|
ListPrice *int
|
|
Title string
|
|
Includes []string
|
|
InventoryLimit *int
|
|
EstimatedDelivery *time.Time
|
|
Featured bool
|
|
}
|
|
|
|
func (q *Queries) GetTier(ctx context.Context, id string) (GetTierRow, error) {
|
|
row := q.db.QueryRow(ctx, getTier, id)
|
|
var i GetTierRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Type,
|
|
&i.Price,
|
|
&i.ListPrice,
|
|
&i.Title,
|
|
&i.Includes,
|
|
&i.InventoryLimit,
|
|
&i.EstimatedDelivery,
|
|
&i.Featured,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertStorySection = `-- name: InsertStorySection :exec
|
|
INSERT INTO story_sections (id, campaign_id, heading, body, position)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
`
|
|
|
|
type InsertStorySectionParams struct {
|
|
ID string
|
|
CampaignID string
|
|
Heading string
|
|
Body []string
|
|
Position int
|
|
}
|
|
|
|
func (q *Queries) InsertStorySection(ctx context.Context, arg InsertStorySectionParams) error {
|
|
_, err := q.db.Exec(ctx, insertStorySection,
|
|
arg.ID,
|
|
arg.CampaignID,
|
|
arg.Heading,
|
|
arg.Body,
|
|
arg.Position,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const insertTier = `-- name: InsertTier :exec
|
|
INSERT INTO reward_tiers (id, campaign_id, type, price, list_price, title,
|
|
includes, inventory_limit, estimated_delivery,
|
|
featured, position)
|
|
VALUES ($1, $2, $3::tier_type, $4, $5, $6,
|
|
$7, $8, $9, $10, $11)
|
|
`
|
|
|
|
type InsertTierParams struct {
|
|
ID string
|
|
CampaignID string
|
|
Type string
|
|
Price int
|
|
ListPrice *int
|
|
Title string
|
|
Includes []string
|
|
InventoryLimit *int
|
|
EstimatedDelivery *time.Time
|
|
Featured bool
|
|
Position int
|
|
}
|
|
|
|
func (q *Queries) InsertTier(ctx context.Context, arg InsertTierParams) error {
|
|
_, err := q.db.Exec(ctx, insertTier,
|
|
arg.ID,
|
|
arg.CampaignID,
|
|
arg.Type,
|
|
arg.Price,
|
|
arg.ListPrice,
|
|
arg.Title,
|
|
arg.Includes,
|
|
arg.InventoryLimit,
|
|
arg.EstimatedDelivery,
|
|
arg.Featured,
|
|
arg.Position,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const listAdminCampaigns = `-- name: ListAdminCampaigns :many
|
|
|
|
SELECT c.id, c.slug, c.title, c.status::text AS status, c.goal_amount, o.name,
|
|
(SELECT COUNT(*) FROM pledges p WHERE p.campaign_id = c.id)::int AS pledge_count
|
|
FROM campaigns c
|
|
JOIN owners o ON o.id = c.owner_id
|
|
ORDER BY c.created_at DESC
|
|
`
|
|
|
|
type ListAdminCampaignsRow struct {
|
|
ID string
|
|
Slug string
|
|
Title string
|
|
Status string
|
|
GoalAmount int
|
|
Name string
|
|
PledgeCount int
|
|
}
|
|
|
|
// The campaign editor. Everything here is behind an admin session.
|
|
func (q *Queries) ListAdminCampaigns(ctx context.Context) ([]ListAdminCampaignsRow, error) {
|
|
rows, err := q.db.Query(ctx, listAdminCampaigns)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListAdminCampaignsRow
|
|
for rows.Next() {
|
|
var i ListAdminCampaignsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Slug,
|
|
&i.Title,
|
|
&i.Status,
|
|
&i.GoalAmount,
|
|
&i.Name,
|
|
&i.PledgeCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listAdminTiers = `-- name: ListAdminTiers :many
|
|
SELECT t.id, t.type::text AS type, t.price, t.list_price, t.title, t.includes,
|
|
t.inventory_limit, t.estimated_delivery, t.featured,
|
|
(SELECT COUNT(*) FROM pledges p WHERE p.tier_id = t.id)::int AS pledge_count
|
|
FROM reward_tiers t
|
|
WHERE t.campaign_id = $1
|
|
ORDER BY t.position ASC
|
|
`
|
|
|
|
type ListAdminTiersRow struct {
|
|
ID string
|
|
Type string
|
|
Price int
|
|
ListPrice *int
|
|
Title string
|
|
Includes []string
|
|
InventoryLimit *int
|
|
EstimatedDelivery *time.Time
|
|
Featured bool
|
|
PledgeCount int
|
|
}
|
|
|
|
func (q *Queries) ListAdminTiers(ctx context.Context, campaignID string) ([]ListAdminTiersRow, error) {
|
|
rows, err := q.db.Query(ctx, listAdminTiers, campaignID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListAdminTiersRow
|
|
for rows.Next() {
|
|
var i ListAdminTiersRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Type,
|
|
&i.Price,
|
|
&i.ListPrice,
|
|
&i.Title,
|
|
&i.Includes,
|
|
&i.InventoryLimit,
|
|
&i.EstimatedDelivery,
|
|
&i.Featured,
|
|
&i.PledgeCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listOwners = `-- name: ListOwners :many
|
|
SELECT id, name, COALESCE(avatar_url, '') AS avatar_url
|
|
FROM owners
|
|
ORDER BY name ASC
|
|
`
|
|
|
|
type ListOwnersRow struct {
|
|
ID string
|
|
Name string
|
|
AvatarUrl string
|
|
}
|
|
|
|
func (q *Queries) ListOwners(ctx context.Context) ([]ListOwnersRow, error) {
|
|
rows, err := q.db.Query(ctx, listOwners)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListOwnersRow
|
|
for rows.Next() {
|
|
var i ListOwnersRow
|
|
if err := rows.Scan(&i.ID, &i.Name, &i.AvatarUrl); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listTierPledgeCounts = `-- name: ListTierPledgeCounts :many
|
|
SELECT t.id, (SELECT COUNT(*) FROM pledges p WHERE p.tier_id = t.id)::int AS pledge_count
|
|
FROM reward_tiers t
|
|
WHERE t.campaign_id = $1
|
|
`
|
|
|
|
type ListTierPledgeCountsRow struct {
|
|
ID string
|
|
PledgeCount int
|
|
}
|
|
|
|
func (q *Queries) ListTierPledgeCounts(ctx context.Context, campaignID string) ([]ListTierPledgeCountsRow, error) {
|
|
rows, err := q.db.Query(ctx, listTierPledgeCounts, campaignID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListTierPledgeCountsRow
|
|
for rows.Next() {
|
|
var i ListTierPledgeCountsRow
|
|
if err := rows.Scan(&i.ID, &i.PledgeCount); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const parkTierPosition = `-- name: ParkTierPosition :exec
|
|
UPDATE reward_tiers SET position = $1 WHERE id = $2
|
|
`
|
|
|
|
type ParkTierPositionParams struct {
|
|
Position int
|
|
ID string
|
|
}
|
|
|
|
func (q *Queries) ParkTierPosition(ctx context.Context, arg ParkTierPositionParams) error {
|
|
_, err := q.db.Exec(ctx, parkTierPosition, arg.Position, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const updateCampaign = `-- name: UpdateCampaign :execrows
|
|
UPDATE campaigns
|
|
SET slug = $1, title = $2, category = $3, summary = $4,
|
|
art = $5, goal_amount = $6, ends_at = $7,
|
|
status = $8::campaign_status, owner_id = $9, updated_at = now()
|
|
WHERE id = $10
|
|
`
|
|
|
|
type UpdateCampaignParams struct {
|
|
Slug string
|
|
Title string
|
|
Category string
|
|
Summary string
|
|
Art string
|
|
GoalAmount int
|
|
EndsAt time.Time
|
|
Status string
|
|
OwnerID string
|
|
ID string
|
|
}
|
|
|
|
func (q *Queries) UpdateCampaign(ctx context.Context, arg UpdateCampaignParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, updateCampaign,
|
|
arg.Slug,
|
|
arg.Title,
|
|
arg.Category,
|
|
arg.Summary,
|
|
arg.Art,
|
|
arg.GoalAmount,
|
|
arg.EndsAt,
|
|
arg.Status,
|
|
arg.OwnerID,
|
|
arg.ID,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const updateTier = `-- name: UpdateTier :exec
|
|
UPDATE reward_tiers
|
|
SET type = $1::tier_type, price = $2, list_price = $3,
|
|
title = $4, includes = $5, inventory_limit = $6,
|
|
estimated_delivery = $7, featured = $8,
|
|
position = $9
|
|
WHERE id = $10
|
|
`
|
|
|
|
type UpdateTierParams struct {
|
|
Type string
|
|
Price int
|
|
ListPrice *int
|
|
Title string
|
|
Includes []string
|
|
InventoryLimit *int
|
|
EstimatedDelivery *time.Time
|
|
Featured bool
|
|
Position int
|
|
ID string
|
|
}
|
|
|
|
func (q *Queries) UpdateTier(ctx context.Context, arg UpdateTierParams) error {
|
|
_, err := q.db.Exec(ctx, updateTier,
|
|
arg.Type,
|
|
arg.Price,
|
|
arg.ListPrice,
|
|
arg.Title,
|
|
arg.Includes,
|
|
arg.InventoryLimit,
|
|
arg.EstimatedDelivery,
|
|
arg.Featured,
|
|
arg.Position,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|