Yimaru-BackEnd/gen/db/raffle.sql.go

329 lines
7.8 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: raffle.sql
package dbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const AddSportRaffleFilter = `-- name: AddSportRaffleFilter :one
INSERT INTO raffle_sport_filters (raffle_id, sport_id, league_id)
VALUES ($1, $2, $3)
RETURNING id, raffle_id, sport_id, league_id
`
type AddSportRaffleFilterParams struct {
RaffleID int32 `json:"raffle_id"`
SportID int64 `json:"sport_id"`
LeagueID int64 `json:"league_id"`
}
func (q *Queries) AddSportRaffleFilter(ctx context.Context, arg AddSportRaffleFilterParams) (RaffleSportFilter, error) {
row := q.db.QueryRow(ctx, AddSportRaffleFilter, arg.RaffleID, arg.SportID, arg.LeagueID)
var i RaffleSportFilter
err := row.Scan(
&i.ID,
&i.RaffleID,
&i.SportID,
&i.LeagueID,
)
return i, err
}
const CheckValidSportRaffleFilter = `-- name: CheckValidSportRaffleFilter :one
SELECT COUNT(*) > 0 AS exists
FROM raffle_sport_filters
WHERE raffle_id = $1
AND sport_id = $2
AND league_id = $3
`
type CheckValidSportRaffleFilterParams struct {
RaffleID int32 `json:"raffle_id"`
SportID int64 `json:"sport_id"`
LeagueID int64 `json:"league_id"`
}
func (q *Queries) CheckValidSportRaffleFilter(ctx context.Context, arg CheckValidSportRaffleFilterParams) (bool, error) {
row := q.db.QueryRow(ctx, CheckValidSportRaffleFilter, arg.RaffleID, arg.SportID, arg.LeagueID)
var exists bool
err := row.Scan(&exists)
return exists, err
}
const CreateRaffle = `-- name: CreateRaffle :one
INSERT INTO raffles (company_id, name, expires_at, type)
VALUES ($1, $2, $3, $4)
RETURNING id, company_id, name, created_at, expires_at, type, status
`
type CreateRaffleParams struct {
CompanyID int32 `json:"company_id"`
Name string `json:"name"`
ExpiresAt pgtype.Timestamp `json:"expires_at"`
Type string `json:"type"`
}
func (q *Queries) CreateRaffle(ctx context.Context, arg CreateRaffleParams) (Raffle, error) {
row := q.db.QueryRow(ctx, CreateRaffle,
arg.CompanyID,
arg.Name,
arg.ExpiresAt,
arg.Type,
)
var i Raffle
err := row.Scan(
&i.ID,
&i.CompanyID,
&i.Name,
&i.CreatedAt,
&i.ExpiresAt,
&i.Type,
&i.Status,
)
return i, err
}
const CreateRaffleTicket = `-- name: CreateRaffleTicket :one
INSERT INTO raffle_tickets (raffle_id, user_id)
VALUES ($1, $2)
RETURNING id, raffle_id, user_id, is_active
`
type CreateRaffleTicketParams struct {
RaffleID int32 `json:"raffle_id"`
UserID int32 `json:"user_id"`
}
func (q *Queries) CreateRaffleTicket(ctx context.Context, arg CreateRaffleTicketParams) (RaffleTicket, error) {
row := q.db.QueryRow(ctx, CreateRaffleTicket, arg.RaffleID, arg.UserID)
var i RaffleTicket
err := row.Scan(
&i.ID,
&i.RaffleID,
&i.UserID,
&i.IsActive,
)
return i, err
}
const CreateRaffleWinner = `-- name: CreateRaffleWinner :one
INSERT INTO raffle_winners (raffle_id, user_id, rank)
VALUES ($1, $2, $3)
RETURNING id, raffle_id, user_id, rank, created_at
`
type CreateRaffleWinnerParams struct {
RaffleID int32 `json:"raffle_id"`
UserID int32 `json:"user_id"`
Rank int32 `json:"rank"`
}
func (q *Queries) CreateRaffleWinner(ctx context.Context, arg CreateRaffleWinnerParams) (RaffleWinner, error) {
row := q.db.QueryRow(ctx, CreateRaffleWinner, arg.RaffleID, arg.UserID, arg.Rank)
var i RaffleWinner
err := row.Scan(
&i.ID,
&i.RaffleID,
&i.UserID,
&i.Rank,
&i.CreatedAt,
)
return i, err
}
const DeleteRaffle = `-- name: DeleteRaffle :one
DELETE FROM raffles
WHERE id = $1
RETURNING id, company_id, name, created_at, expires_at, type, status
`
func (q *Queries) DeleteRaffle(ctx context.Context, id int32) (Raffle, error) {
row := q.db.QueryRow(ctx, DeleteRaffle, id)
var i Raffle
err := row.Scan(
&i.ID,
&i.CompanyID,
&i.Name,
&i.CreatedAt,
&i.ExpiresAt,
&i.Type,
&i.Status,
)
return i, err
}
const GetRaffleStanding = `-- name: GetRaffleStanding :many
SELECT
u.id AS user_id,
rt.raffle_id,
u.first_name,
u.last_name,
u.phone_number,
u.email,
COUNT(*) AS ticket_count
FROM raffle_tickets rt
JOIN users u ON rt.user_id = u.id
WHERE rt.is_active = true
AND rt.raffle_id = $1
GROUP BY u.id, rt.raffle_id, u.first_name, u.last_name, u.phone_number, u.email
ORDER BY ticket_count DESC
LIMIT $2
`
type GetRaffleStandingParams struct {
RaffleID int32 `json:"raffle_id"`
Limit int32 `json:"limit"`
}
type GetRaffleStandingRow struct {
UserID int64 `json:"user_id"`
RaffleID int32 `json:"raffle_id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
PhoneNumber pgtype.Text `json:"phone_number"`
Email pgtype.Text `json:"email"`
TicketCount int64 `json:"ticket_count"`
}
func (q *Queries) GetRaffleStanding(ctx context.Context, arg GetRaffleStandingParams) ([]GetRaffleStandingRow, error) {
rows, err := q.db.Query(ctx, GetRaffleStanding, arg.RaffleID, arg.Limit)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetRaffleStandingRow
for rows.Next() {
var i GetRaffleStandingRow
if err := rows.Scan(
&i.UserID,
&i.RaffleID,
&i.FirstName,
&i.LastName,
&i.PhoneNumber,
&i.Email,
&i.TicketCount,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetRafflesOfCompany = `-- name: GetRafflesOfCompany :many
SELECT id, company_id, name, created_at, expires_at, type, status FROM raffles WHERE company_id = $1
`
func (q *Queries) GetRafflesOfCompany(ctx context.Context, companyID int32) ([]Raffle, error) {
rows, err := q.db.Query(ctx, GetRafflesOfCompany, companyID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Raffle
for rows.Next() {
var i Raffle
if err := rows.Scan(
&i.ID,
&i.CompanyID,
&i.Name,
&i.CreatedAt,
&i.ExpiresAt,
&i.Type,
&i.Status,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetUserRaffleTickets = `-- name: GetUserRaffleTickets :many
SELECT
rt.id AS ticket_id,
rt.user_id,
r.name,
r.type,
r.expires_at,
r.status
FROM raffle_tickets rt
JOIN raffles r ON rt.raffle_id = r.id
WHERE rt.user_id = $1
`
type GetUserRaffleTicketsRow struct {
TicketID int32 `json:"ticket_id"`
UserID int32 `json:"user_id"`
Name string `json:"name"`
Type string `json:"type"`
ExpiresAt pgtype.Timestamp `json:"expires_at"`
Status string `json:"status"`
}
func (q *Queries) GetUserRaffleTickets(ctx context.Context, userID int32) ([]GetUserRaffleTicketsRow, error) {
rows, err := q.db.Query(ctx, GetUserRaffleTickets, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetUserRaffleTicketsRow
for rows.Next() {
var i GetUserRaffleTicketsRow
if err := rows.Scan(
&i.TicketID,
&i.UserID,
&i.Name,
&i.Type,
&i.ExpiresAt,
&i.Status,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const SetRaffleComplete = `-- name: SetRaffleComplete :exec
UPDATE raffles
SET status = 'completed'
WHERE id = $1
`
func (q *Queries) SetRaffleComplete(ctx context.Context, id int32) error {
_, err := q.db.Exec(ctx, SetRaffleComplete, id)
return err
}
const UpdateRaffleTicketStatus = `-- name: UpdateRaffleTicketStatus :exec
UPDATE raffle_tickets
SET is_active = $1
WHERE id = $2
`
type UpdateRaffleTicketStatusParams struct {
IsActive pgtype.Bool `json:"is_active"`
ID int32 `json:"id"`
}
func (q *Queries) UpdateRaffleTicketStatus(ctx context.Context, arg UpdateRaffleTicketStatusParams) error {
_, err := q.db.Exec(ctx, UpdateRaffleTicketStatus, arg.IsActive, arg.ID)
return err
}