166 lines
5.4 KiB
Go
166 lines
5.4 KiB
Go
package domain
|
|
|
|
import (
|
|
"time"
|
|
|
|
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
type TicketOutcome struct {
|
|
ID int64 `json:"id" example:"1"`
|
|
TicketID int64 `json:"ticket_id" example:"1"`
|
|
EventID int64 `json:"event_id" example:"1"`
|
|
HomeTeamName string `json:"home_team_name" example:"Manchester"`
|
|
AwayTeamName string `json:"away_team_name" example:"Liverpool"`
|
|
MarketID int64 `json:"market_id" example:"1"`
|
|
MarketName string `json:"market_name" example:"Fulltime Result"`
|
|
OddID int64 `json:"odd_id" example:"1"`
|
|
Odd float32 `json:"odd" example:"1.5"`
|
|
OddName string `json:"odd_name" example:"1"`
|
|
OddHeader string `json:"odd_header" example:"1"`
|
|
OddHandicap string `json:"odd_handicap" example:"1"`
|
|
Status OutcomeStatus `json:"status" example:"1"`
|
|
Expires time.Time `json:"expires" example:"2025-04-08T12:00:00Z"`
|
|
}
|
|
|
|
type CreateTicketOutcome struct {
|
|
TicketID int64 `json:"ticket_id" example:"1"`
|
|
EventID int64 `json:"event_id" example:"1"`
|
|
OddID int64 `json:"odd_id" example:"1"`
|
|
HomeTeamName string `json:"home_team_name" example:"Manchester"`
|
|
AwayTeamName string `json:"away_team_name" example:"Liverpool"`
|
|
MarketID int64 `json:"market_id" example:"1"`
|
|
MarketName string `json:"market_name" example:"Fulltime Result"`
|
|
Odd float32 `json:"odd" example:"1.5"`
|
|
OddName string `json:"odd_name" example:"1"`
|
|
OddHeader string `json:"odd_header" example:"1"`
|
|
OddHandicap string `json:"odd_handicap" example:"1"`
|
|
Expires time.Time `json:"expires" example:"2025-04-08T12:00:00Z"`
|
|
}
|
|
|
|
// ID will serve as the fast code since this doesn't need to be secure
|
|
type Ticket struct {
|
|
ID int64
|
|
Amount Currency
|
|
TotalOdds float32
|
|
CompanyID int64
|
|
}
|
|
|
|
type GetTicket struct {
|
|
ID int64
|
|
Amount Currency
|
|
TotalOdds float32
|
|
Outcomes []TicketOutcome
|
|
CompanyID int64
|
|
}
|
|
|
|
type CreateTicket struct {
|
|
Amount Currency
|
|
TotalOdds float32
|
|
IP string
|
|
CompanyID int64
|
|
}
|
|
|
|
type CreateTicketOutcomeReq struct {
|
|
// TicketID int64 `json:"ticket_id" example:"1"`
|
|
EventID int64 `json:"event_id" example:"1"`
|
|
OddID int64 `json:"odd_id" example:"1"`
|
|
MarketID int64 `json:"market_id" example:"1"`
|
|
// HomeTeamName string `json:"home_team_name" example:"Manchester"`
|
|
// AwayTeamName string `json:"away_team_name" example:"Liverpool"`
|
|
// MarketName string `json:"market_name" example:"Fulltime Result"`
|
|
// Odd float32 `json:"odd" example:"1.5"`
|
|
// OddName string `json:"odd_name" example:"1"`
|
|
// Expires time.Time `json:"expires" example:"2025-04-08T12:00:00Z"`
|
|
}
|
|
|
|
type CreateTicketReq struct {
|
|
Outcomes []CreateTicketOutcomeReq `json:"outcomes"`
|
|
Amount float32 `json:"amount" example:"100.0"`
|
|
}
|
|
type CreateTicketRes struct {
|
|
FastCode int64 `json:"fast_code" example:"1234"`
|
|
CreatedNumber int64 `json:"created_number" example:"3"`
|
|
}
|
|
type TicketRes struct {
|
|
ID int64 `json:"id" example:"1"`
|
|
Outcomes []TicketOutcome `json:"outcomes"`
|
|
Amount float32 `json:"amount" example:"100.0"`
|
|
TotalOdds float32 `json:"total_odds" example:"4.22"`
|
|
CompanyID int64 `json:"company_id" example:"1"`
|
|
}
|
|
|
|
type TicketFilter struct {
|
|
CompanyID ValidInt64
|
|
}
|
|
|
|
func ConvertDBTicket(ticket dbgen.Ticket) Ticket {
|
|
return Ticket{
|
|
ID: ticket.ID,
|
|
Amount: Currency(ticket.Amount),
|
|
TotalOdds: ticket.TotalOdds,
|
|
CompanyID: ticket.CompanyID,
|
|
}
|
|
}
|
|
|
|
func ConvertDBTicketOutcomes(ticket dbgen.TicketWithOutcome) GetTicket {
|
|
|
|
var outcomes []TicketOutcome = make([]TicketOutcome, 0, len(ticket.Outcomes))
|
|
|
|
for _, outcome := range ticket.Outcomes {
|
|
outcomes = append(outcomes, TicketOutcome{
|
|
ID: outcome.ID,
|
|
TicketID: outcome.TicketID,
|
|
EventID: outcome.EventID,
|
|
OddID: outcome.OddID,
|
|
HomeTeamName: outcome.HomeTeamName,
|
|
AwayTeamName: outcome.AwayTeamName,
|
|
MarketID: outcome.MarketID,
|
|
MarketName: outcome.MarketName,
|
|
Odd: outcome.Odd,
|
|
OddName: outcome.OddName,
|
|
OddHeader: outcome.OddHeader,
|
|
OddHandicap: outcome.OddHandicap,
|
|
Status: OutcomeStatus(outcome.Status),
|
|
Expires: outcome.Expires.Time,
|
|
})
|
|
}
|
|
return GetTicket{
|
|
ID: ticket.ID,
|
|
CompanyID: ticket.CompanyID,
|
|
Amount: Currency(ticket.Amount),
|
|
TotalOdds: ticket.TotalOdds,
|
|
Outcomes: outcomes,
|
|
}
|
|
}
|
|
|
|
func ConvertDBCreateTicketOutcome(ticketOutcome CreateTicketOutcome) dbgen.CreateTicketOutcomeParams {
|
|
return dbgen.CreateTicketOutcomeParams{
|
|
TicketID: ticketOutcome.TicketID,
|
|
EventID: ticketOutcome.EventID,
|
|
OddID: ticketOutcome.OddID,
|
|
HomeTeamName: ticketOutcome.HomeTeamName,
|
|
AwayTeamName: ticketOutcome.AwayTeamName,
|
|
MarketID: ticketOutcome.MarketID,
|
|
MarketName: ticketOutcome.MarketName,
|
|
Odd: ticketOutcome.Odd,
|
|
OddName: ticketOutcome.OddName,
|
|
OddHeader: ticketOutcome.OddHeader,
|
|
OddHandicap: ticketOutcome.OddHandicap,
|
|
Expires: pgtype.Timestamp{
|
|
Time: ticketOutcome.Expires,
|
|
Valid: true,
|
|
},
|
|
}
|
|
}
|
|
|
|
func ConvertCreateTicket(ticket CreateTicket) dbgen.CreateTicketParams {
|
|
return dbgen.CreateTicketParams{
|
|
Amount: int64(ticket.Amount),
|
|
TotalOdds: ticket.TotalOdds,
|
|
Ip: ticket.IP,
|
|
CompanyID: ticket.CompanyID,
|
|
}
|
|
}
|