Merge branch 'wallet'

This commit is contained in:
Samuel Tariku 2025-04-10 16:06:24 +03:00
commit 06cd464672
17 changed files with 104 additions and 28 deletions

View File

@ -46,14 +46,15 @@ CREATE TABLE IF NOT EXISTS bets (
phone_number VARCHAR(255) NOT NULL, phone_number VARCHAR(255) NOT NULL,
branch_id BIGINT, branch_id BIGINT,
user_id BIGINT, user_id BIGINT,
cashed_out BOOLEAN DEFAULT FALSE, cashed_out BOOLEAN DEFAULT FALSE NOT NULL,
cashout_id VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_shop_bet BOOLEAN NOT NULL, is_shop_bet BOOLEAN NOT NULL,
CHECK (user_id IS NOT NULL OR branch_id IS NOT NULL) CHECK (user_id IS NOT NULL OR branch_id IS NOT NULL)
); );
CREATE TABLE IF NOT EXISTS tickets ( CREATE TABLE IF NOT EXISTS `tickets` (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
amount BIGINT NULL, amount BIGINT NULL,
total_odds REAL NOT NULL, total_odds REAL NOT NULL,
@ -118,6 +119,7 @@ CREATE TABLE IF NOT EXISTS transactions (
branch_id BIGINT NOT NULL, branch_id BIGINT NOT NULL,
cashier_id BIGINT NOT NULL, cashier_id BIGINT NOT NULL,
bet_id BIGINT NOT NULL, bet_id BIGINT NOT NULL,
type BIGINT NOT NULL,
payment_option BIGINT NOT NULL, payment_option BIGINT NOT NULL,
full_name VARCHAR(255) NOT NULL, full_name VARCHAR(255) NOT NULL,
phone_number VARCHAR(255) NOT NULL, phone_number VARCHAR(255) NOT NULL,

View File

@ -1,6 +1,6 @@
-- name: CreateBet :one -- name: CreateBet :one
INSERT INTO bets (amount, total_odds, status, full_name, phone_number, branch_id, user_id, is_shop_bet) INSERT INTO bets (amount, total_odds, status, full_name, phone_number, branch_id, user_id, is_shop_bet, cashout_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
RETURNING *; RETURNING *;
-- name: GetAllBets :many -- name: GetAllBets :many

View File

@ -1,5 +1,5 @@
-- name: CreateTransaction :one -- name: CreateTransaction :one
INSERT INTO transactions (amount, branch_id, cashier_id, bet_id, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *; INSERT INTO transactions (amount, branch_id, cashier_id, bet_id, type, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING *;
-- name: GetAllTransactions :many -- name: GetAllTransactions :many
SELECT * FROM transactions; SELECT * FROM transactions;

View File

@ -2533,6 +2533,10 @@ const docTemplate = `{
}, },
"reference_number": { "reference_number": {
"type": "string" "type": "string"
},
"type": {
"type": "integer",
"example": 1
} }
} }
}, },
@ -2774,6 +2778,10 @@ const docTemplate = `{
"reference_number": { "reference_number": {
"type": "string" "type": "string"
}, },
"type": {
"type": "integer",
"example": 1
},
"verified": { "verified": {
"type": "boolean", "type": "boolean",
"example": true "example": true

View File

@ -2525,6 +2525,10 @@
}, },
"reference_number": { "reference_number": {
"type": "string" "type": "string"
},
"type": {
"type": "integer",
"example": 1
} }
} }
}, },
@ -2766,6 +2770,10 @@
"reference_number": { "reference_number": {
"type": "string" "type": "string"
}, },
"type": {
"type": "integer",
"example": 1
},
"verified": { "verified": {
"type": "boolean", "type": "boolean",
"example": true "example": true

View File

@ -306,6 +306,9 @@ definitions:
type: string type: string
reference_number: reference_number:
type: string type: string
type:
example: 1
type: integer
type: object type: object
handlers.CreateTransferReq: handlers.CreateTransferReq:
properties: properties:
@ -473,6 +476,9 @@ definitions:
type: string type: string
reference_number: reference_number:
type: string type: string
type:
example: 1
type: integer
verified: verified:
example: true example: true
type: boolean type: boolean

View File

@ -12,9 +12,9 @@ import (
) )
const CreateBet = `-- name: CreateBet :one const CreateBet = `-- name: CreateBet :one
INSERT INTO bets (amount, total_odds, status, full_name, phone_number, branch_id, user_id, is_shop_bet) INSERT INTO bets (amount, total_odds, status, full_name, phone_number, branch_id, user_id, is_shop_bet, cashout_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
RETURNING id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, created_at, updated_at, is_shop_bet RETURNING id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, cashout_id, created_at, updated_at, is_shop_bet
` `
type CreateBetParams struct { type CreateBetParams struct {
@ -26,6 +26,7 @@ type CreateBetParams struct {
BranchID pgtype.Int8 BranchID pgtype.Int8
UserID pgtype.Int8 UserID pgtype.Int8
IsShopBet bool IsShopBet bool
CashoutID string
} }
func (q *Queries) CreateBet(ctx context.Context, arg CreateBetParams) (Bet, error) { func (q *Queries) CreateBet(ctx context.Context, arg CreateBetParams) (Bet, error) {
@ -38,6 +39,7 @@ func (q *Queries) CreateBet(ctx context.Context, arg CreateBetParams) (Bet, erro
arg.BranchID, arg.BranchID,
arg.UserID, arg.UserID,
arg.IsShopBet, arg.IsShopBet,
arg.CashoutID,
) )
var i Bet var i Bet
err := row.Scan( err := row.Scan(
@ -50,6 +52,7 @@ func (q *Queries) CreateBet(ctx context.Context, arg CreateBetParams) (Bet, erro
&i.BranchID, &i.BranchID,
&i.UserID, &i.UserID,
&i.CashedOut, &i.CashedOut,
&i.CashoutID,
&i.CreatedAt, &i.CreatedAt,
&i.UpdatedAt, &i.UpdatedAt,
&i.IsShopBet, &i.IsShopBet,
@ -67,7 +70,7 @@ func (q *Queries) DeleteBet(ctx context.Context, id int64) error {
} }
const GetAllBets = `-- name: GetAllBets :many const GetAllBets = `-- name: GetAllBets :many
SELECT id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, created_at, updated_at, is_shop_bet FROM bets SELECT id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, cashout_id, created_at, updated_at, is_shop_bet FROM bets
` `
func (q *Queries) GetAllBets(ctx context.Context) ([]Bet, error) { func (q *Queries) GetAllBets(ctx context.Context) ([]Bet, error) {
@ -89,6 +92,7 @@ func (q *Queries) GetAllBets(ctx context.Context) ([]Bet, error) {
&i.BranchID, &i.BranchID,
&i.UserID, &i.UserID,
&i.CashedOut, &i.CashedOut,
&i.CashoutID,
&i.CreatedAt, &i.CreatedAt,
&i.UpdatedAt, &i.UpdatedAt,
&i.IsShopBet, &i.IsShopBet,
@ -104,7 +108,7 @@ func (q *Queries) GetAllBets(ctx context.Context) ([]Bet, error) {
} }
const GetBetByID = `-- name: GetBetByID :one const GetBetByID = `-- name: GetBetByID :one
SELECT id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, created_at, updated_at, is_shop_bet FROM bets WHERE id = $1 SELECT id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, cashout_id, created_at, updated_at, is_shop_bet FROM bets WHERE id = $1
` `
func (q *Queries) GetBetByID(ctx context.Context, id int64) (Bet, error) { func (q *Queries) GetBetByID(ctx context.Context, id int64) (Bet, error) {
@ -120,6 +124,7 @@ func (q *Queries) GetBetByID(ctx context.Context, id int64) (Bet, error) {
&i.BranchID, &i.BranchID,
&i.UserID, &i.UserID,
&i.CashedOut, &i.CashedOut,
&i.CashoutID,
&i.CreatedAt, &i.CreatedAt,
&i.UpdatedAt, &i.UpdatedAt,
&i.IsShopBet, &i.IsShopBet,
@ -133,7 +138,7 @@ UPDATE bets SET cashed_out = $2, updated_at = CURRENT_TIMESTAMP WHERE id = $1
type UpdateCashOutParams struct { type UpdateCashOutParams struct {
ID int64 ID int64
CashedOut pgtype.Bool CashedOut bool
} }
func (q *Queries) UpdateCashOut(ctx context.Context, arg UpdateCashOutParams) error { func (q *Queries) UpdateCashOut(ctx context.Context, arg UpdateCashOutParams) error {

View File

@ -17,7 +17,8 @@ type Bet struct {
PhoneNumber string PhoneNumber string
BranchID pgtype.Int8 BranchID pgtype.Int8
UserID pgtype.Int8 UserID pgtype.Int8
CashedOut pgtype.Bool CashedOut bool
CashoutID string
CreatedAt pgtype.Timestamp CreatedAt pgtype.Timestamp
UpdatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp
IsShopBet bool IsShopBet bool
@ -125,6 +126,7 @@ type Transaction struct {
BranchID int64 BranchID int64
CashierID int64 CashierID int64
BetID int64 BetID int64
Type int64
PaymentOption int64 PaymentOption int64
FullName string FullName string
PhoneNumber string PhoneNumber string

View File

@ -10,7 +10,7 @@ import (
) )
const CreateTransaction = `-- name: CreateTransaction :one const CreateTransaction = `-- name: CreateTransaction :one
INSERT INTO transactions (amount, branch_id, cashier_id, bet_id, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING id, amount, branch_id, cashier_id, bet_id, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number, verified, created_at, updated_at INSERT INTO transactions (amount, branch_id, cashier_id, bet_id, type, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING id, amount, branch_id, cashier_id, bet_id, type, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number, verified, created_at, updated_at
` `
type CreateTransactionParams struct { type CreateTransactionParams struct {
@ -18,6 +18,7 @@ type CreateTransactionParams struct {
BranchID int64 BranchID int64
CashierID int64 CashierID int64
BetID int64 BetID int64
Type int64
PaymentOption int64 PaymentOption int64
FullName string FullName string
PhoneNumber string PhoneNumber string
@ -34,6 +35,7 @@ func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionPa
arg.BranchID, arg.BranchID,
arg.CashierID, arg.CashierID,
arg.BetID, arg.BetID,
arg.Type,
arg.PaymentOption, arg.PaymentOption,
arg.FullName, arg.FullName,
arg.PhoneNumber, arg.PhoneNumber,
@ -50,6 +52,7 @@ func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionPa
&i.BranchID, &i.BranchID,
&i.CashierID, &i.CashierID,
&i.BetID, &i.BetID,
&i.Type,
&i.PaymentOption, &i.PaymentOption,
&i.FullName, &i.FullName,
&i.PhoneNumber, &i.PhoneNumber,
@ -66,7 +69,7 @@ func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionPa
} }
const GetAllTransactions = `-- name: GetAllTransactions :many const GetAllTransactions = `-- name: GetAllTransactions :many
SELECT id, amount, branch_id, cashier_id, bet_id, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number, verified, created_at, updated_at FROM transactions SELECT id, amount, branch_id, cashier_id, bet_id, type, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number, verified, created_at, updated_at FROM transactions
` `
func (q *Queries) GetAllTransactions(ctx context.Context) ([]Transaction, error) { func (q *Queries) GetAllTransactions(ctx context.Context) ([]Transaction, error) {
@ -84,6 +87,7 @@ func (q *Queries) GetAllTransactions(ctx context.Context) ([]Transaction, error)
&i.BranchID, &i.BranchID,
&i.CashierID, &i.CashierID,
&i.BetID, &i.BetID,
&i.Type,
&i.PaymentOption, &i.PaymentOption,
&i.FullName, &i.FullName,
&i.PhoneNumber, &i.PhoneNumber,
@ -107,7 +111,7 @@ func (q *Queries) GetAllTransactions(ctx context.Context) ([]Transaction, error)
} }
const GetTransactionByBranch = `-- name: GetTransactionByBranch :many const GetTransactionByBranch = `-- name: GetTransactionByBranch :many
SELECT id, amount, branch_id, cashier_id, bet_id, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number, verified, created_at, updated_at FROM transactions WHERE branch_id = $1 SELECT id, amount, branch_id, cashier_id, bet_id, type, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number, verified, created_at, updated_at FROM transactions WHERE branch_id = $1
` `
func (q *Queries) GetTransactionByBranch(ctx context.Context, branchID int64) ([]Transaction, error) { func (q *Queries) GetTransactionByBranch(ctx context.Context, branchID int64) ([]Transaction, error) {
@ -125,6 +129,7 @@ func (q *Queries) GetTransactionByBranch(ctx context.Context, branchID int64) ([
&i.BranchID, &i.BranchID,
&i.CashierID, &i.CashierID,
&i.BetID, &i.BetID,
&i.Type,
&i.PaymentOption, &i.PaymentOption,
&i.FullName, &i.FullName,
&i.PhoneNumber, &i.PhoneNumber,
@ -148,7 +153,7 @@ func (q *Queries) GetTransactionByBranch(ctx context.Context, branchID int64) ([
} }
const GetTransactionByID = `-- name: GetTransactionByID :one const GetTransactionByID = `-- name: GetTransactionByID :one
SELECT id, amount, branch_id, cashier_id, bet_id, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number, verified, created_at, updated_at FROM transactions WHERE id = $1 SELECT id, amount, branch_id, cashier_id, bet_id, type, payment_option, full_name, phone_number, bank_code, beneficiary_name, account_name, account_number, reference_number, verified, created_at, updated_at FROM transactions WHERE id = $1
` `
func (q *Queries) GetTransactionByID(ctx context.Context, id int64) (Transaction, error) { func (q *Queries) GetTransactionByID(ctx context.Context, id int64) (Transaction, error) {
@ -160,6 +165,7 @@ func (q *Queries) GetTransactionByID(ctx context.Context, id int64) (Transaction
&i.BranchID, &i.BranchID,
&i.CashierID, &i.CashierID,
&i.BetID, &i.BetID,
&i.Type,
&i.PaymentOption, &i.PaymentOption,
&i.FullName, &i.FullName,
&i.PhoneNumber, &i.PhoneNumber,

View File

@ -36,6 +36,7 @@ type CreateBet struct {
BranchID ValidInt64 // Can Be Nullable BranchID ValidInt64 // Can Be Nullable
UserID ValidInt64 // Can Be Nullable UserID ValidInt64 // Can Be Nullable
IsShopBet bool IsShopBet bool
CashoutID string
} }
func (b BetStatus) String() string { func (b BetStatus) String() string {

View File

@ -1,5 +1,12 @@
package domain package domain
type TransactionType int
const (
TRANSACTION_CASHOUT TransactionType = iota
TRANSACTION_DEPOSIT
)
type PaymentOption int64 type PaymentOption int64
const ( const (
@ -8,6 +15,7 @@ const (
ARIFPAY_TRANSACTION ARIFPAY_TRANSACTION
BANK BANK
) )
// Transaction only represents when the user cashes out a bet in the shop // Transaction only represents when the user cashes out a bet in the shop
// It probably would be better to call it a CashOut or ShopWithdrawal // It probably would be better to call it a CashOut or ShopWithdrawal
type Transaction struct { type Transaction struct {
@ -16,6 +24,7 @@ type Transaction struct {
BranchID int64 BranchID int64
CashierID int64 CashierID int64
BetID int64 BetID int64
Type TransactionType
PaymentOption PaymentOption PaymentOption PaymentOption
FullName string FullName string
PhoneNumber string PhoneNumber string
@ -33,6 +42,7 @@ type CreateTransaction struct {
BranchID int64 BranchID int64
CashierID int64 CashierID int64
BetID int64 BetID int64
Type TransactionType
PaymentOption PaymentOption PaymentOption PaymentOption
FullName string FullName string
PhoneNumber string PhoneNumber string

View File

@ -25,6 +25,8 @@ func convertDBBet(bet dbgen.Bet) domain.Bet {
Valid: bet.UserID.Valid, Valid: bet.UserID.Valid,
}, },
IsShopBet: bet.IsShopBet, IsShopBet: bet.IsShopBet,
CashedOut: bet.CashedOut,
CashoutID: bet.CashoutID,
} }
} }
@ -44,6 +46,7 @@ func convertCreateBet(bet domain.CreateBet) dbgen.CreateBetParams {
Valid: bet.UserID.Valid, Valid: bet.UserID.Valid,
}, },
IsShopBet: bet.IsShopBet, IsShopBet: bet.IsShopBet,
CashoutID: bet.CashoutID,
} }
} }
@ -83,10 +86,8 @@ func (s *Store) GetAllBets(ctx context.Context) ([]domain.Bet, error) {
func (s *Store) UpdateCashOut(ctx context.Context, id int64, cashedOut bool) error { func (s *Store) UpdateCashOut(ctx context.Context, id int64, cashedOut bool) error {
err := s.queries.UpdateCashOut(ctx, dbgen.UpdateCashOutParams{ err := s.queries.UpdateCashOut(ctx, dbgen.UpdateCashOutParams{
ID: id, ID: id,
CashedOut: pgtype.Bool{ CashedOut: cashedOut,
Bool: cashedOut,
},
}) })
return err return err
} }

View File

@ -13,6 +13,7 @@ func convertDBTransaction(transaction dbgen.Transaction) domain.Transaction {
BranchID: transaction.BranchID, BranchID: transaction.BranchID,
CashierID: transaction.CashierID, CashierID: transaction.CashierID,
BetID: transaction.BetID, BetID: transaction.BetID,
Type: domain.TransactionType(transaction.Type),
PaymentOption: domain.PaymentOption(transaction.PaymentOption), PaymentOption: domain.PaymentOption(transaction.PaymentOption),
FullName: transaction.FullName, FullName: transaction.FullName,
PhoneNumber: transaction.PhoneNumber, PhoneNumber: transaction.PhoneNumber,
@ -30,6 +31,7 @@ func convertCreateTransaction(transaction domain.CreateTransaction) dbgen.Create
BranchID: transaction.BranchID, BranchID: transaction.BranchID,
CashierID: transaction.CashierID, CashierID: transaction.CashierID,
BetID: transaction.BetID, BetID: transaction.BetID,
Type: int64(transaction.Type),
PaymentOption: int64(transaction.PaymentOption), PaymentOption: int64(transaction.PaymentOption),
FullName: transaction.FullName, FullName: transaction.FullName,
PhoneNumber: transaction.PhoneNumber, PhoneNumber: transaction.PhoneNumber,

View File

@ -9,6 +9,7 @@ import (
"github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/response" "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/response"
customvalidator "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/validator" customvalidator "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/validator"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/google/uuid"
) )
type CreateBetReq struct { type CreateBetReq struct {
@ -65,7 +66,6 @@ func CreateBet(logger *slog.Logger, betSvc *bet.Service, validator *customvalida
// TODO: If user is a cashier, check the token, and find the role and get the branch id from there. Reduce amount from the branch wallet // TODO: If user is a cashier, check the token, and find the role and get the branch id from there. Reduce amount from the branch wallet
var isShopBet bool = true var isShopBet bool = true
var branchID int64 = 1 var branchID int64 = 1
var userID int64 var userID int64
@ -87,6 +87,8 @@ func CreateBet(logger *slog.Logger, betSvc *bet.Service, validator *customvalida
// TODO Validate Outcomes Here and make sure they didn't expire // TODO Validate Outcomes Here and make sure they didn't expire
cashoutUUID := uuid.New()
bet, err := betSvc.CreateBet(c.Context(), domain.CreateBet{ bet, err := betSvc.CreateBet(c.Context(), domain.CreateBet{
Outcomes: req.Outcomes, Outcomes: req.Outcomes,
Amount: domain.Currency(req.Amount), Amount: domain.Currency(req.Amount),
@ -104,6 +106,7 @@ func CreateBet(logger *slog.Logger, betSvc *bet.Service, validator *customvalida
Valid: !isShopBet, Valid: !isShopBet,
}, },
IsShopBet: req.IsShopBet, IsShopBet: req.IsShopBet,
CashoutID: cashoutUUID.String(),
}) })
if err != nil { if err != nil {

View File

@ -151,9 +151,22 @@ func CreateBranch(logger *slog.Logger, branchSvc *branch.Service, walletSvc *wal
}) })
} }
for _, operation := range req.Operations {
err := branchSvc.CreateBranchOperation(c.Context(), domain.CreateBranchOperation{
BranchID: branch.ID,
OperationID: operation,
})
if err != nil {
logger.Error("Failed to create branch operations", "BranchID", branch.ID, "operation", operation, "error", err)
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": "Internal server error",
})
}
}
res := convertBranch(branch) res := convertBranch(branch)
return response.WriteJSON(c, fiber.StatusOK, "Branch Created", res, nil) return response.WriteJSON(c, fiber.StatusCreated, "Branch Created", res, nil)
} }

View File

@ -1,6 +1,7 @@
package handlers package handlers
import ( import (
// "fmt"
"log/slog" "log/slog"
"strconv" "strconv"
@ -13,12 +14,12 @@ import (
) )
type TransactionRes struct { type TransactionRes struct {
ID int64 `json:"id" example:"1"` ID int64 `json:"id" example:"1"`
Amount float32 `json:"amount" example:"100.0"` Amount float32 `json:"amount" example:"100.0"`
BranchID int64 `json:"branch_id" example:"1"` BranchID int64 `json:"branch_id" example:"1"`
CashierID int64 `json:"cashier_id" example:"1"` CashierID int64 `json:"cashier_id" example:"1"`
BetID int64 `json:"bet_id" example:"1"` BetID int64 `json:"bet_id" example:"1"`
Type int64 `json:"type" example:"1"`
PaymentOption domain.PaymentOption `json:"payment_option" example:"1"` PaymentOption domain.PaymentOption `json:"payment_option" example:"1"`
FullName string `json:"full_name" example:"John Smith"` FullName string `json:"full_name" example:"John Smith"`
PhoneNumber string `json:"phone_number" example:"0911111111"` PhoneNumber string `json:"phone_number" example:"0911111111"`
@ -35,6 +36,7 @@ type CreateTransactionReq struct {
BranchID int64 `json:"branch_id" example:"1"` BranchID int64 `json:"branch_id" example:"1"`
CashierID int64 `json:"cashier_id" example:"1"` CashierID int64 `json:"cashier_id" example:"1"`
BetID int64 `json:"bet_id" example:"1"` BetID int64 `json:"bet_id" example:"1"`
Type int64 `json:"type" example:"1"`
PaymentOption domain.PaymentOption `json:"payment_option" example:"1"` PaymentOption domain.PaymentOption `json:"payment_option" example:"1"`
FullName string `json:"full_name" example:"John Smith"` FullName string `json:"full_name" example:"John Smith"`
PhoneNumber string `json:"phone_number" example:"0911111111"` PhoneNumber string `json:"phone_number" example:"0911111111"`
@ -53,6 +55,7 @@ func convertTransaction(transaction domain.Transaction) TransactionRes {
BranchID: transaction.BranchID, BranchID: transaction.BranchID,
CashierID: transaction.CashierID, CashierID: transaction.CashierID,
BetID: transaction.BetID, BetID: transaction.BetID,
Type: int64(transaction.Type),
PaymentOption: transaction.PaymentOption, PaymentOption: transaction.PaymentOption,
FullName: transaction.FullName, FullName: transaction.FullName,
PhoneNumber: transaction.PhoneNumber, PhoneNumber: transaction.PhoneNumber,
@ -97,6 +100,7 @@ func CreateTransaction(logger *slog.Logger, transactionSvc *transaction.Service,
BranchID: req.BranchID, BranchID: req.BranchID,
CashierID: req.CashierID, CashierID: req.CashierID,
BetID: req.BetID, BetID: req.BetID,
Type: domain.TransactionType(req.Type),
PaymentOption: domain.PaymentOption(req.PaymentOption), PaymentOption: domain.PaymentOption(req.PaymentOption),
FullName: req.FullName, FullName: req.FullName,
PhoneNumber: req.PhoneNumber, PhoneNumber: req.PhoneNumber,

View File

@ -2,6 +2,7 @@ package httpserver
import ( import (
"errors" "errors"
"fmt"
"strings" "strings"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain" "github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
@ -13,10 +14,12 @@ func (a *App) authMiddleware(c *fiber.Ctx) error {
authHeader := c.Get("Authorization") authHeader := c.Get("Authorization")
if authHeader == "" { if authHeader == "" {
fmt.Println("Auth Header Missing")
return fiber.NewError(fiber.StatusUnauthorized, "Authorization header missing") return fiber.NewError(fiber.StatusUnauthorized, "Authorization header missing")
} }
if !strings.HasPrefix(authHeader, "Bearer ") { if !strings.HasPrefix(authHeader, "Bearer ") {
fmt.Println("Invalid authorization header format")
return fiber.NewError(fiber.StatusUnauthorized, "Invalid authorization header format") return fiber.NewError(fiber.StatusUnauthorized, "Invalid authorization header format")
} }
@ -25,8 +28,10 @@ func (a *App) authMiddleware(c *fiber.Ctx) error {
claim, err := jwtutil.ParseJwt(accessToken, a.JwtConfig.JwtAccessKey) claim, err := jwtutil.ParseJwt(accessToken, a.JwtConfig.JwtAccessKey)
if err != nil { if err != nil {
if errors.Is(err, jwtutil.ErrExpiredToken) { if errors.Is(err, jwtutil.ErrExpiredToken) {
fmt.Println("Token Expired")
return fiber.NewError(fiber.StatusUnauthorized, "Access token expired") return fiber.NewError(fiber.StatusUnauthorized, "Access token expired")
} }
fmt.Println("Invalid Token")
return fiber.NewError(fiber.StatusUnauthorized, "Invalid access token") return fiber.NewError(fiber.StatusUnauthorized, "Invalid access token")
} }