fix: integration fixes

This commit is contained in:
Samuel Tariku 2025-10-07 13:39:36 +03:00
parent c00110a503
commit d997cde387
34 changed files with 4654 additions and 826 deletions

View File

@ -73,7 +73,8 @@ CREATE TABLE IF NOT EXISTS wallets (
is_active BOOLEAN NOT NULL DEFAULT true, is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(user_id, type) UNIQUE(user_id, type),
CONSTRAINT balance_positve CHECK (balance >= 0)
); );
CREATE TABLE refresh_tokens ( CREATE TABLE refresh_tokens (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
@ -184,19 +185,19 @@ CREATE TABLE IF NOT EXISTS banks (
currency VARCHAR(10) NOT NULL, currency VARCHAR(10) NOT NULL,
bank_logo TEXT -- URL or base64 string bank_logo TEXT -- URL or base64 string
); );
CREATE TABLE IF NOT EXISTS wallets ( -- CREATE TABLE IF NOT EXISTS wallets (
id BIGSERIAL PRIMARY KEY, -- id BIGSERIAL PRIMARY KEY,
balance BIGINT NOT NULL DEFAULT 0, -- balance BIGINT NOT NULL DEFAULT 0,
is_withdraw BOOLEAN NOT NULL, -- is_withdraw BOOLEAN NOT NULL,
is_bettable BOOLEAN NOT NULL, -- is_bettable BOOLEAN NOT NULL,
is_transferable BOOLEAN NOT NULL, -- is_transferable BOOLEAN NOT NULL,
user_id BIGINT NOT NULL, -- user_id BIGINT NOT NULL,
type VARCHAR(255) NOT NULL, -- type VARCHAR(255) NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT true, -- is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT balance_positve CHECK (balance >= 0) -- CONSTRAINT balance_positve CHECK (balance >= 0)
); -- );
CREATE TABLE IF NOT EXISTS customer_wallets ( CREATE TABLE IF NOT EXISTS customer_wallets (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
customer_id BIGINT NOT NULL, customer_id BIGINT NOT NULL,
@ -270,7 +271,7 @@ CREATE TABLE IF NOT EXISTS branches (
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
location TEXT NOT NULL, location TEXT NOT NULL,
profit_percent REAL NOT NULL, profit_percent REAL NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT false, is_active BOOLEAN NOT NULL DEFAULT true,
wallet_id BIGINT NOT NULL, wallet_id BIGINT NOT NULL,
branch_manager_id BIGINT NOT NULL, branch_manager_id BIGINT NOT NULL,
company_id BIGINT NOT NULL, company_id BIGINT NOT NULL,
@ -406,7 +407,7 @@ CREATE TABLE companies (
admin_id BIGINT NOT NULL, admin_id BIGINT NOT NULL,
wallet_id BIGINT NOT NULL, wallet_id BIGINT NOT NULL,
deducted_percentage REAL NOT NULL, deducted_percentage REAL NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT false, is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT deducted_percentage_check CHECK ( CONSTRAINT deducted_percentage_check CHECK (
@ -642,6 +643,7 @@ SELECT sb.*,
st.verified AS transaction_verified, st.verified AS transaction_verified,
bets.status, bets.status,
bets.total_odds, bets.total_odds,
bets.fast_code,
JSON_AGG (bet_outcomes.*) AS outcomes JSON_AGG (bet_outcomes.*) AS outcomes
FROM shop_bets AS sb FROM shop_bets AS sb
JOIN shop_transactions st ON st.id = sb.shop_transaction_id JOIN shop_transactions st ON st.id = sb.shop_transaction_id
@ -655,7 +657,8 @@ GROUP BY sb.id,
st.amount, st.amount,
st.verified, st.verified,
bets.status, bets.status,
bets.total_odds; bets.total_odds,
bets.fast_code;
CREATE VIEW shop_deposit_detail AS CREATE VIEW shop_deposit_detail AS
SELECT sd.*, SELECT sd.*,
st.full_name, st.full_name,

View File

@ -4,9 +4,10 @@ INSERT INTO companies (
slug, slug,
admin_id, admin_id,
wallet_id, wallet_id,
deducted_percentage deducted_percentage,
is_active
) )
VALUES ($1, $2, $3, $4, $5) VALUES ($1, $2, $3, $4, $5, $6)
RETURNING *; RETURNING *;
-- name: GetAllCompanies :many -- name: GetAllCompanies :many
SELECT * SELECT *
@ -38,7 +39,7 @@ WHERE slug = $1;
SELECT * SELECT *
FROM companies_details FROM companies_details
WHERE name ILIKE '%' || $1 || '%'; WHERE name ILIKE '%' || $1 || '%';
-- name: UpdateCompany :one -- name: UpdateCompany :exec
UPDATE companies UPDATE companies
SET name = COALESCE(sqlc.narg(name), name), SET name = COALESCE(sqlc.narg(name), name),
admin_id = COALESCE(sqlc.narg(admin_id), admin_id), admin_id = COALESCE(sqlc.narg(admin_id), admin_id),
@ -47,9 +48,9 @@ SET name = COALESCE(sqlc.narg(name), name),
sqlc.narg(deducted_percentage), sqlc.narg(deducted_percentage),
deducted_percentage deducted_percentage
), ),
slug = COALESCE(sqlc.narg(slug), slug),
updated_at = CURRENT_TIMESTAMP updated_at = CURRENT_TIMESTAMP
WHERE id = $1 WHERE id = $1;
RETURNING *;
-- name: DeleteCompany :exec -- name: DeleteCompany :exec
DELETE FROM companies DELETE FROM companies
WHERE id = $1; WHERE id = $1;

View File

@ -40,8 +40,31 @@ WHERE (
name ILIKE '%' || sqlc.narg('query') || '%' name ILIKE '%' || sqlc.narg('query') || '%'
OR sqlc.narg('query') IS NULL OR sqlc.narg('query') IS NULL
) )
AND (
default_is_active = sqlc.narg('is_active')
OR sqlc.narg('is_active') IS NULL
)
ORDER BY name ASC ORDER BY name ASC
LIMIT sqlc.narg('limit') OFFSET sqlc.narg('offset'); LIMIT sqlc.narg('limit') OFFSET sqlc.narg('offset');
-- name: GetTotalLeagues :one
SELECT COUNT(*)
FROM leagues
WHERE (
country_code = sqlc.narg('country_code')
OR sqlc.narg('country_code') IS NULL
)
AND (
sport_id = sqlc.narg('sport_id')
OR sqlc.narg('sport_id') IS NULL
)
AND (
name ILIKE '%' || sqlc.narg('query') || '%'
OR sqlc.narg('query') IS NULL
)
AND (
default_is_active = sqlc.narg('is_active')
OR sqlc.narg('is_active') IS NULL
);
-- name: GetTotalLeaguesWithSettings :one -- name: GetTotalLeaguesWithSettings :one
SELECT COUNT(*) SELECT COUNT(*)
FROM leagues l FROM leagues l

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -17,9 +17,10 @@ INSERT INTO companies (
slug, slug,
admin_id, admin_id,
wallet_id, wallet_id,
deducted_percentage deducted_percentage,
is_active
) )
VALUES ($1, $2, $3, $4, $5) VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, name, slug, admin_id, wallet_id, deducted_percentage, is_active, created_at, updated_at RETURNING id, name, slug, admin_id, wallet_id, deducted_percentage, is_active, created_at, updated_at
` `
@ -29,6 +30,7 @@ type CreateCompanyParams struct {
AdminID int64 `json:"admin_id"` AdminID int64 `json:"admin_id"`
WalletID int64 `json:"wallet_id"` WalletID int64 `json:"wallet_id"`
DeductedPercentage float32 `json:"deducted_percentage"` DeductedPercentage float32 `json:"deducted_percentage"`
IsActive bool `json:"is_active"`
} }
func (q *Queries) CreateCompany(ctx context.Context, arg CreateCompanyParams) (Company, error) { func (q *Queries) CreateCompany(ctx context.Context, arg CreateCompanyParams) (Company, error) {
@ -38,6 +40,7 @@ func (q *Queries) CreateCompany(ctx context.Context, arg CreateCompanyParams) (C
arg.AdminID, arg.AdminID,
arg.WalletID, arg.WalletID,
arg.DeductedPercentage, arg.DeductedPercentage,
arg.IsActive,
) )
var i Company var i Company
err := row.Scan( err := row.Scan(
@ -217,7 +220,7 @@ func (q *Queries) SearchCompanyByName(ctx context.Context, dollar_1 pgtype.Text)
return items, nil return items, nil
} }
const UpdateCompany = `-- name: UpdateCompany :one const UpdateCompany = `-- name: UpdateCompany :exec
UPDATE companies UPDATE companies
SET name = COALESCE($2, name), SET name = COALESCE($2, name),
admin_id = COALESCE($3, admin_id), admin_id = COALESCE($3, admin_id),
@ -226,9 +229,9 @@ SET name = COALESCE($2, name),
$5, $5,
deducted_percentage deducted_percentage
), ),
slug = COALESCE($6, slug),
updated_at = CURRENT_TIMESTAMP updated_at = CURRENT_TIMESTAMP
WHERE id = $1 WHERE id = $1
RETURNING id, name, slug, admin_id, wallet_id, deducted_percentage, is_active, created_at, updated_at
` `
type UpdateCompanyParams struct { type UpdateCompanyParams struct {
@ -237,27 +240,17 @@ type UpdateCompanyParams struct {
AdminID pgtype.Int8 `json:"admin_id"` AdminID pgtype.Int8 `json:"admin_id"`
IsActive pgtype.Bool `json:"is_active"` IsActive pgtype.Bool `json:"is_active"`
DeductedPercentage pgtype.Float4 `json:"deducted_percentage"` DeductedPercentage pgtype.Float4 `json:"deducted_percentage"`
Slug pgtype.Text `json:"slug"`
} }
func (q *Queries) UpdateCompany(ctx context.Context, arg UpdateCompanyParams) (Company, error) { func (q *Queries) UpdateCompany(ctx context.Context, arg UpdateCompanyParams) error {
row := q.db.QueryRow(ctx, UpdateCompany, _, err := q.db.Exec(ctx, UpdateCompany,
arg.ID, arg.ID,
arg.Name, arg.Name,
arg.AdminID, arg.AdminID,
arg.IsActive, arg.IsActive,
arg.DeductedPercentage, arg.DeductedPercentage,
arg.Slug,
) )
var i Company return err
err := row.Scan(
&i.ID,
&i.Name,
&i.Slug,
&i.AdminID,
&i.WalletID,
&i.DeductedPercentage,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
} }

View File

@ -48,14 +48,19 @@ WHERE (
name ILIKE '%' || $3 || '%' name ILIKE '%' || $3 || '%'
OR $3 IS NULL OR $3 IS NULL
) )
AND (
default_is_active = $4
OR $4 IS NULL
)
ORDER BY name ASC ORDER BY name ASC
LIMIT $5 OFFSET $4 LIMIT $6 OFFSET $5
` `
type GetAllLeaguesParams struct { type GetAllLeaguesParams struct {
CountryCode pgtype.Text `json:"country_code"` CountryCode pgtype.Text `json:"country_code"`
SportID pgtype.Int4 `json:"sport_id"` SportID pgtype.Int4 `json:"sport_id"`
Query pgtype.Text `json:"query"` Query pgtype.Text `json:"query"`
IsActive pgtype.Bool `json:"is_active"`
Offset pgtype.Int4 `json:"offset"` Offset pgtype.Int4 `json:"offset"`
Limit pgtype.Int4 `json:"limit"` Limit pgtype.Int4 `json:"limit"`
} }
@ -65,6 +70,7 @@ func (q *Queries) GetAllLeagues(ctx context.Context, arg GetAllLeaguesParams) ([
arg.CountryCode, arg.CountryCode,
arg.SportID, arg.SportID,
arg.Query, arg.Query,
arg.IsActive,
arg.Offset, arg.Offset,
arg.Limit, arg.Limit,
) )
@ -199,6 +205,46 @@ func (q *Queries) GetAllLeaguesWithSettings(ctx context.Context, arg GetAllLeagu
return items, nil return items, nil
} }
const GetTotalLeagues = `-- name: GetTotalLeagues :one
SELECT COUNT(*)
FROM leagues
WHERE (
country_code = $1
OR $1 IS NULL
)
AND (
sport_id = $2
OR $2 IS NULL
)
AND (
name ILIKE '%' || $3 || '%'
OR $3 IS NULL
)
AND (
default_is_active = $4
OR $4 IS NULL
)
`
type GetTotalLeaguesParams struct {
CountryCode pgtype.Text `json:"country_code"`
SportID pgtype.Int4 `json:"sport_id"`
Query pgtype.Text `json:"query"`
IsActive pgtype.Bool `json:"is_active"`
}
func (q *Queries) GetTotalLeagues(ctx context.Context, arg GetTotalLeaguesParams) (int64, error) {
row := q.db.QueryRow(ctx, GetTotalLeagues,
arg.CountryCode,
arg.SportID,
arg.Query,
arg.IsActive,
)
var count int64
err := row.Scan(&count)
return count, err
}
const GetTotalLeaguesWithSettings = `-- name: GetTotalLeaguesWithSettings :one const GetTotalLeaguesWithSettings = `-- name: GetTotalLeaguesWithSettings :one
SELECT COUNT(*) SELECT COUNT(*)
FROM leagues l FROM leagues l

View File

@ -687,6 +687,7 @@ type ShopBetDetail struct {
TransactionVerified bool `json:"transaction_verified"` TransactionVerified bool `json:"transaction_verified"`
Status int32 `json:"status"` Status int32 `json:"status"`
TotalOdds float32 `json:"total_odds"` TotalOdds float32 `json:"total_odds"`
FastCode string `json:"fast_code"`
Outcomes []BetOutcome `json:"outcomes"` Outcomes []BetOutcome `json:"outcomes"`
} }

View File

@ -173,7 +173,7 @@ func (q *Queries) CreateShopTransaction(ctx context.Context, arg CreateShopTrans
} }
const GetAllShopBets = `-- name: GetAllShopBets :many const GetAllShopBets = `-- name: GetAllShopBets :many
SELECT id, shop_transaction_id, cashout_id, cashed_out_by, bet_id, number_of_outcomes, cashed_out, created_at, updated_at, customer_full_name, customer_phone_number, branch_id, company_id, amount, transaction_verified, status, total_odds, outcomes SELECT id, shop_transaction_id, cashout_id, cashed_out_by, bet_id, number_of_outcomes, cashed_out, created_at, updated_at, customer_full_name, customer_phone_number, branch_id, company_id, amount, transaction_verified, status, total_odds, fast_code, outcomes
FROM shop_bet_detail FROM shop_bet_detail
WHERE ( WHERE (
full_name ILIKE '%' || $1 || '%' full_name ILIKE '%' || $1 || '%'
@ -239,6 +239,7 @@ func (q *Queries) GetAllShopBets(ctx context.Context, arg GetAllShopBetsParams)
&i.TransactionVerified, &i.TransactionVerified,
&i.Status, &i.Status,
&i.TotalOdds, &i.TotalOdds,
&i.FastCode,
&i.Outcomes, &i.Outcomes,
); err != nil { ); err != nil {
return nil, err return nil, err
@ -419,7 +420,7 @@ func (q *Queries) GetAllShopTransactions(ctx context.Context, arg GetAllShopTran
} }
const GetShopBetByBetID = `-- name: GetShopBetByBetID :one const GetShopBetByBetID = `-- name: GetShopBetByBetID :one
SELECT id, shop_transaction_id, cashout_id, cashed_out_by, bet_id, number_of_outcomes, cashed_out, created_at, updated_at, customer_full_name, customer_phone_number, branch_id, company_id, amount, transaction_verified, status, total_odds, outcomes SELECT id, shop_transaction_id, cashout_id, cashed_out_by, bet_id, number_of_outcomes, cashed_out, created_at, updated_at, customer_full_name, customer_phone_number, branch_id, company_id, amount, transaction_verified, status, total_odds, fast_code, outcomes
FROM shop_bet_detail FROM shop_bet_detail
WHERE bet_id = $1 WHERE bet_id = $1
` `
@ -445,13 +446,14 @@ func (q *Queries) GetShopBetByBetID(ctx context.Context, betID int64) (ShopBetDe
&i.TransactionVerified, &i.TransactionVerified,
&i.Status, &i.Status,
&i.TotalOdds, &i.TotalOdds,
&i.FastCode,
&i.Outcomes, &i.Outcomes,
) )
return i, err return i, err
} }
const GetShopBetByCashoutID = `-- name: GetShopBetByCashoutID :one const GetShopBetByCashoutID = `-- name: GetShopBetByCashoutID :one
SELECT id, shop_transaction_id, cashout_id, cashed_out_by, bet_id, number_of_outcomes, cashed_out, created_at, updated_at, customer_full_name, customer_phone_number, branch_id, company_id, amount, transaction_verified, status, total_odds, outcomes SELECT id, shop_transaction_id, cashout_id, cashed_out_by, bet_id, number_of_outcomes, cashed_out, created_at, updated_at, customer_full_name, customer_phone_number, branch_id, company_id, amount, transaction_verified, status, total_odds, fast_code, outcomes
FROM shop_bet_detail FROM shop_bet_detail
WHERE cashout_id = $1 WHERE cashout_id = $1
` `
@ -477,13 +479,14 @@ func (q *Queries) GetShopBetByCashoutID(ctx context.Context, cashoutID string) (
&i.TransactionVerified, &i.TransactionVerified,
&i.Status, &i.Status,
&i.TotalOdds, &i.TotalOdds,
&i.FastCode,
&i.Outcomes, &i.Outcomes,
) )
return i, err return i, err
} }
const GetShopBetByID = `-- name: GetShopBetByID :one const GetShopBetByID = `-- name: GetShopBetByID :one
SELECT id, shop_transaction_id, cashout_id, cashed_out_by, bet_id, number_of_outcomes, cashed_out, created_at, updated_at, customer_full_name, customer_phone_number, branch_id, company_id, amount, transaction_verified, status, total_odds, outcomes SELECT id, shop_transaction_id, cashout_id, cashed_out_by, bet_id, number_of_outcomes, cashed_out, created_at, updated_at, customer_full_name, customer_phone_number, branch_id, company_id, amount, transaction_verified, status, total_odds, fast_code, outcomes
FROM shop_bet_detail FROM shop_bet_detail
WHERE id = $1 WHERE id = $1
` `
@ -509,13 +512,14 @@ func (q *Queries) GetShopBetByID(ctx context.Context, id int64) (ShopBetDetail,
&i.TransactionVerified, &i.TransactionVerified,
&i.Status, &i.Status,
&i.TotalOdds, &i.TotalOdds,
&i.FastCode,
&i.Outcomes, &i.Outcomes,
) )
return i, err return i, err
} }
const GetShopBetByShopTransactionID = `-- name: GetShopBetByShopTransactionID :one const GetShopBetByShopTransactionID = `-- name: GetShopBetByShopTransactionID :one
SELECT id, shop_transaction_id, cashout_id, cashed_out_by, bet_id, number_of_outcomes, cashed_out, created_at, updated_at, customer_full_name, customer_phone_number, branch_id, company_id, amount, transaction_verified, status, total_odds, outcomes SELECT id, shop_transaction_id, cashout_id, cashed_out_by, bet_id, number_of_outcomes, cashed_out, created_at, updated_at, customer_full_name, customer_phone_number, branch_id, company_id, amount, transaction_verified, status, total_odds, fast_code, outcomes
FROM shop_bet_detail FROM shop_bet_detail
WHERE shop_transaction_id = $1 WHERE shop_transaction_id = $1
` `
@ -541,6 +545,7 @@ func (q *Queries) GetShopBetByShopTransactionID(ctx context.Context, shopTransac
&i.TransactionVerified, &i.TransactionVerified,
&i.Status, &i.Status,
&i.TotalOdds, &i.TotalOdds,
&i.FastCode,
&i.Outcomes, &i.Outcomes,
) )
return i, err return i, err

View File

@ -45,6 +45,8 @@ type CreateCompany struct {
AdminID int64 AdminID int64
WalletID int64 WalletID int64
DeductedPercentage float32 DeductedPercentage float32
Slug string
IsActive bool
} }
type UpdateCompany struct { type UpdateCompany struct {
@ -53,18 +55,22 @@ type UpdateCompany struct {
AdminID ValidInt64 AdminID ValidInt64
IsActive ValidBool IsActive ValidBool
DeductedPercentage ValidFloat32 DeductedPercentage ValidFloat32
Slug ValidString
} }
type CreateCompanyReq struct { type CreateCompanyReq struct {
Name string `json:"name" example:"CompanyName"` Name string `json:"name" example:"CompanyName"`
AdminID int64 `json:"admin_id" example:"1"` AdminID int64 `json:"admin_id" example:"1"`
DeductedPercentage float32 `json:"deducted_percentage" example:"0.1" validate:"lt=1"` DeductedPercentage float32 `json:"deducted_percentage" example:"0.1" validate:"lt=1"`
Slug string `json:"slug"`
IsActive bool `json:"is_active"`
} }
type UpdateCompanyReq struct { type UpdateCompanyReq struct {
Name *string `json:"name,omitempty" example:"CompanyName"` Name *string `json:"name,omitempty" example:"CompanyName"`
AdminID *int64 `json:"admin_id,omitempty" example:"1"` AdminID *int64 `json:"admin_id,omitempty" example:"1"`
IsActive *bool `json:"is_active,omitempty" example:"true"` IsActive *bool `json:"is_active,omitempty" example:"true"`
DeductedPercentage *float32 `json:"deducted_percentage,omitempty" example:"0.1" validate:"lt=1"` DeductedPercentage *float32 `json:"deducted_percentage,omitempty" example:"0.1" validate:"lt=1"`
Slug *string `json:"slug"`
} }
type CompanyRes struct { type CompanyRes struct {
@ -113,13 +119,14 @@ func ConvertGetCompany(company GetCompany) GetCompanyRes {
} }
} }
func ConvertCreateCompany(company CreateCompany, uniqueSlug string) dbgen.CreateCompanyParams { func ConvertCreateCompany(company CreateCompany) dbgen.CreateCompanyParams {
return dbgen.CreateCompanyParams{ return dbgen.CreateCompanyParams{
Name: company.Name, Name: company.Name,
Slug: uniqueSlug, Slug: company.Slug,
AdminID: company.AdminID, AdminID: company.AdminID,
WalletID: company.WalletID, WalletID: company.WalletID,
DeductedPercentage: company.DeductedPercentage, DeductedPercentage: company.DeductedPercentage,
IsActive: company.IsActive,
} }
} }
@ -155,30 +162,21 @@ func ConvertDBCompanyDetails(dbCompany dbgen.CompaniesDetail) GetCompany {
func ConvertUpdateCompany(updateCompany UpdateCompany) dbgen.UpdateCompanyParams { func ConvertUpdateCompany(updateCompany UpdateCompany) dbgen.UpdateCompanyParams {
newUpdateCompany := dbgen.UpdateCompanyParams{ newUpdateCompany := dbgen.UpdateCompanyParams{
ID: updateCompany.ID, ID: updateCompany.ID,
Name: pgtype.Text{ Name: updateCompany.Name.ToPG(),
String: updateCompany.Name.Value, AdminID: updateCompany.AdminID.ToPG(),
Valid: updateCompany.Name.Valid, IsActive: updateCompany.IsActive.ToPG(),
}, DeductedPercentage: updateCompany.DeductedPercentage.ToPG(),
AdminID: pgtype.Int8{ Slug: updateCompany.Slug.ToPG(),
Int64: updateCompany.AdminID.Value,
Valid: updateCompany.AdminID.Valid,
},
IsActive: pgtype.Bool{
Bool: updateCompany.IsActive.Value,
Valid: updateCompany.IsActive.Valid,
},
DeductedPercentage: pgtype.Float4{
Float32: updateCompany.DeductedPercentage.Value,
Valid: updateCompany.DeductedPercentage.Valid,
},
} }
return newUpdateCompany return newUpdateCompany
} }
func ConvertUpdateCompanyReq(req UpdateCompanyReq) UpdateCompany { func ConvertUpdateCompanyReq(req UpdateCompanyReq, companyID int64) UpdateCompany {
var updateCompany UpdateCompany var updateCompany UpdateCompany
updateCompany.ID = companyID
if req.Name != nil { if req.Name != nil {
updateCompany.Name = ValidString{ updateCompany.Name = ValidString{
Value: *req.Name, Value: *req.Name,
@ -206,6 +204,12 @@ func ConvertUpdateCompanyReq(req UpdateCompanyReq) UpdateCompany {
Valid: true, Valid: true,
} }
} }
if req.Slug != nil {
updateCompany.Slug = ValidString{
Value: *req.Slug,
Valid: true,
}
}
return updateCompany return updateCompany
} }

View File

@ -34,6 +34,7 @@ type ShopBetDetail struct {
CompanyID int64 CompanyID int64
FullName string FullName string
PhoneNumber string PhoneNumber string
FastCode string
CashoutID string CashoutID string
CashedOut bool CashedOut bool
BetID int64 BetID int64
@ -80,6 +81,7 @@ type ShopBetRes struct {
CompanyID int64 `json:"company_id" example:"2"` CompanyID int64 `json:"company_id" example:"2"`
FullName string `json:"full_name" example:"John"` FullName string `json:"full_name" example:"John"`
PhoneNumber string `json:"phone_number" example:"1234567890"` PhoneNumber string `json:"phone_number" example:"1234567890"`
FastCode string `json:"fast_code" example:"12SD1"`
CashoutID string `json:"cashout_id" example:"21234"` CashoutID string `json:"cashout_id" example:"21234"`
CashedOut bool `json:"cashed_out" example:"false"` CashedOut bool `json:"cashed_out" example:"false"`
BetID int64 `json:"bet_id" example:"1"` BetID int64 `json:"bet_id" example:"1"`
@ -111,6 +113,7 @@ func ConvertShopBetDetail(shopBet ShopBetDetail) ShopBetRes {
CompanyID: shopBet.CompanyID, CompanyID: shopBet.CompanyID,
FullName: shopBet.FullName, FullName: shopBet.FullName,
PhoneNumber: shopBet.PhoneNumber, PhoneNumber: shopBet.PhoneNumber,
FastCode: shopBet.FastCode,
CashoutID: shopBet.CashoutID, CashoutID: shopBet.CashoutID,
CashedOut: shopBet.CashedOut, CashedOut: shopBet.CashedOut,
BetID: shopBet.BetID, BetID: shopBet.BetID,

View File

@ -1,6 +1,13 @@
package domain package domain
import "time" import (
"errors"
"time"
)
var (
ErrWalletIDDuplicate = errors.New("there already exists user id with wallet_type")
)
type Wallet struct { type Wallet struct {
ID int64 ID int64

View File

@ -103,7 +103,10 @@ func (s *Store) GetAllBets(ctx context.Context, filter domain.BetFilter) ([]doma
Query: filter.Query.ToPG(), Query: filter.Query.ToPG(),
CreatedBefore: filter.CreatedBefore.ToPG(), CreatedBefore: filter.CreatedBefore.ToPG(),
CreatedAfter: filter.CreatedAfter.ToPG(), CreatedAfter: filter.CreatedAfter.ToPG(),
Offset: filter.Offset.ToPG(), Offset: pgtype.Int4{
Int32: int32(filter.Offset.Value * filter.Limit.Value),
Valid: filter.Offset.Valid,
},
Limit: filter.Limit.ToPG(), Limit: filter.Limit.ToPG(),
}) })
if err != nil { if err != nil {

View File

@ -0,0 +1,12 @@
package repository
import (
"errors"
"github.com/jackc/pgx/v5/pgconn"
)
func IsUniqueViolation(err error) bool {
var pgErr *pgconn.PgError
return errors.As(err, &pgErr) && pgErr.Code == "23505"
}

View File

@ -2,36 +2,34 @@ package repository
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain" "github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
"github.com/SamuelTariku/FortuneBet-Backend/internal/pkgs/helpers"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype" "github.com/jackc/pgx/v5/pgtype"
) )
func (s *Store) CreateCompany(ctx context.Context, company domain.CreateCompany) (domain.Company, error) { func (s *Store) CreateCompany(ctx context.Context, company domain.CreateCompany) (domain.Company, error) {
baseSlug := helpers.GenerateSlug(company.Name) // baseSlug := helpers.GenerateSlug(company.Name)
uniqueSlug := baseSlug // uniqueSlug := baseSlug
i := 1 // i := 1
for { // for {
_, err := s.queries.GetCompanyUsingSlug(ctx, uniqueSlug) // _, err := s.queries.GetCompanyUsingSlug(ctx, uniqueSlug)
if err != nil { // if err != nil {
if errors.Is(err, pgx.ErrNoRows) { // if errors.Is(err, pgx.ErrNoRows) {
// slug is unique // // slug is unique
break // break
} else { // } else {
// real DB error // // real DB error
return domain.Company{}, err // return domain.Company{}, err
} // }
} // }
uniqueSlug = fmt.Sprintf("%s-%d", baseSlug, i) // uniqueSlug = fmt.Sprintf("%s-%d", baseSlug, i)
i++ // i++
} // }
fmt.Printf("\ncompany %v\n\n", company)
dbCompany, err := s.queries.CreateCompany(ctx, domain.ConvertCreateCompany(company))
dbCompany, err := s.queries.CreateCompany(ctx, domain.ConvertCreateCompany(company, uniqueSlug))
if err != nil { if err != nil {
return domain.Company{}, err return domain.Company{}, err
} }
@ -87,14 +85,15 @@ func (s *Store) GetCompanyBySlug(ctx context.Context, slug string) (domain.Compa
return domain.ConvertDBCompany(dbCompany), nil return domain.ConvertDBCompany(dbCompany), nil
} }
func (s *Store) UpdateCompany(ctx context.Context, company domain.UpdateCompany) (domain.Company, error) { func (s *Store) UpdateCompany(ctx context.Context, company domain.UpdateCompany) error {
dbCompany, err := s.queries.UpdateCompany(ctx, domain.ConvertUpdateCompany(company)) fmt.Printf("company %v\n", company)
err := s.queries.UpdateCompany(ctx, domain.ConvertUpdateCompany(company))
if err != nil { if err != nil {
return domain.Company{}, err return err
} }
return domain.ConvertDBCompany(dbCompany), nil return nil
} }
func (s *Store) DeleteCompany(ctx context.Context, id int64) error { func (s *Store) DeleteCompany(ctx context.Context, id int64) error {

View File

@ -26,7 +26,11 @@ func (s *Store) GetAllEvents(ctx context.Context, filter domain.EventFilter) ([]
SportID: filter.SportID.ToPG(), SportID: filter.SportID.ToPG(),
Query: filter.Query.ToPG(), Query: filter.Query.ToPG(),
Limit: filter.Limit.ToPG(), Limit: filter.Limit.ToPG(),
Offset: filter.Offset.ToPG(), Offset: pgtype.Int4{
Int32: int32(filter.Offset.Value * filter.Limit.Value),
Valid: filter.Offset.Valid,
},
FirstStartTime: filter.FirstStartTime.ToPG(), FirstStartTime: filter.FirstStartTime.ToPG(),
LastStartTime: filter.LastStartTime.ToPG(), LastStartTime: filter.LastStartTime.ToPG(),
CountryCode: filter.CountryCode.ToPG(), CountryCode: filter.CountryCode.ToPG(),

View File

@ -16,7 +16,7 @@ func (s *Store) SaveLeagueSettings(ctx context.Context, leagueSettings domain.Cr
return s.queries.SaveLeagueSettings(ctx, domain.ConvertCreateLeagueSettings(leagueSettings)) return s.queries.SaveLeagueSettings(ctx, domain.ConvertCreateLeagueSettings(leagueSettings))
} }
func (s *Store) GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) ([]domain.BaseLeague, error) { func (s *Store) GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) ([]domain.BaseLeague,int64, error) {
l, err := s.queries.GetAllLeagues(ctx, dbgen.GetAllLeaguesParams{ l, err := s.queries.GetAllLeagues(ctx, dbgen.GetAllLeaguesParams{
Query: filter.Query.ToPG(), Query: filter.Query.ToPG(),
CountryCode: filter.CountryCode.ToPG(), CountryCode: filter.CountryCode.ToPG(),
@ -31,10 +31,17 @@ func (s *Store) GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) (
}, },
}) })
if err != nil { if err != nil {
return nil, err return nil, 0, err
} }
return domain.ConvertDBBaseLeagues(l), nil total, err := s.queries.GetTotalLeagues(ctx, dbgen.GetTotalLeaguesParams{
Query: filter.Query.ToPG(),
CountryCode: filter.CountryCode.ToPG(),
SportID: filter.SportID.ToPG(),
IsActive: filter.IsActive.ToPG(),
})
return domain.ConvertDBBaseLeagues(l), total, nil
} }
func (s *Store) GetAllLeaguesByCompany(ctx context.Context, companyID int64, filter domain.LeagueFilter) ([]domain.LeagueWithSettings, int64, error) { func (s *Store) GetAllLeaguesByCompany(ctx context.Context, companyID int64, filter domain.LeagueFilter) ([]domain.LeagueWithSettings, int64, error) {

View File

@ -35,6 +35,7 @@ func convertDBShopBetDetail(bet dbgen.ShopBetDetail) domain.ShopBetDetail {
CompanyID: bet.CompanyID, CompanyID: bet.CompanyID,
FullName: bet.CustomerFullName, FullName: bet.CustomerFullName,
PhoneNumber: bet.CustomerPhoneNumber, PhoneNumber: bet.CustomerPhoneNumber,
FastCode: bet.FastCode,
CashoutID: bet.CashoutID, CashoutID: bet.CashoutID,
CashedOut: bet.CashedOut, CashedOut: bet.CashedOut,
BetID: bet.BetID, BetID: bet.BetID,

View File

@ -111,7 +111,7 @@ func (s *Store) GetAllUsers(ctx context.Context, filter domain.UserFilter) ([]do
Valid: filter.PageSize.Valid, Valid: filter.PageSize.Valid,
}, },
Offset: pgtype.Int4{ Offset: pgtype.Int4{
Int32: int32(filter.Page.Value), Int32: int32(filter.Page.Value * filter.PageSize.Value),
Valid: filter.Page.Valid, Valid: filter.Page.Valid,
}, },
Query: pgtype.Text{ Query: pgtype.Text{

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"database/sql" "database/sql"
"errors" "errors"
"fmt"
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db" dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain" "github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
@ -30,7 +29,7 @@ type VirtualGameRepository interface {
RemoveFavoriteGame(ctx context.Context, userID, gameID int64) error RemoveFavoriteGame(ctx context.Context, userID, gameID int64) error
ListFavoriteGames(ctx context.Context, userID int64) ([]int64, error) ListFavoriteGames(ctx context.Context, userID int64) ([]int64, error)
GetGameCounts(ctx context.Context, filter domain.ReportFilter) (total, active, inactive int64, err error) // GetGameCounts(ctx context.Context, filter domain.ReportFilter) (total, active, inactive int64, err error)
GetUserGameHistory(ctx context.Context, userID int64) ([]domain.VirtualGameHistory, error) GetUserGameHistory(ctx context.Context, userID int64) ([]domain.VirtualGameHistory, error)
CreateVirtualGameHistory(ctx context.Context, his *domain.VirtualGameHistory) error CreateVirtualGameHistory(ctx context.Context, his *domain.VirtualGameHistory) error
@ -255,36 +254,36 @@ func (r *VirtualGameRepo) UpdateVirtualGameTransactionStatus(ctx context.Context
}) })
} }
func (r *VirtualGameRepo) GetGameCounts(ctx context.Context, filter domain.ReportFilter) (total, active, inactive int64, err error) { // func (r *VirtualGameRepo) GetGameCounts(ctx context.Context, filter domain.ReportFilter) (total, active, inactive int64, err error) {
query := `SELECT // query := `SELECT
COUNT(*) as total, // COUNT(*) as total,
COUNT(CASE WHEN is_active = true THEN 1 END) as active, // COUNT(CASE WHEN is_active = true THEN 1 END) as active,
COUNT(CASE WHEN is_active = false THEN 1 END) as inactive // COUNT(CASE WHEN is_active = false THEN 1 END) as inactive
FROM virtual_games` // FROM virtual_games`
args := []interface{}{} // args := []interface{}{}
argPos := 1 // argPos := 1
// Add filters if provided // // Add filters if provided
if filter.StartTime.Valid { // if filter.StartTime.Valid {
query += fmt.Sprintf(" WHERE created_at >= $%d", argPos) // query += fmt.Sprintf(" WHERE created_at >= $%d", argPos)
args = append(args, filter.StartTime.Value) // args = append(args, filter.StartTime.Value)
argPos++ // argPos++
} // }
if filter.EndTime.Valid { // if filter.EndTime.Valid {
query += fmt.Sprintf(" AND created_at <= $%d", argPos) // query += fmt.Sprintf(" AND created_at <= $%d", argPos)
args = append(args, filter.EndTime.Value) // args = append(args, filter.EndTime.Value)
argPos++ // argPos++
} // }
row := r.store.conn.QueryRow(ctx, query, args...) // row := r.store.conn.QueryRow(ctx, query, args...)
err = row.Scan(&total, &active, &inactive) // err = row.Scan(&total, &active, &inactive)
if err != nil { // if err != nil {
return 0, 0, 0, fmt.Errorf("failed to get game counts: %w", err) // return 0, 0, 0, fmt.Errorf("failed to get game counts: %w", err)
} // }
return total, active, inactive, nil // return total, active, inactive, nil
} // }
func (r *VirtualGameRepo) GetUserGameHistory(ctx context.Context, userID int64) ([]domain.VirtualGameHistory, error) { func (r *VirtualGameRepo) GetUserGameHistory(ctx context.Context, userID int64) ([]domain.VirtualGameHistory, error) {
query := `SELECT game_id FROM virtual_game_histories WHERE user_id = $1 AND transaction_type = 'BET' ORDER BY created_at DESC LIMIT 100` query := `SELECT game_id FROM virtual_game_histories WHERE user_id = $1 AND transaction_type = 'BET' ORDER BY created_at DESC LIMIT 100`
@ -315,4 +314,3 @@ func (r *VirtualGameRepo) ListAllVirtualGames(ctx context.Context, arg dbgen.Get
func (r *VirtualGameRepo) RemoveAllVirtualGames(ctx context.Context) error { func (r *VirtualGameRepo) RemoveAllVirtualGames(ctx context.Context) error {
return r.store.queries.DeleteAllVirtualGames(ctx) return r.store.queries.DeleteAllVirtualGames(ctx)
} }

View File

@ -71,6 +71,9 @@ func convertDBGetCustomerWallet(customerWallet dbgen.CustomerWalletDetail) domai
func (s *Store) CreateWallet(ctx context.Context, wallet domain.CreateWallet) (domain.Wallet, error) { func (s *Store) CreateWallet(ctx context.Context, wallet domain.CreateWallet) (domain.Wallet, error) {
newWallet, err := s.queries.CreateWallet(ctx, convertCreateWallet(wallet)) newWallet, err := s.queries.CreateWallet(ctx, convertCreateWallet(wallet))
if err != nil { if err != nil {
if IsUniqueViolation(err) {
return domain.Wallet{}, domain.ErrWalletIDDuplicate
}
return domain.Wallet{}, err return domain.Wallet{}, err
} }
return convertDBWallet(newWallet), nil return convertDBWallet(newWallet), nil

View File

@ -12,7 +12,7 @@ type CompanyStore interface {
SearchCompanyByName(ctx context.Context, name string) ([]domain.GetCompany, error) SearchCompanyByName(ctx context.Context, name string) ([]domain.GetCompany, error)
GetCompanyByID(ctx context.Context, id int64) (domain.GetCompany, error) GetCompanyByID(ctx context.Context, id int64) (domain.GetCompany, error)
GetCompanyBySlug(ctx context.Context, slug string) (domain.Company, error) GetCompanyBySlug(ctx context.Context, slug string) (domain.Company, error)
UpdateCompany(ctx context.Context, company domain.UpdateCompany) (domain.Company, error) UpdateCompany(ctx context.Context, company domain.UpdateCompany) (error)
DeleteCompany(ctx context.Context, id int64) error DeleteCompany(ctx context.Context, id int64) error
GetCompanyCounts(ctx context.Context, filter domain.ReportFilter) (total, active, inactive int64, err error) GetCompanyCounts(ctx context.Context, filter domain.ReportFilter) (total, active, inactive int64, err error)

View File

@ -34,7 +34,7 @@ func (s *Service) SearchCompanyByName(ctx context.Context, name string) ([]domai
return s.companyStore.SearchCompanyByName(ctx, name) return s.companyStore.SearchCompanyByName(ctx, name)
} }
func (s *Service) UpdateCompany(ctx context.Context, company domain.UpdateCompany) (domain.Company, error) { func (s *Service) UpdateCompany(ctx context.Context, company domain.UpdateCompany) (error) {
return s.companyStore.UpdateCompany(ctx, company) return s.companyStore.UpdateCompany(ctx, company)
} }
func (s *Service) DeleteCompany(ctx context.Context, id int64) error { func (s *Service) DeleteCompany(ctx context.Context, id int64) error {

View File

@ -9,7 +9,7 @@ import (
type Service interface { type Service interface {
SaveLeague(ctx context.Context, league domain.CreateLeague) error SaveLeague(ctx context.Context, league domain.CreateLeague) error
SaveLeagueSettings(ctx context.Context, leagueSettings domain.CreateLeagueSettings) error SaveLeagueSettings(ctx context.Context, leagueSettings domain.CreateLeagueSettings) error
GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) ([]domain.BaseLeague, error) GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) ([]domain.BaseLeague, int64, error)
GetAllLeaguesByCompany(ctx context.Context, companyID int64, filter domain.LeagueFilter) ([]domain.LeagueWithSettings, int64, error) GetAllLeaguesByCompany(ctx context.Context, companyID int64, filter domain.LeagueFilter) ([]domain.LeagueWithSettings, int64, error)
CheckLeagueSupport(ctx context.Context, leagueID int64, companyID int64) (bool, error) CheckLeagueSupport(ctx context.Context, leagueID int64, companyID int64) (bool, error)
UpdateLeague(ctx context.Context, league domain.UpdateLeague) error UpdateLeague(ctx context.Context, league domain.UpdateLeague) error

View File

@ -25,7 +25,7 @@ func (s *service) SaveLeagueSettings(ctx context.Context, leagueSettings domain.
return s.store.SaveLeagueSettings(ctx, leagueSettings) return s.store.SaveLeagueSettings(ctx, leagueSettings)
} }
func (s *service) GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) ([]domain.BaseLeague, error) { func (s *service) GetAllLeagues(ctx context.Context, filter domain.LeagueFilter) ([]domain.BaseLeague, int64, error) {
return s.store.GetAllLeagues(ctx, filter) return s.store.GetAllLeagues(ctx, filter)
} }

View File

@ -135,11 +135,11 @@ func (s *Service) GetDashboardSummary(ctx context.Context, filter domain.ReportF
} }
// Get sport/game metrics // Get sport/game metrics
summary.TotalGames, summary.ActiveGames, summary.InactiveGames, err = s.virtulaGamesStore.GetGameCounts(ctx, filter) // summary.TotalGames, summary.ActiveGames, summary.InactiveGames, err = s.virtulaGamesStore.GetGameCounts(ctx, filter)
if err != nil { // if err != nil {
s.logger.Error("failed to get game counts", "error", err) // s.logger.Error("failed to get game counts", "error", err)
return domain.DashboardSummary{}, err // return domain.DashboardSummary{}, err
} // }
// Get company metrics // Get company metrics
summary.TotalCompanies, summary.ActiveCompanies, summary.InactiveCompanies, err = s.companyStore.GetCompanyCounts(ctx, filter) summary.TotalCompanies, summary.ActiveCompanies, summary.InactiveCompanies, err = s.companyStore.GetCompanyCounts(ctx, filter)

View File

@ -23,7 +23,7 @@ type VirtualGameService interface {
ProcessTournamentWin(ctx context.Context, req *domain.PopOKWinRequest) (*domain.PopOKWinResponse, error) ProcessTournamentWin(ctx context.Context, req *domain.PopOKWinRequest) (*domain.PopOKWinResponse, error)
ProcessPromoWin(ctx context.Context, req *domain.PopOKWinRequest) (*domain.PopOKWinResponse, error) ProcessPromoWin(ctx context.Context, req *domain.PopOKWinRequest) (*domain.PopOKWinResponse, error)
GetGameCounts(ctx context.Context, filter domain.ReportFilter) (total, active, inactive int64, err error) // GetGameCounts(ctx context.Context, filter domain.ReportFilter) (total, active, inactive int64, err error)
ListGames(ctx context.Context, currency string) ([]domain.PopOKGame, error) ListGames(ctx context.Context, currency string) ([]domain.PopOKGame, error)
RecommendGames(ctx context.Context, userID int64) ([]domain.GameRecommendation, error) RecommendGames(ctx context.Context, userID int64) ([]domain.GameRecommendation, error)
AddFavoriteGame(ctx context.Context, userID, gameID int64) error AddFavoriteGame(ctx context.Context, userID, gameID int64) error

View File

@ -657,9 +657,9 @@ func (s *service) verifySignature(callback *domain.PopOKCallback) bool {
return expected == callback.Signature return expected == callback.Signature
} }
func (s *service) GetGameCounts(ctx context.Context, filter domain.ReportFilter) (total, active, inactive int64, err error) { // func (s *service) GetGameCounts(ctx context.Context, filter domain.ReportFilter) (total, active, inactive int64, err error) {
return s.repo.GetGameCounts(ctx, filter) // return s.repo.GetGameCounts(ctx, filter)
} // }
func (s *service) ListGames(ctx context.Context, currency string) ([]domain.PopOKGame, error) { func (s *service) ListGames(ctx context.Context, currency string) ([]domain.PopOKGame, error) {
now := time.Now().Format("02-01-2006 15:04:05") // dd-mm-yyyy hh:mm:ss now := time.Now().Format("02-01-2006 15:04:05") // dd-mm-yyyy hh:mm:ss

View File

@ -95,7 +95,7 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S
} }
for _, job := range schedule { for _, job := range schedule {
// job.task() job.task()
if _, err := c.AddFunc(job.spec, job.task); err != nil { if _, err := c.AddFunc(job.spec, job.task); err != nil {
mongoLogger.Error("Failed to schedule data fetching cron job", mongoLogger.Error("Failed to schedule data fetching cron job",
zap.Error(err), zap.Error(err),

View File

@ -103,25 +103,25 @@ func (h *Handler) CreateAdmin(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create admin:"+err.Error()) return fiber.NewError(fiber.StatusInternalServerError, "Failed to create admin:"+err.Error())
} }
if req.CompanyID != nil { // if req.CompanyID != nil {
_, err := h.companySvc.UpdateCompany(c.Context(), domain.UpdateCompany{ // _, err := h.companySvc.UpdateCompany(c.Context(), domain.UpdateCompany{
ID: *req.CompanyID, // ID: *req.CompanyID,
AdminID: domain.ValidInt64{ // AdminID: domain.ValidInt64{
Value: newUser.ID, // Value: newUser.ID,
Valid: true, // Valid: true,
}, // },
}) // })
if err != nil { // if err != nil {
h.mongoLoggerSvc.Error("failed to update company with new admin", // h.mongoLoggerSvc.Error("failed to update company with new admin",
zap.Int64("status_code", fiber.StatusInternalServerError), // zap.Int64("status_code", fiber.StatusInternalServerError),
zap.Int64("company_id", *req.CompanyID), // zap.Int64("company_id", *req.CompanyID),
zap.Int64("admin_id", newUser.ID), // zap.Int64("admin_id", newUser.ID),
zap.Error(err), // zap.Error(err),
zap.Time("timestamp", time.Now()), // zap.Time("timestamp", time.Now()),
) // )
return fiber.NewError(fiber.StatusInternalServerError, "Failed to update company"+err.Error()) // return fiber.NewError(fiber.StatusInternalServerError, "Failed to update company"+err.Error())
} // }
} // }
h.mongoLoggerSvc.Info("admin created successfully", h.mongoLoggerSvc.Info("admin created successfully",
zap.Int64("admin_id", newUser.ID), zap.Int64("admin_id", newUser.ID),
@ -283,7 +283,7 @@ func (h *Handler) GetAllAdmins(c *fiber.Ctx) error {
zap.Time("timestamp", time.Now()), zap.Time("timestamp", time.Now()),
) )
return response.WritePaginatedJSON(c, fiber.StatusOK, "Admins retrieved successfully", result, nil, filter.Page.Value, int(total)) return response.WritePaginatedJSON(c, fiber.StatusOK, "Admins retrieved successfully", result, nil, filter.Page.Value+1, int(total))
} }
// GetAdminByID godoc // GetAdminByID godoc

View File

@ -1,6 +1,7 @@
package handlers package handlers
import ( import (
"errors"
"fmt" "fmt"
"strconv" "strconv"
"time" "time"
@ -82,17 +83,31 @@ func (h *Handler) CreateCompany(c *fiber.Ctx) error {
AdminID: user.ID, AdminID: user.ID,
WalletID: newWallet.ID, WalletID: newWallet.ID,
DeductedPercentage: req.DeductedPercentage, DeductedPercentage: req.DeductedPercentage,
Slug: req.Slug,
IsActive: req.IsActive,
}) })
if err != nil { if err != nil {
if errors.Is(err, domain.ErrWalletIDDuplicate) {
h.mongoLoggerSvc.Error("CreateCompanyReq failed to create company",
zap.Int64("userID", user.ID),
zap.String("name", req.Name),
zap.Int("status_code", fiber.StatusBadRequest),
zap.Error(err),
zap.Time("timestamp", time.Now()),
)
return fiber.NewError(fiber.StatusBadRequest, "this admin already has a company assigned to him")
}
h.mongoLoggerSvc.Error("CreateCompanyReq failed to create company", h.mongoLoggerSvc.Error("CreateCompanyReq failed to create company",
zap.Int64("userID", user.ID), zap.Int64("userID", user.ID),
zap.String("name", req.Name), zap.String("name", req.Name),
zap.String("Name", req.Name),
zap.Int("status_code", fiber.StatusInternalServerError), zap.Int("status_code", fiber.StatusInternalServerError),
zap.Error(err), zap.Error(err),
zap.Time("timestamp", time.Now()), zap.Time("timestamp", time.Now()),
) )
return fiber.NewError(fiber.StatusInternalServerError, err.Error()) return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} }
@ -361,11 +376,12 @@ func (h *Handler) UpdateCompany(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusBadRequest, errMsg) return fiber.NewError(fiber.StatusBadRequest, errMsg)
} }
company, err := h.companySvc.UpdateCompany(c.Context(), domain.ConvertUpdateCompanyReq(req)) err = h.companySvc.UpdateCompany(c.Context(), domain.ConvertUpdateCompanyReq(req, id))
if err != nil { if err != nil {
h.mongoLoggerSvc.Error("Failed to update company", h.mongoLoggerSvc.Error("Failed to update company",
zap.Int64("companyID", id), zap.Int64("companyID", id),
zap.Any("req", req),
zap.Int("status_code", fiber.StatusInternalServerError), zap.Int("status_code", fiber.StatusInternalServerError),
zap.Error(err), zap.Error(err),
zap.Time("timestamp", time.Now()), zap.Time("timestamp", time.Now()),
@ -373,9 +389,7 @@ func (h *Handler) UpdateCompany(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusInternalServerError, err.Error()) return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} }
res := domain.ConvertCompany(company) return response.WriteJSON(c, fiber.StatusOK, "Company Updated", nil, nil)
return response.WriteJSON(c, fiber.StatusOK, "Company Updated", res, nil)
} }

View File

@ -86,7 +86,7 @@ func (h *Handler) GetAllLeagues(c *fiber.Ctx) error {
zap.Bool("sport_id_valid", sportID.Valid), zap.Bool("sport_id_valid", sportID.Valid),
} }
leagues, err := h.leagueSvc.GetAllLeagues(c.Context(), domain.LeagueFilter{ leagues, total, err := h.leagueSvc.GetAllLeagues(c.Context(), domain.LeagueFilter{
CountryCode: countryCode, CountryCode: countryCode,
IsActive: isActive, IsActive: isActive,
SportID: sportID, SportID: sportID,
@ -104,7 +104,7 @@ func (h *Handler) GetAllLeagues(c *fiber.Ctx) error {
res := domain.ConvertBaseLeagueResList(leagues) res := domain.ConvertBaseLeagueResList(leagues)
return response.WriteJSON(c, fiber.StatusOK, "All leagues retrieved", res, nil) return response.WritePaginatedJSON(c, fiber.StatusOK, "All leagues retrieved successfully", res, nil, page, int(total))
} }
// GetAllLeaguesForTenant godoc // GetAllLeaguesForTenant godoc

View File

@ -328,9 +328,9 @@ func (h *Handler) RegisterUser(c *fiber.Ctx) error {
} }
// TODO: Remove later // TODO: Remove later
_, err = h.walletSvc.AddToWallet( // _, err = h.walletSvc.AddToWallet(
c.Context(), newWallet.RegularID, domain.ToCurrency(10000.0), domain.ValidInt64{}, domain.TRANSFER_DIRECT, domain.PaymentDetails{}, // c.Context(), newWallet.RegularID, domain.ToCurrency(10000.0), domain.ValidInt64{}, domain.TRANSFER_DIRECT, domain.PaymentDetails{},
"Added 10000.0 to wallet only as test for deployment") // "Added 10000.0 to wallet only as test for deployment")
if err != nil { if err != nil {
h.mongoLoggerSvc.Error("Failed to update wallet for user", h.mongoLoggerSvc.Error("Failed to update wallet for user",