package domain import ( "time" dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db" "github.com/jackc/pgx/v5/pgtype" ) type Raffle struct { ID int32 CompanyID int32 Name string CreatedAt time.Time ExpiresAt time.Time TicketLimit int32 Type string Status string } type RaffleFilter struct { // requireds will depend on type of raffle (sport or game) Type string `json:"type" validate:"required,oneof=sport game"` RaffleID int32 `json:"raffle_id" validate:"required"` SportID int32 `json:"sport_id" validate:"required_if=Type sport"` LeagueID int32 `json:"league_id" validate:"required_if=Type sport"` GameID string `json:"game_id" validate:"required_if=Type game"` } type RaffleStanding struct { UserID int64 RaffleID int32 FirstName string LastName string PhoneNumber string Email string TicketCount int64 } type RaffleStandingRes struct { UserID int64 `json:"user_id"` RaffleID int32 `json:"raffle_id"` FirstName string `json:"first_name"` LastName string `json:"last_name"` PhoneNumber string `json:"phone_number"` Email string `json:"email"` TicketCount int64 `json:"ticket_count"` } type RaffleWinnerParams struct { RaffleID int32 UserID int32 Rank int32 } type RaffleTicket struct { ID int32 RaffleID int32 UserID int32 IsActive bool } type RaffleTicketRes struct { TicketID int32 UserID int32 Name string Type string ExpiresAt time.Time Status string } type CreateRaffle struct { CompanyID int32 `json:"company_id" validate:"required"` Name string `json:"name" validate:"required"` ExpiresAt *time.Time `json:"expires_at" validate:"required"` TicketLimit int32 `json:"ticket_limit" validate:"required"` Type string `json:"type" validate:"required"` } type CreateRaffleTicket struct { RaffleID int32 `json:"raffle_id" validate:"required"` UserID int32 `json:"user_id" validate:"required"` } // aside from ID, atleast one of the fields should be required type UpdateRaffleParams struct { ID int32 `json:"id" validate:"required"` Name string `json:"name" validate:"required_without_all=ExpiresAt"` ExpiresAt *time.Time `json:"expires_at" validate:"required_without_all=Name"` } func ConvertRaffleOutcome(raffle dbgen.Raffle) Raffle { return Raffle{ ID: raffle.ID, CompanyID: raffle.CompanyID, Name: raffle.Name, CreatedAt: raffle.CreatedAt.Time, ExpiresAt: raffle.ExpiresAt.Time, TicketLimit: raffle.TicketLimit, Type: raffle.Type, Status: raffle.Status, } } func ConvertRaffleTicketOutcome(raffle dbgen.RaffleTicket) RaffleTicket { return RaffleTicket{ ID: raffle.ID, RaffleID: raffle.RaffleID, UserID: raffle.UserID, IsActive: raffle.IsActive.Bool, } } func ConvertJoinedRaffleTicketOutcome(raffle dbgen.GetUserRaffleTicketsRow) RaffleTicketRes { return RaffleTicketRes{ TicketID: raffle.TicketID, UserID: raffle.UserID, Name: raffle.Name, Type: raffle.Type, ExpiresAt: raffle.ExpiresAt.Time, Status: raffle.Status, } } func ConvertCreateRaffle(raffle CreateRaffle) dbgen.CreateRaffleParams { return dbgen.CreateRaffleParams{ CompanyID: raffle.CompanyID, Name: raffle.Name, ExpiresAt: pgtype.Timestamp{ Time: *raffle.ExpiresAt, Valid: true, }, TicketLimit: raffle.TicketLimit, Type: raffle.Type, } } func ConvertRaffleStanding(raffleStanding dbgen.GetRaffleStandingRow) RaffleStanding { return RaffleStanding{ UserID: raffleStanding.UserID, RaffleID: raffleStanding.RaffleID, FirstName: raffleStanding.FirstName, LastName: raffleStanding.LastName, PhoneNumber: raffleStanding.PhoneNumber.String, Email: raffleStanding.Email.String, TicketCount: raffleStanding.TicketCount, } }