diff --git a/docs/docs.go b/docs/docs.go index d569ff8..66d8837 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2680,7 +2680,43 @@ const docTemplate = `{ } }, "handlers.CreateBetReq": { - "type": "object" + "type": "object", + "properties": { + "amount": { + "type": "number", + "example": 100 + }, + "full_name": { + "type": "string", + "example": "John" + }, + "is_shop_bet": { + "type": "boolean", + "example": false + }, + "outcomes": { + "type": "array", + "items": { + "$ref": "#/definitions/handlers.BetOutcome" + } + }, + "phone_number": { + "type": "string", + "example": "1234567890" + }, + "status": { + "allOf": [ + { + "$ref": "#/definitions/domain.BetStatus" + } + ], + "example": 1 + }, + "total_odds": { + "type": "number", + "example": 4.22 + } + } }, "handlers.CreateBranchOperationReq": { "type": "object", @@ -2937,17 +2973,6 @@ const docTemplate = `{ } } }, - "handlers.NullableInt64": { - "type": "object", - "properties": { - "valid": { - "type": "boolean" - }, - "value": { - "type": "integer" - } - } - }, "handlers.RegisterCodeReq": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 31f5a1d..9412cfa 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2672,7 +2672,43 @@ } }, "handlers.CreateBetReq": { - "type": "object" + "type": "object", + "properties": { + "amount": { + "type": "number", + "example": 100 + }, + "full_name": { + "type": "string", + "example": "John" + }, + "is_shop_bet": { + "type": "boolean", + "example": false + }, + "outcomes": { + "type": "array", + "items": { + "$ref": "#/definitions/handlers.BetOutcome" + } + }, + "phone_number": { + "type": "string", + "example": "1234567890" + }, + "status": { + "allOf": [ + { + "$ref": "#/definitions/domain.BetStatus" + } + ], + "example": 1 + }, + "total_odds": { + "type": "number", + "example": 4.22 + } + } }, "handlers.CreateBranchOperationReq": { "type": "object", @@ -2929,17 +2965,6 @@ } } }, - "handlers.NullableInt64": { - "type": "object", - "properties": { - "valid": { - "type": "boolean" - }, - "value": { - "type": "integer" - } - } - }, "handlers.RegisterCodeReq": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index a6726d2..041c38a 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -223,6 +223,30 @@ definitions: type: boolean type: object handlers.CreateBetReq: + properties: + amount: + example: 100 + type: number + full_name: + example: John + type: string + is_shop_bet: + example: false + type: boolean + outcomes: + items: + $ref: '#/definitions/handlers.BetOutcome' + type: array + phone_number: + example: "1234567890" + type: string + status: + allOf: + - $ref: '#/definitions/domain.BetStatus' + example: 1 + total_odds: + example: 4.22 + type: number type: object handlers.CreateBranchOperationReq: properties: @@ -403,13 +427,6 @@ definitions: static_updated_at: type: string type: object - handlers.NullableInt64: - properties: - valid: - type: boolean - value: - type: integer - type: object handlers.RegisterCodeReq: properties: email: diff --git a/gen/db/auth.sql.go b/gen/db/auth.sql.go index c826c36..bbc0e60 100644 --- a/gen/db/auth.sql.go +++ b/gen/db/auth.sql.go @@ -17,11 +17,11 @@ VALUES ($1, $2, $3, $4, $5) ` type CreateRefreshTokenParams struct { - UserID int64 - Token string - ExpiresAt pgtype.Timestamptz - CreatedAt pgtype.Timestamptz - Revoked bool + UserID int64 `json:"user_id"` + Token string `json:"token"` + ExpiresAt pgtype.Timestamptz `json:"expires_at"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + Revoked bool `json:"revoked"` } func (q *Queries) CreateRefreshToken(ctx context.Context, arg CreateRefreshTokenParams) error { @@ -60,8 +60,8 @@ WHERE email = $1 OR phone_number = $2 ` type GetUserByEmailPhoneParams struct { - Email pgtype.Text - PhoneNumber pgtype.Text + Email pgtype.Text `json:"email"` + PhoneNumber pgtype.Text `json:"phone_number"` } func (q *Queries) GetUserByEmailPhone(ctx context.Context, arg GetUserByEmailPhoneParams) (User, error) { diff --git a/gen/db/bet.sql.go b/gen/db/bet.sql.go index 89a636a..c429b91 100644 --- a/gen/db/bet.sql.go +++ b/gen/db/bet.sql.go @@ -28,15 +28,15 @@ RETURNING id, amount, total_odds, status, full_name, phone_number, branch_id, us ` type CreateBetParams struct { - Amount int64 - TotalOdds float32 - Status int32 - FullName string - PhoneNumber string - BranchID pgtype.Int8 - UserID pgtype.Int8 - IsShopBet bool - CashoutID string + Amount int64 `json:"amount"` + TotalOdds float32 `json:"total_odds"` + Status int32 `json:"status"` + FullName string `json:"full_name"` + PhoneNumber string `json:"phone_number"` + BranchID pgtype.Int8 `json:"branch_id"` + UserID pgtype.Int8 `json:"user_id"` + IsShopBet bool `json:"is_shop_bet"` + CashoutID string `json:"cashout_id"` } func (q *Queries) CreateBet(ctx context.Context, arg CreateBetParams) (Bet, error) { @@ -71,9 +71,9 @@ func (q *Queries) CreateBet(ctx context.Context, arg CreateBetParams) (Bet, erro } type CreateBetOutcomeParams struct { - BetID int64 - EventID int64 - OddID int64 + BetID int64 `json:"bet_id"` + EventID int64 `json:"event_id"` + OddID int64 `json:"odd_id"` } const DeleteBet = `-- name: DeleteBet :exec @@ -242,8 +242,8 @@ WHERE id = $1 ` type UpdateCashOutParams struct { - ID int64 - CashedOut bool + ID int64 `json:"id"` + CashedOut bool `json:"cashed_out"` } func (q *Queries) UpdateCashOut(ctx context.Context, arg UpdateCashOutParams) error { diff --git a/gen/db/branch.sql.go b/gen/db/branch.sql.go index d1d8e99..a04d4fd 100644 --- a/gen/db/branch.sql.go +++ b/gen/db/branch.sql.go @@ -25,12 +25,12 @@ RETURNING id, name, location, wallet_id, branch_manager_id, company_id, is_self_ ` type CreateBranchParams struct { - Name string - Location string - WalletID int64 - BranchManagerID int64 - CompanyID int64 - IsSelfOwned bool + Name string `json:"name"` + Location string `json:"location"` + WalletID int64 `json:"wallet_id"` + BranchManagerID int64 `json:"branch_manager_id"` + CompanyID int64 `json:"company_id"` + IsSelfOwned bool `json:"is_self_owned"` } func (q *Queries) CreateBranch(ctx context.Context, arg CreateBranchParams) (Branch, error) { @@ -64,8 +64,8 @@ RETURNING id, user_id, branch_id ` type CreateBranchCashierParams struct { - UserID int64 - BranchID int64 + UserID int64 `json:"user_id"` + BranchID int64 `json:"branch_id"` } func (q *Queries) CreateBranchCashier(ctx context.Context, arg CreateBranchCashierParams) (BranchCashier, error) { @@ -82,8 +82,8 @@ RETURNING id, operation_id, branch_id, created_at, updated_at ` type CreateBranchOperationParams struct { - OperationID int64 - BranchID int64 + OperationID int64 `json:"operation_id"` + BranchID int64 `json:"branch_id"` } func (q *Queries) CreateBranchOperation(ctx context.Context, arg CreateBranchOperationParams) (BranchOperation, error) { @@ -106,8 +106,8 @@ RETURNING id, name, description ` type CreateSupportedOperationParams struct { - Name string - Description string + Name string `json:"name"` + Description string `json:"description"` } func (q *Queries) CreateSupportedOperation(ctx context.Context, arg CreateSupportedOperationParams) (SupportedOperation, error) { @@ -144,8 +144,8 @@ WHERE operation_id = $1 ` type DeleteBranchOperationParams struct { - OperationID int64 - BranchID int64 + OperationID int64 `json:"operation_id"` + BranchID int64 `json:"branch_id"` } func (q *Queries) DeleteBranchOperation(ctx context.Context, arg DeleteBranchOperationParams) error { @@ -390,13 +390,13 @@ WHERE branch_operations.branch_id = $1 ` type GetBranchOperationsRow struct { - ID int64 - OperationID int64 - BranchID int64 - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp - Name string - Description string + ID int64 `json:"id"` + OperationID int64 `json:"operation_id"` + BranchID int64 `json:"branch_id"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` + Name string `json:"name"` + Description string `json:"description"` } func (q *Queries) GetBranchOperations(ctx context.Context, branchID int64) ([]GetBranchOperationsRow, error) { @@ -518,12 +518,12 @@ RETURNING id, name, location, wallet_id, branch_manager_id, company_id, is_self_ ` type UpdateBranchParams struct { - Name string - Location string - BranchManagerID int64 - CompanyID int64 - IsSelfOwned bool - ID int64 + Name string `json:"name"` + Location string `json:"location"` + BranchManagerID int64 `json:"branch_manager_id"` + CompanyID int64 `json:"company_id"` + IsSelfOwned bool `json:"is_self_owned"` + ID int64 `json:"id"` } func (q *Queries) UpdateBranch(ctx context.Context, arg UpdateBranchParams) (Branch, error) { diff --git a/gen/db/events.sql.go b/gen/db/events.sql.go index e833d0e..6cb26e1 100644 --- a/gen/db/events.sql.go +++ b/gen/db/events.sql.go @@ -49,26 +49,26 @@ ON CONFLICT (id) DO UPDATE SET ` type InsertEventParams struct { - ID string - SportID pgtype.Text - MatchName pgtype.Text - HomeTeam pgtype.Text - AwayTeam pgtype.Text - HomeTeamID pgtype.Text - AwayTeamID pgtype.Text - HomeKitImage pgtype.Text - AwayKitImage pgtype.Text - LeagueID pgtype.Text - LeagueName pgtype.Text - LeagueCc pgtype.Text - StartTime pgtype.Timestamp - Score pgtype.Text - MatchMinute pgtype.Int4 - TimerStatus pgtype.Text - AddedTime pgtype.Int4 - MatchPeriod pgtype.Int4 - IsLive pgtype.Bool - Status pgtype.Text + ID string `json:"id"` + SportID pgtype.Text `json:"sport_id"` + MatchName pgtype.Text `json:"match_name"` + HomeTeam pgtype.Text `json:"home_team"` + AwayTeam pgtype.Text `json:"away_team"` + HomeTeamID pgtype.Text `json:"home_team_id"` + AwayTeamID pgtype.Text `json:"away_team_id"` + HomeKitImage pgtype.Text `json:"home_kit_image"` + AwayKitImage pgtype.Text `json:"away_kit_image"` + LeagueID pgtype.Text `json:"league_id"` + LeagueName pgtype.Text `json:"league_name"` + LeagueCc pgtype.Text `json:"league_cc"` + StartTime pgtype.Timestamp `json:"start_time"` + Score pgtype.Text `json:"score"` + MatchMinute pgtype.Int4 `json:"match_minute"` + TimerStatus pgtype.Text `json:"timer_status"` + AddedTime pgtype.Int4 `json:"added_time"` + MatchPeriod pgtype.Int4 `json:"match_period"` + IsLive pgtype.Bool `json:"is_live"` + Status pgtype.Text `json:"status"` } func (q *Queries) InsertEvent(ctx context.Context, arg InsertEventParams) error { diff --git a/gen/db/models.go b/gen/db/models.go index 31b7b3b..8fe75fd 100644 --- a/gen/db/models.go +++ b/gen/db/models.go @@ -9,265 +9,265 @@ import ( ) type Bet struct { - ID int64 - Amount int64 - TotalOdds float32 - Status int32 - FullName string - PhoneNumber string - BranchID pgtype.Int8 - UserID pgtype.Int8 - CashedOut bool - CashoutID string - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp - IsShopBet bool + ID int64 `json:"id"` + Amount int64 `json:"amount"` + TotalOdds float32 `json:"total_odds"` + Status int32 `json:"status"` + FullName string `json:"full_name"` + PhoneNumber string `json:"phone_number"` + BranchID pgtype.Int8 `json:"branch_id"` + UserID pgtype.Int8 `json:"user_id"` + CashedOut bool `json:"cashed_out"` + CashoutID string `json:"cashout_id"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` + IsShopBet bool `json:"is_shop_bet"` } type BetOutcome struct { - ID int64 - BetID int64 - EventID int64 - OddID int64 + ID int64 `json:"id"` + BetID int64 `json:"bet_id"` + EventID int64 `json:"event_id"` + OddID int64 `json:"odd_id"` } type BetWithOutcome struct { - ID int64 - Amount int64 - TotalOdds float32 - Status int32 - FullName string - PhoneNumber string - BranchID pgtype.Int8 - UserID pgtype.Int8 - CashedOut bool - CashoutID string - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp - IsShopBet bool - Outcomes []BetOutcome + ID int64 `json:"id"` + Amount int64 `json:"amount"` + TotalOdds float32 `json:"total_odds"` + Status int32 `json:"status"` + FullName string `json:"full_name"` + PhoneNumber string `json:"phone_number"` + BranchID pgtype.Int8 `json:"branch_id"` + UserID pgtype.Int8 `json:"user_id"` + CashedOut bool `json:"cashed_out"` + CashoutID string `json:"cashout_id"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` + IsShopBet bool `json:"is_shop_bet"` + Outcomes []BetOutcome `json:"outcomes"` } type Branch struct { - ID int64 - Name string - Location string - WalletID int64 - BranchManagerID int64 - CompanyID int64 - IsSelfOwned bool - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp + ID int64 `json:"id"` + Name string `json:"name"` + Location string `json:"location"` + WalletID int64 `json:"wallet_id"` + BranchManagerID int64 `json:"branch_manager_id"` + CompanyID int64 `json:"company_id"` + IsSelfOwned bool `json:"is_self_owned"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` } type BranchCashier struct { - ID int64 - UserID int64 - BranchID int64 + ID int64 `json:"id"` + UserID int64 `json:"user_id"` + BranchID int64 `json:"branch_id"` } type BranchDetail struct { - ID int64 - Name string - Location string - WalletID int64 - BranchManagerID int64 - CompanyID int64 - IsSelfOwned bool - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp - ManagerName interface{} - ManagerPhoneNumber pgtype.Text + ID int64 `json:"id"` + Name string `json:"name"` + Location string `json:"location"` + WalletID int64 `json:"wallet_id"` + BranchManagerID int64 `json:"branch_manager_id"` + CompanyID int64 `json:"company_id"` + IsSelfOwned bool `json:"is_self_owned"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` + ManagerName interface{} `json:"manager_name"` + ManagerPhoneNumber pgtype.Text `json:"manager_phone_number"` } type BranchOperation struct { - ID int64 - OperationID int64 - BranchID int64 - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp + ID int64 `json:"id"` + OperationID int64 `json:"operation_id"` + BranchID int64 `json:"branch_id"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` } type CustomerWallet struct { - ID int64 - CustomerID int64 - CompanyID int64 - RegularWalletID int64 - StaticWalletID int64 - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp + ID int64 `json:"id"` + CustomerID int64 `json:"customer_id"` + CompanyID int64 `json:"company_id"` + RegularWalletID int64 `json:"regular_wallet_id"` + StaticWalletID int64 `json:"static_wallet_id"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` } type Event struct { - ID string - SportID pgtype.Text - MatchName pgtype.Text - HomeTeam pgtype.Text - AwayTeam pgtype.Text - HomeTeamID pgtype.Text - AwayTeamID pgtype.Text - HomeKitImage pgtype.Text - AwayKitImage pgtype.Text - LeagueID pgtype.Text - LeagueName pgtype.Text - LeagueCc pgtype.Text - StartTime pgtype.Timestamp - Score pgtype.Text - MatchMinute pgtype.Int4 - TimerStatus pgtype.Text - AddedTime pgtype.Int4 - MatchPeriod pgtype.Int4 - IsLive pgtype.Bool - Status pgtype.Text - FetchedAt pgtype.Timestamp + ID string `json:"id"` + SportID pgtype.Text `json:"sport_id"` + MatchName pgtype.Text `json:"match_name"` + HomeTeam pgtype.Text `json:"home_team"` + AwayTeam pgtype.Text `json:"away_team"` + HomeTeamID pgtype.Text `json:"home_team_id"` + AwayTeamID pgtype.Text `json:"away_team_id"` + HomeKitImage pgtype.Text `json:"home_kit_image"` + AwayKitImage pgtype.Text `json:"away_kit_image"` + LeagueID pgtype.Text `json:"league_id"` + LeagueName pgtype.Text `json:"league_name"` + LeagueCc pgtype.Text `json:"league_cc"` + StartTime pgtype.Timestamp `json:"start_time"` + Score pgtype.Text `json:"score"` + MatchMinute pgtype.Int4 `json:"match_minute"` + TimerStatus pgtype.Text `json:"timer_status"` + AddedTime pgtype.Int4 `json:"added_time"` + MatchPeriod pgtype.Int4 `json:"match_period"` + IsLive pgtype.Bool `json:"is_live"` + Status pgtype.Text `json:"status"` + FetchedAt pgtype.Timestamp `json:"fetched_at"` } type Notification struct { - ID string - RecipientID int64 - Type string - Level string - ErrorSeverity pgtype.Text - Reciever string - IsRead bool - DeliveryStatus string - DeliveryChannel pgtype.Text - Payload []byte - Priority pgtype.Int4 - Version int32 - Timestamp pgtype.Timestamptz - Metadata []byte + ID string `json:"id"` + RecipientID int64 `json:"recipient_id"` + Type string `json:"type"` + Level string `json:"level"` + ErrorSeverity pgtype.Text `json:"error_severity"` + Reciever string `json:"reciever"` + IsRead bool `json:"is_read"` + DeliveryStatus string `json:"delivery_status"` + DeliveryChannel pgtype.Text `json:"delivery_channel"` + Payload []byte `json:"payload"` + Priority pgtype.Int4 `json:"priority"` + Version int32 `json:"version"` + Timestamp pgtype.Timestamptz `json:"timestamp"` + Metadata []byte `json:"metadata"` } type Odd struct { - ID int32 - EventID pgtype.Text - Fi pgtype.Text - RawEventID pgtype.Text - MarketType string - MarketName pgtype.Text - MarketCategory pgtype.Text - MarketID pgtype.Text - Header pgtype.Text - Name pgtype.Text - Handicap pgtype.Text - OddsValue pgtype.Float8 - Section string - Category pgtype.Text - RawOdds []byte - FetchedAt pgtype.Timestamp - Source pgtype.Text - IsActive pgtype.Bool + ID int32 `json:"id"` + EventID pgtype.Text `json:"event_id"` + Fi pgtype.Text `json:"fi"` + RawEventID pgtype.Text `json:"raw_event_id"` + MarketType string `json:"market_type"` + MarketName pgtype.Text `json:"market_name"` + MarketCategory pgtype.Text `json:"market_category"` + MarketID pgtype.Text `json:"market_id"` + Header pgtype.Text `json:"header"` + Name pgtype.Text `json:"name"` + Handicap pgtype.Text `json:"handicap"` + OddsValue pgtype.Float8 `json:"odds_value"` + Section string `json:"section"` + Category pgtype.Text `json:"category"` + RawOdds []byte `json:"raw_odds"` + FetchedAt pgtype.Timestamp `json:"fetched_at"` + Source pgtype.Text `json:"source"` + IsActive pgtype.Bool `json:"is_active"` } type Otp struct { - ID int64 - SentTo string - Medium string - OtpFor string - Otp string - Used bool - UsedAt pgtype.Timestamptz - CreatedAt pgtype.Timestamptz - ExpiresAt pgtype.Timestamptz + ID int64 `json:"id"` + SentTo string `json:"sent_to"` + Medium string `json:"medium"` + OtpFor string `json:"otp_for"` + Otp string `json:"otp"` + Used bool `json:"used"` + UsedAt pgtype.Timestamptz `json:"used_at"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + ExpiresAt pgtype.Timestamptz `json:"expires_at"` } type RefreshToken struct { - ID int64 - UserID int64 - Token string - ExpiresAt pgtype.Timestamptz - CreatedAt pgtype.Timestamptz - Revoked bool + ID int64 `json:"id"` + UserID int64 `json:"user_id"` + Token string `json:"token"` + ExpiresAt pgtype.Timestamptz `json:"expires_at"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + Revoked bool `json:"revoked"` } type SupportedOperation struct { - ID int64 - Name string - Description string + ID int64 `json:"id"` + Name string `json:"name"` + Description string `json:"description"` } type Ticket struct { - ID int64 - Amount pgtype.Int8 - TotalOdds float32 - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp + ID int64 `json:"id"` + Amount pgtype.Int8 `json:"amount"` + TotalOdds float32 `json:"total_odds"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` } type TicketOutcome struct { - ID int64 - TicketID int64 - EventID int64 - OddID int64 + ID int64 `json:"id"` + TicketID int64 `json:"ticket_id"` + EventID int64 `json:"event_id"` + OddID int64 `json:"odd_id"` } type TicketWithOutcome struct { - ID int64 - Amount pgtype.Int8 - TotalOdds float32 - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp - Outcomes []TicketOutcome + ID int64 `json:"id"` + Amount pgtype.Int8 `json:"amount"` + TotalOdds float32 `json:"total_odds"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` + Outcomes []TicketOutcome `json:"outcomes"` } type Transaction struct { - ID int64 - Amount int64 - BranchID int64 - CashierID int64 - BetID int64 - Type int64 - PaymentOption int64 - FullName string - PhoneNumber string - BankCode string - BeneficiaryName string - AccountName string - AccountNumber string - ReferenceNumber string - Verified bool - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp + ID int64 `json:"id"` + Amount int64 `json:"amount"` + BranchID int64 `json:"branch_id"` + CashierID int64 `json:"cashier_id"` + BetID int64 `json:"bet_id"` + Type int64 `json:"type"` + PaymentOption int64 `json:"payment_option"` + FullName string `json:"full_name"` + PhoneNumber string `json:"phone_number"` + BankCode string `json:"bank_code"` + BeneficiaryName string `json:"beneficiary_name"` + AccountName string `json:"account_name"` + AccountNumber string `json:"account_number"` + ReferenceNumber string `json:"reference_number"` + Verified bool `json:"verified"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` } type User struct { - ID int64 - FirstName string - LastName string - Email pgtype.Text - PhoneNumber pgtype.Text - Role string - Password []byte - EmailVerified bool - PhoneVerified bool - CreatedAt pgtype.Timestamptz - UpdatedAt pgtype.Timestamptz - SuspendedAt pgtype.Timestamptz - Suspended bool + ID int64 `json:"id"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email pgtype.Text `json:"email"` + PhoneNumber pgtype.Text `json:"phone_number"` + Role string `json:"role"` + Password []byte `json:"password"` + EmailVerified bool `json:"email_verified"` + PhoneVerified bool `json:"phone_verified"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + UpdatedAt pgtype.Timestamptz `json:"updated_at"` + SuspendedAt pgtype.Timestamptz `json:"suspended_at"` + Suspended bool `json:"suspended"` } type Wallet struct { - ID int64 - Balance int64 - IsWithdraw bool - IsBettable bool - IsTransferable bool - UserID int64 - IsActive bool - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp + ID int64 `json:"id"` + Balance int64 `json:"balance"` + IsWithdraw bool `json:"is_withdraw"` + IsBettable bool `json:"is_bettable"` + IsTransferable bool `json:"is_transferable"` + UserID int64 `json:"user_id"` + IsActive bool `json:"is_active"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` } type WalletTransfer struct { - ID int64 - Amount int64 - Type string - ReceiverWalletID int64 - SenderWalletID pgtype.Int8 - CashierID pgtype.Int8 - Verified bool - PaymentMethod string - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp + ID int64 `json:"id"` + Amount int64 `json:"amount"` + Type string `json:"type"` + ReceiverWalletID int64 `json:"receiver_wallet_id"` + SenderWalletID pgtype.Int8 `json:"sender_wallet_id"` + CashierID pgtype.Int8 `json:"cashier_id"` + Verified bool `json:"verified"` + PaymentMethod string `json:"payment_method"` + CreatedAt pgtype.Timestamp `json:"created_at"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` } diff --git a/gen/db/notification.sql.go b/gen/db/notification.sql.go index 3735d72..5bfedd6 100644 --- a/gen/db/notification.sql.go +++ b/gen/db/notification.sql.go @@ -20,19 +20,19 @@ INSERT INTO notifications ( ` type CreateNotificationParams struct { - ID string - RecipientID int64 - Type string - Level string - ErrorSeverity pgtype.Text - Reciever string - IsRead bool - DeliveryStatus string - DeliveryChannel pgtype.Text - Payload []byte - Priority pgtype.Int4 - Timestamp pgtype.Timestamptz - Metadata []byte + ID string `json:"id"` + RecipientID int64 `json:"recipient_id"` + Type string `json:"type"` + Level string `json:"level"` + ErrorSeverity pgtype.Text `json:"error_severity"` + Reciever string `json:"reciever"` + IsRead bool `json:"is_read"` + DeliveryStatus string `json:"delivery_status"` + DeliveryChannel pgtype.Text `json:"delivery_channel"` + Payload []byte `json:"payload"` + Priority pgtype.Int4 `json:"priority"` + Timestamp pgtype.Timestamptz `json:"timestamp"` + Metadata []byte `json:"metadata"` } func (q *Queries) CreateNotification(ctx context.Context, arg CreateNotificationParams) (Notification, error) { @@ -141,9 +141,9 @@ SELECT id, recipient_id, type, level, error_severity, reciever, is_read, deliver ` type ListNotificationsParams struct { - RecipientID int64 - Limit int32 - Offset int32 + RecipientID int64 `json:"recipient_id"` + Limit int32 `json:"limit"` + Offset int32 `json:"offset"` } func (q *Queries) ListNotifications(ctx context.Context, arg ListNotificationsParams) ([]Notification, error) { @@ -210,10 +210,10 @@ UPDATE notifications SET delivery_status = $2, is_read = $3, metadata = $4 WHERE ` type UpdateNotificationStatusParams struct { - ID string - DeliveryStatus string - IsRead bool - Metadata []byte + ID string `json:"id"` + DeliveryStatus string `json:"delivery_status"` + IsRead bool `json:"is_read"` + Metadata []byte `json:"metadata"` } func (q *Queries) UpdateNotificationStatus(ctx context.Context, arg UpdateNotificationStatusParams) (Notification, error) { diff --git a/gen/db/odds.sql.go b/gen/db/odds.sql.go index 003be80..3b8441c 100644 --- a/gen/db/odds.sql.go +++ b/gen/db/odds.sql.go @@ -112,20 +112,20 @@ ON CONFLICT (event_id, market_id, header, name, handicap) DO UPDATE SET ` type InsertNonLiveOddParams struct { - EventID pgtype.Text - Fi pgtype.Text - RawEventID pgtype.Text - MarketType string - MarketName pgtype.Text - MarketCategory pgtype.Text - MarketID pgtype.Text - Header pgtype.Text - Name pgtype.Text - Handicap pgtype.Text - OddsValue pgtype.Float8 - Section string - Category pgtype.Text - RawOdds []byte + EventID pgtype.Text `json:"event_id"` + Fi pgtype.Text `json:"fi"` + RawEventID pgtype.Text `json:"raw_event_id"` + MarketType string `json:"market_type"` + MarketName pgtype.Text `json:"market_name"` + MarketCategory pgtype.Text `json:"market_category"` + MarketID pgtype.Text `json:"market_id"` + Header pgtype.Text `json:"header"` + Name pgtype.Text `json:"name"` + Handicap pgtype.Text `json:"handicap"` + OddsValue pgtype.Float8 `json:"odds_value"` + Section string `json:"section"` + Category pgtype.Text `json:"category"` + RawOdds []byte `json:"raw_odds"` } func (q *Queries) InsertNonLiveOdd(ctx context.Context, arg InsertNonLiveOddParams) error { diff --git a/gen/db/otp.sql.go b/gen/db/otp.sql.go index e0b9806..99cdd4c 100644 --- a/gen/db/otp.sql.go +++ b/gen/db/otp.sql.go @@ -17,12 +17,12 @@ VALUES ($1, $2, $3, $4, FALSE, $5, $6) ` type CreateOtpParams struct { - SentTo string - Medium string - OtpFor string - Otp string - CreatedAt pgtype.Timestamptz - ExpiresAt pgtype.Timestamptz + SentTo string `json:"sent_to"` + Medium string `json:"medium"` + OtpFor string `json:"otp_for"` + Otp string `json:"otp"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + ExpiresAt pgtype.Timestamptz `json:"expires_at"` } func (q *Queries) CreateOtp(ctx context.Context, arg CreateOtpParams) error { @@ -45,9 +45,9 @@ ORDER BY created_at DESC LIMIT 1 ` type GetOtpParams struct { - SentTo string - OtpFor string - Medium string + SentTo string `json:"sent_to"` + OtpFor string `json:"otp_for"` + Medium string `json:"medium"` } func (q *Queries) GetOtp(ctx context.Context, arg GetOtpParams) (Otp, error) { @@ -74,8 +74,8 @@ WHERE id = $1 ` type MarkOtpAsUsedParams struct { - ID int64 - UsedAt pgtype.Timestamptz + ID int64 `json:"id"` + UsedAt pgtype.Timestamptz `json:"used_at"` } func (q *Queries) MarkOtpAsUsed(ctx context.Context, arg MarkOtpAsUsedParams) error { diff --git a/gen/db/ticket.sql.go b/gen/db/ticket.sql.go index 150d386..59ebd69 100644 --- a/gen/db/ticket.sql.go +++ b/gen/db/ticket.sql.go @@ -18,8 +18,8 @@ RETURNING id, amount, total_odds, created_at, updated_at ` type CreateTicketParams struct { - Amount pgtype.Int8 - TotalOdds float32 + Amount pgtype.Int8 `json:"amount"` + TotalOdds float32 `json:"total_odds"` } func (q *Queries) CreateTicket(ctx context.Context, arg CreateTicketParams) (Ticket, error) { @@ -36,9 +36,9 @@ func (q *Queries) CreateTicket(ctx context.Context, arg CreateTicketParams) (Tic } type CreateTicketOutcomeParams struct { - TicketID int64 - EventID int64 - OddID int64 + TicketID int64 `json:"ticket_id"` + EventID int64 `json:"event_id"` + OddID int64 `json:"odd_id"` } const DeleteOldTickets = `-- name: DeleteOldTickets :exec diff --git a/gen/db/transactions.sql.go b/gen/db/transactions.sql.go index 8f15071..2865972 100644 --- a/gen/db/transactions.sql.go +++ b/gen/db/transactions.sql.go @@ -14,19 +14,19 @@ INSERT INTO transactions (amount, branch_id, cashier_id, bet_id, type, payment_o ` type CreateTransactionParams struct { - Amount int64 - BranchID int64 - CashierID int64 - BetID int64 - Type int64 - PaymentOption int64 - FullName string - PhoneNumber string - BankCode string - BeneficiaryName string - AccountName string - AccountNumber string - ReferenceNumber string + Amount int64 `json:"amount"` + BranchID int64 `json:"branch_id"` + CashierID int64 `json:"cashier_id"` + BetID int64 `json:"bet_id"` + Type int64 `json:"type"` + PaymentOption int64 `json:"payment_option"` + FullName string `json:"full_name"` + PhoneNumber string `json:"phone_number"` + BankCode string `json:"bank_code"` + BeneficiaryName string `json:"beneficiary_name"` + AccountName string `json:"account_name"` + AccountNumber string `json:"account_number"` + ReferenceNumber string `json:"reference_number"` } func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) { @@ -186,8 +186,8 @@ UPDATE transactions SET verified = $2, updated_at = CURRENT_TIMESTAMP WHERE id = ` type UpdateTransactionVerifiedParams struct { - ID int64 - Verified bool + ID int64 `json:"id"` + Verified bool `json:"verified"` } func (q *Queries) UpdateTransactionVerified(ctx context.Context, arg UpdateTransactionVerifiedParams) error { diff --git a/gen/db/transfer.sql.go b/gen/db/transfer.sql.go index 9faeaf5..f4d8cc2 100644 --- a/gen/db/transfer.sql.go +++ b/gen/db/transfer.sql.go @@ -16,13 +16,13 @@ INSERT INTO wallet_transfer (amount, type, receiver_wallet_id, sender_wallet_id, ` type CreateTransferParams struct { - Amount int64 - Type string - ReceiverWalletID int64 - SenderWalletID pgtype.Int8 - CashierID pgtype.Int8 - Verified bool - PaymentMethod string + Amount int64 `json:"amount"` + Type string `json:"type"` + ReceiverWalletID int64 `json:"receiver_wallet_id"` + SenderWalletID pgtype.Int8 `json:"sender_wallet_id"` + CashierID pgtype.Int8 `json:"cashier_id"` + Verified bool `json:"verified"` + PaymentMethod string `json:"payment_method"` } func (q *Queries) CreateTransfer(ctx context.Context, arg CreateTransferParams) (WalletTransfer, error) { @@ -148,8 +148,8 @@ UPDATE wallet_transfer SET verified = $1, updated_at = CURRENT_TIMESTAMP WHERE i ` type UpdateTransferVerificationParams struct { - Verified bool - ID int64 + Verified bool `json:"verified"` + ID int64 `json:"id"` } func (q *Queries) UpdateTransferVerification(ctx context.Context, arg UpdateTransferVerificationParams) error { diff --git a/gen/db/user.sql.go b/gen/db/user.sql.go index e259cb9..d4c5b34 100644 --- a/gen/db/user.sql.go +++ b/gen/db/user.sql.go @@ -27,13 +27,13 @@ SELECT EXISTS ( ` type CheckPhoneEmailExistParams struct { - PhoneNumber pgtype.Text - Email pgtype.Text + PhoneNumber pgtype.Text `json:"phone_number"` + Email pgtype.Text `json:"email"` } type CheckPhoneEmailExistRow struct { - PhoneExists bool - EmailExists bool + PhoneExists bool `json:"phone_exists"` + EmailExists bool `json:"email_exists"` } func (q *Queries) CheckPhoneEmailExist(ctx context.Context, arg CheckPhoneEmailExistParams) (CheckPhoneEmailExistRow, error) { @@ -70,29 +70,29 @@ RETURNING id, ` type CreateUserParams struct { - FirstName string - LastName string - Email pgtype.Text - PhoneNumber pgtype.Text - Role string - Password []byte - EmailVerified bool - PhoneVerified bool - CreatedAt pgtype.Timestamptz - UpdatedAt pgtype.Timestamptz + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email pgtype.Text `json:"email"` + PhoneNumber pgtype.Text `json:"phone_number"` + Role string `json:"role"` + Password []byte `json:"password"` + EmailVerified bool `json:"email_verified"` + PhoneVerified bool `json:"phone_verified"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + UpdatedAt pgtype.Timestamptz `json:"updated_at"` } type CreateUserRow struct { - ID int64 - FirstName string - LastName string - Email pgtype.Text - PhoneNumber pgtype.Text - Role string - EmailVerified bool - PhoneVerified bool - CreatedAt pgtype.Timestamptz - UpdatedAt pgtype.Timestamptz + ID int64 `json:"id"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email pgtype.Text `json:"email"` + PhoneNumber pgtype.Text `json:"phone_number"` + Role string `json:"role"` + EmailVerified bool `json:"email_verified"` + PhoneVerified bool `json:"phone_verified"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + UpdatedAt pgtype.Timestamptz `json:"updated_at"` } func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) { @@ -149,16 +149,16 @@ FROM users ` type GetAllUsersRow struct { - ID int64 - FirstName string - LastName string - Email pgtype.Text - PhoneNumber pgtype.Text - Role string - EmailVerified bool - PhoneVerified bool - CreatedAt pgtype.Timestamptz - UpdatedAt pgtype.Timestamptz + ID int64 `json:"id"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email pgtype.Text `json:"email"` + PhoneNumber pgtype.Text `json:"phone_number"` + Role string `json:"role"` + EmailVerified bool `json:"email_verified"` + PhoneVerified bool `json:"phone_verified"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + UpdatedAt pgtype.Timestamptz `json:"updated_at"` } func (q *Queries) GetAllUsers(ctx context.Context) ([]GetAllUsersRow, error) { @@ -208,16 +208,16 @@ WHERE email = $1 ` type GetUserByEmailRow struct { - ID int64 - FirstName string - LastName string - Email pgtype.Text - PhoneNumber pgtype.Text - Role string - EmailVerified bool - PhoneVerified bool - CreatedAt pgtype.Timestamptz - UpdatedAt pgtype.Timestamptz + ID int64 `json:"id"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email pgtype.Text `json:"email"` + PhoneNumber pgtype.Text `json:"phone_number"` + Role string `json:"role"` + EmailVerified bool `json:"email_verified"` + PhoneVerified bool `json:"phone_verified"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + UpdatedAt pgtype.Timestamptz `json:"updated_at"` } func (q *Queries) GetUserByEmail(ctx context.Context, email pgtype.Text) (GetUserByEmailRow, error) { @@ -281,16 +281,16 @@ WHERE phone_number = $1 ` type GetUserByPhoneRow struct { - ID int64 - FirstName string - LastName string - Email pgtype.Text - PhoneNumber pgtype.Text - Role string - EmailVerified bool - PhoneVerified bool - CreatedAt pgtype.Timestamptz - UpdatedAt pgtype.Timestamptz + ID int64 `json:"id"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email pgtype.Text `json:"email"` + PhoneNumber pgtype.Text `json:"phone_number"` + Role string `json:"role"` + EmailVerified bool `json:"email_verified"` + PhoneVerified bool `json:"phone_verified"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + UpdatedAt pgtype.Timestamptz `json:"updated_at"` } func (q *Queries) GetUserByPhone(ctx context.Context, phoneNumber pgtype.Text) (GetUserByPhoneRow, error) { @@ -329,16 +329,16 @@ WHERE first_name ILIKE '%' || $1 || '%' ` type SearchUserByNameOrPhoneRow struct { - ID int64 - FirstName string - LastName string - Email pgtype.Text - PhoneNumber pgtype.Text - Role string - EmailVerified bool - PhoneVerified bool - CreatedAt pgtype.Timestamptz - UpdatedAt pgtype.Timestamptz + ID int64 `json:"id"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email pgtype.Text `json:"email"` + PhoneNumber pgtype.Text `json:"phone_number"` + Role string `json:"role"` + EmailVerified bool `json:"email_verified"` + PhoneVerified bool `json:"phone_verified"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + UpdatedAt pgtype.Timestamptz `json:"updated_at"` } func (q *Queries) SearchUserByNameOrPhone(ctx context.Context, dollar_1 pgtype.Text) ([]SearchUserByNameOrPhoneRow, error) { @@ -383,10 +383,10 @@ WHERE ( ` type UpdatePasswordParams struct { - Password []byte - Email pgtype.Text - PhoneNumber pgtype.Text - UpdatedAt pgtype.Timestamptz + Password []byte `json:"password"` + Email pgtype.Text `json:"email"` + PhoneNumber pgtype.Text `json:"phone_number"` + UpdatedAt pgtype.Timestamptz `json:"updated_at"` } func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error { @@ -411,13 +411,13 @@ WHERE id = $7 ` type UpdateUserParams struct { - FirstName string - LastName string - Email pgtype.Text - PhoneNumber pgtype.Text - Role string - UpdatedAt pgtype.Timestamptz - ID int64 + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email pgtype.Text `json:"email"` + PhoneNumber pgtype.Text `json:"phone_number"` + Role string `json:"role"` + UpdatedAt pgtype.Timestamptz `json:"updated_at"` + ID int64 `json:"id"` } func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error { diff --git a/gen/db/wallet.sql.go b/gen/db/wallet.sql.go index 5c3410a..6684284 100644 --- a/gen/db/wallet.sql.go +++ b/gen/db/wallet.sql.go @@ -23,10 +23,10 @@ RETURNING id, customer_id, company_id, regular_wallet_id, static_wallet_id, crea ` type CreateCustomerWalletParams struct { - CustomerID int64 - CompanyID int64 - RegularWalletID int64 - StaticWalletID int64 + CustomerID int64 `json:"customer_id"` + CompanyID int64 `json:"company_id"` + RegularWalletID int64 `json:"regular_wallet_id"` + StaticWalletID int64 `json:"static_wallet_id"` } func (q *Queries) CreateCustomerWallet(ctx context.Context, arg CreateCustomerWalletParams) (CustomerWallet, error) { @@ -61,10 +61,10 @@ RETURNING id, balance, is_withdraw, is_bettable, is_transferable, user_id, is_ac ` type CreateWalletParams struct { - IsWithdraw bool - IsBettable bool - IsTransferable bool - UserID int64 + IsWithdraw bool `json:"is_withdraw"` + IsBettable bool `json:"is_bettable"` + IsTransferable bool `json:"is_transferable"` + UserID int64 `json:"user_id"` } func (q *Queries) CreateWallet(ctx context.Context, arg CreateWalletParams) (Wallet, error) { @@ -105,16 +105,16 @@ FROM branches ` type GetAllBranchWalletsRow struct { - ID int64 - Balance int64 - IsActive bool - UpdatedAt pgtype.Timestamp - CreatedAt pgtype.Timestamp - Name string - Location string - BranchManagerID int64 - CompanyID int64 - IsSelfOwned bool + ID int64 `json:"id"` + Balance int64 `json:"balance"` + IsActive bool `json:"is_active"` + UpdatedAt pgtype.Timestamp `json:"updated_at"` + CreatedAt pgtype.Timestamp `json:"created_at"` + Name string `json:"name"` + Location string `json:"location"` + BranchManagerID int64 `json:"branch_manager_id"` + CompanyID int64 `json:"company_id"` + IsSelfOwned bool `json:"is_self_owned"` } func (q *Queries) GetAllBranchWallets(ctx context.Context) ([]GetAllBranchWalletsRow, error) { @@ -202,21 +202,21 @@ WHERE cw.customer_id = $1 ` type GetCustomerWalletParams struct { - CustomerID int64 - CompanyID int64 + CustomerID int64 `json:"customer_id"` + CompanyID int64 `json:"company_id"` } type GetCustomerWalletRow struct { - ID int64 - CustomerID int64 - CompanyID int64 - RegularID int64 - RegularBalance int64 - StaticID int64 - StaticBalance int64 - RegularUpdatedAt pgtype.Timestamp - StaticUpdatedAt pgtype.Timestamp - CreatedAt pgtype.Timestamp + ID int64 `json:"id"` + CustomerID int64 `json:"customer_id"` + CompanyID int64 `json:"company_id"` + RegularID int64 `json:"regular_id"` + RegularBalance int64 `json:"regular_balance"` + StaticID int64 `json:"static_id"` + StaticBalance int64 `json:"static_balance"` + RegularUpdatedAt pgtype.Timestamp `json:"regular_updated_at"` + StaticUpdatedAt pgtype.Timestamp `json:"static_updated_at"` + CreatedAt pgtype.Timestamp `json:"created_at"` } func (q *Queries) GetCustomerWallet(ctx context.Context, arg GetCustomerWalletParams) (GetCustomerWalletRow, error) { @@ -304,8 +304,8 @@ WHERE id = $2 ` type UpdateBalanceParams struct { - Balance int64 - ID int64 + Balance int64 `json:"balance"` + ID int64 `json:"id"` } func (q *Queries) UpdateBalance(ctx context.Context, arg UpdateBalanceParams) error { @@ -321,8 +321,8 @@ WHERE id = $2 ` type UpdateWalletActiveParams struct { - IsActive bool - ID int64 + IsActive bool `json:"is_active"` + ID int64 `json:"id"` } func (q *Queries) UpdateWalletActive(ctx context.Context, arg UpdateWalletActiveParams) error { diff --git a/internal/domain/ticket.go b/internal/domain/ticket.go index 18cbf68..50e23f3 100644 --- a/internal/domain/ticket.go +++ b/internal/domain/ticket.go @@ -1,10 +1,10 @@ package domain type TicketOutcome struct { - ID int64 - TicketID int64 - EventID int64 - OddID int64 + ID int64 `json:"id" example:"1"` + TicketID int64 `json:"ticket_id" example:"1"` + EventID int64 `json:"event_id" example:"1"` + OddID int64 `json:"odd_id" example:"1"` } type CreateTicketOutcome struct { diff --git a/internal/repository/ticket.go b/internal/repository/ticket.go index a2d5c1a..cefdbf8 100644 --- a/internal/repository/ticket.go +++ b/internal/repository/ticket.go @@ -2,6 +2,7 @@ package repository import ( "context" + "fmt" dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db" "github.com/SamuelTariku/FortuneBet-Backend/internal/domain" @@ -78,6 +79,7 @@ func (s *Store) CreateTicketOutcome(ctx context.Context, outcomes []domain.Creat func (s *Store) GetTicketByID(ctx context.Context, id int64) (domain.GetTicket, error) { ticket, err := s.queries.GetTicketByID(ctx, id) + if err != nil { return domain.GetTicket{}, err } @@ -87,7 +89,7 @@ func (s *Store) GetTicketByID(ctx context.Context, id int64) (domain.GetTicket, func (s *Store) GetAllTickets(ctx context.Context) ([]domain.GetTicket, error) { tickets, err := s.queries.GetAllTickets(ctx) - + fmt.Printf("%v", tickets) if err != nil { return nil, err } @@ -95,6 +97,7 @@ func (s *Store) GetAllTickets(ctx context.Context) ([]domain.GetTicket, error) { var result []domain.GetTicket = make([]domain.GetTicket, 0, len(tickets)) for _, ticket := range tickets { result = append(result, convertDBTicketOutcomes(ticket)) + // fmt.Printf("%v", convertDBTicketOutcomes(ticket)) } return result, nil diff --git a/internal/web_server/cron.go b/internal/web_server/cron.go index 68ddcf2..4b4b5f4 100644 --- a/internal/web_server/cron.go +++ b/internal/web_server/cron.go @@ -1,7 +1,6 @@ package httpserver import ( - "context" "log" eventsvc "github.com/SamuelTariku/FortuneBet-Backend/internal/services/event" @@ -16,31 +15,38 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S spec string task func() }{ - { - spec: "0 0 * * * *", // Every hour - task: func() { - if err := eventService.FetchUpcomingEvents(context.Background()); err != nil { - log.Printf(" FetchUpcomingEvents error: %v", err) - } - }, - }, - { - spec: "*/5 * * * * *", // Every 5 seconds - task: func() { - if err := eventService.FetchLiveEvents(context.Background()); err != nil { - log.Printf(" FetchLiveEvents error: %v", err) - } - }, - }, - { - spec: "*/5 * * * * *", // Every 5 seconds - task: func() { - if err := oddsService.FetchNonLiveOdds(context.Background()); err != nil { - log.Printf(" FetchNonLiveOdds error: %v", err) - } - }, - }, - + // { + // spec: "0 0 * * * *", // Every hour + // task: func() { + // if err := eventService.FetchUpcomingEvents(context.Background()); err != nil { + // log.Printf(" FetchUpcomingEvents error: %v", err) + // } + // }, + // }, + // { + // spec: "*/5 * * * * *", // Every 5 seconds + // task: func() { + // if err := eventService.FetchLiveEvents(context.Background()); err != nil { + // log.Printf(" FetchLiveEvents error: %v", err) + // } + // }, + // }, + // { + // spec: "0 0 * * * *", // Every 5 seconds + // task: func() { + // if err := eventService.FetchLiveEvents(context.Background()); err != nil { + // log.Printf(" FetchLiveEvents error: %v", err) + // } + // }, + // }, + // { + // spec: "0 0 * * * *", // Every 5 seconds + // task: func() { + // if err := oddsService.FetchNonLiveOdds(context.Background()); err != nil { + // log.Printf(" FetchNonLiveOdds error: %v", err) + // } + // }, + // }, } for _, job := range schedule { diff --git a/internal/web_server/handlers/bet_handler.go b/internal/web_server/handlers/bet_handler.go index efd3884..dca3acc 100644 --- a/internal/web_server/handlers/bet_handler.go +++ b/internal/web_server/handlers/bet_handler.go @@ -56,7 +56,6 @@ type CreateBetReq struct { FullName string `json:"full_name" example:"John"` PhoneNumber string `json:"phone_number" example:"1234567890"` IsShopBet bool `json:"is_shop_bet" example:"false"` - BranchID NullableInt64 `json:"branch_id" example:"1"` } type CreateBetRes struct { @@ -127,7 +126,6 @@ func CreateBet(logger *slog.Logger, betSvc *bet.Service, userSvc *user.Service, // Get user_id from middleware userID := c.Locals("user_id").(int64) - var isShopBet bool var req CreateBetReq @@ -145,18 +143,12 @@ func CreateBet(logger *slog.Logger, betSvc *bet.Service, userSvc *user.Service, } user, err := userSvc.GetUserByID(c.Context(), userID) - - if user.Role != domain.RoleCustomer { - isShopBet = true - if !req.BranchID.Valid { - logger.Error("CreateBetReq failed, branch id necessary") - return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ - "error": "Branch ID necessary", - }) - } + cashoutUUID := uuid.New() + var bet domain.Bet + if user.Role != domain.RoleCashier { // Get the branch from the branch ID - branch, err := branchSvc.GetBranchByID(c.Context(), req.BranchID.Value) + branch, err := branchSvc.GetBranchByCashier(c.Context(), user.ID) if err != nil { logger.Error("CreateBetReq failed, branch id invalid") return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ @@ -165,43 +157,58 @@ func CreateBet(logger *slog.Logger, betSvc *bet.Service, userSvc *user.Service, } // Deduct a percentage of the amount + // TODO move to service layer var deductedAmount = req.Amount / 10 - err = walletSvc.DeductFromWallet(c.Context(), branch.WalletID, domain.Currency(deductedAmount)) + err = walletSvc.DeductFromWallet(c.Context(), branch.WalletID, domain.ToCurrency(deductedAmount)) if err != nil { - logger.Error("CreateBetReq failed, unable to deduct from WalletID", branch.WalletID) + logger.Error("CreateBetReq failed, unable to deduct from WalletID") return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ "error": "Unable to deduct from branch wallet", }) } + bet, err = betSvc.CreateBet(c.Context(), domain.CreateBet{ + Amount: domain.ToCurrency(req.Amount), + TotalOdds: req.TotalOdds, + Status: req.Status, + FullName: req.FullName, + PhoneNumber: req.PhoneNumber, + + BranchID: domain.ValidInt64{ + Value: branch.ID, + Valid: true, + }, + UserID: domain.ValidInt64{ + Value: userID, + Valid: false, + }, + IsShopBet: req.IsShopBet, + CashoutID: cashoutUUID.String(), + }) } else { - isShopBet = false // TODO if user is customer, get id from the token then get the wallet id from there and reduce the amount + bet, err = betSvc.CreateBet(c.Context(), domain.CreateBet{ + Amount: domain.ToCurrency(req.Amount), + TotalOdds: req.TotalOdds, + Status: req.Status, + FullName: req.FullName, + PhoneNumber: req.PhoneNumber, + + BranchID: domain.ValidInt64{ + Value: 0, + Valid: false, + }, + UserID: domain.ValidInt64{ + Value: userID, + Valid: true, + }, + IsShopBet: req.IsShopBet, + CashoutID: cashoutUUID.String(), + }) } // TODO Validate Outcomes Here and make sure they didn't expire - cashoutUUID := uuid.New() - - bet, err := betSvc.CreateBet(c.Context(), domain.CreateBet{ - Amount: domain.Currency(req.Amount), - TotalOdds: req.TotalOdds, - Status: req.Status, - FullName: req.FullName, - PhoneNumber: req.PhoneNumber, - - BranchID: domain.ValidInt64{ - Value: req.BranchID.Value, - Valid: isShopBet, - }, - UserID: domain.ValidInt64{ - Value: userID, - Valid: !isShopBet, - }, - IsShopBet: req.IsShopBet, - CashoutID: cashoutUUID.String(), - }) - if err != nil { logger.Error("CreateBetReq failed", "error", err) return response.WriteJSON(c, fiber.StatusInternalServerError, "Internal Server Error", err, nil) diff --git a/internal/web_server/handlers/ticket_handler.go b/internal/web_server/handlers/ticket_handler.go index a5bf943..013eca6 100644 --- a/internal/web_server/handlers/ticket_handler.go +++ b/internal/web_server/handlers/ticket_handler.go @@ -57,7 +57,7 @@ func CreateTicket(logger *slog.Logger, ticketSvc *ticket.Service, // TODO Validate Outcomes Here and make sure they didn't expire ticket, err := ticketSvc.CreateTicket(c.Context(), domain.CreateTicket{ - Amount: domain.Currency(req.Amount), + Amount: domain.ToCurrency(req.Amount), TotalOdds: req.TotalOdds, }) if err != nil { diff --git a/internal/web_server/handlers/transaction_handler.go b/internal/web_server/handlers/transaction_handler.go index 1b5e9fa..c5b5ea4 100644 --- a/internal/web_server/handlers/transaction_handler.go +++ b/internal/web_server/handlers/transaction_handler.go @@ -96,7 +96,7 @@ func CreateTransaction(logger *slog.Logger, transactionSvc *transaction.Service, } transaction, err := transactionSvc.CreateTransaction(c.Context(), domain.CreateTransaction{ - Amount: domain.Currency(req.Amount), + Amount: domain.ToCurrency(req.Amount), BranchID: req.BranchID, CashierID: req.CashierID, BetID: req.BetID, diff --git a/internal/web_server/handlers/transfer_handler.go b/internal/web_server/handlers/transfer_handler.go index c3d71af..983164e 100644 --- a/internal/web_server/handlers/transfer_handler.go +++ b/internal/web_server/handlers/transfer_handler.go @@ -64,10 +64,14 @@ func convertTransfer(transfer domain.Transfer) TransferWalletRes { } type CreateTransferReq struct { - Amount float64 `json:"amount" example:"100.0"` + Amount float32 `json:"amount" example:"100.0"` PaymentMethod string `json:"payment_method" example:"cash"` } +type CreateRefillReq struct { + Amount float32 `json:"amount" example:"100.0"` +} + // GetTransfersByWallet godoc // @Summary Get transfer by wallet // @Description Get transfer by wallet @@ -165,7 +169,7 @@ func TransferToWallet(logger *slog.Logger, walletSvc *wallet.Service, branchSvc return nil } - transfer, err := walletSvc.TransferToWallet(c.Context(), senderID, receiverID, domain.Currency(req.Amount), domain.PaymentMethod(req.PaymentMethod), domain.ValidInt64{Value: userID, Valid: true}) + transfer, err := walletSvc.TransferToWallet(c.Context(), senderID, receiverID, domain.ToCurrency(req.Amount), domain.PaymentMethod(req.PaymentMethod), domain.ValidInt64{Value: userID, Valid: true}) if !ok { response.WriteJSON(c, fiber.StatusInternalServerError, "Transfer Failed", err, nil) @@ -210,10 +214,10 @@ func RefillWallet(logger *slog.Logger, walletSvc *wallet.Service, validator *cus return response.WriteJSON(c, fiber.StatusUnauthorized, "Unauthorized access", nil, nil) } - var req CreateTransferReq + var req CreateRefillReq if err := c.BodyParser(&req); err != nil { - logger.Error("CreateTransferReq failed", "error", err) + logger.Error("CreateRefillReq failed", "error", err) return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ "error": "Invalid request", }) @@ -226,8 +230,8 @@ func RefillWallet(logger *slog.Logger, walletSvc *wallet.Service, validator *cus } transfer, err := walletSvc.RefillWallet(c.Context(), domain.CreateTransfer{ - Amount: domain.Currency(req.Amount), - PaymentMethod: domain.PaymentMethod(req.PaymentMethod), + Amount: domain.ToCurrency(req.Amount), + PaymentMethod: domain.TRANSFER_BANK, ReceiverWalletID: receiverID, CashierID: domain.ValidInt64{ Value: userID, diff --git a/internal/web_server/routes.go b/internal/web_server/routes.go index b2b6063..f199a7d 100644 --- a/internal/web_server/routes.go +++ b/internal/web_server/routes.go @@ -57,7 +57,6 @@ func (a *App) initAppRoutes() { a.fiber.Get("/company/:id/branch", handlers.GetBranchByCompanyID(a.logger, a.branchSvc, a.validator)) - a.fiber.Get("/prematch/odds/:event_id", handlers.GetPrematchOdds(a.logger, a.prematchSvc)) // Swagger @@ -103,7 +102,7 @@ func (a *App) initAppRoutes() { // /transfer/wallet - transfer from one wallet to another wallet a.fiber.Post("/transfer/wallet/:id", a.authMiddleware, handlers.TransferToWallet(a.logger, a.walletSvc, a.branchSvc, a.validator)) a.fiber.Get("/transfer/wallet/:id", a.authMiddleware, handlers.GetTransfersByWallet(a.logger, a.walletSvc, a.validator)) - a.fiber.Get("/transfer/refill/:id", a.authMiddleware, handlers.RefillWallet(a.logger, a.walletSvc, a.validator)) + a.fiber.Post("/transfer/refill/:id", a.authMiddleware, handlers.RefillWallet(a.logger, a.walletSvc, a.validator)) // Transactions a.fiber.Post("/transaction", a.authMiddleware, handlers.CreateTransaction(a.logger, a.transactionSvc, a.validator)) diff --git a/sqlc.yaml b/sqlc.yaml index 5e2ff3a..dca5591 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -9,7 +9,7 @@ sql: sql_package: "pgx/v5" out: "./gen/db" emit_exported_queries: true - emit_json_tags: false + emit_json_tags: true overrides: - db_type: "uuid" go_type: "github.com/google/uuid.UUID"