feat: branch location list

This commit is contained in:
Samuel Tariku 2025-07-13 13:46:38 +03:00
parent ae56d253c2
commit aa4bddef58
11 changed files with 136 additions and 6 deletions

View File

@ -4,8 +4,7 @@ VALUES ('max_number_of_outcomes', '30'),
('bet_amount_limit', '100000'), ('bet_amount_limit', '100000'),
('daily_ticket_limit', '50'), ('daily_ticket_limit', '50'),
('total_winnings_limit', '1000000'), ('total_winnings_limit', '1000000'),
('amount_for_bet_referral', '1000000') ('amount_for_bet_referral', '1000000'),
('cashback_amount_cap', '1000') ('cashback_amount_cap', '1000') ON CONFLICT (key) DO
ON CONFLICT (key) DO
UPDATE UPDATE
SET value = EXCLUDED.value; SET value = EXCLUDED.value;

7
db/query/location.sql Normal file
View File

@ -0,0 +1,7 @@
-- name: GetAllBranchLocations :many
SELECT *
FROM branch_locations
WHERE (
value ILIKE '%' || sqlc.narg('query') || '%'
OR sqlc.narg('query') IS NULL
);

41
gen/db/location.sql.go Normal file
View File

@ -0,0 +1,41 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: location.sql
package dbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const GetAllBranchLocations = `-- name: GetAllBranchLocations :many
SELECT key, value
FROM branch_locations
WHERE (
value ILIKE '%' || $1 || '%'
OR $1 IS NULL
)
`
func (q *Queries) GetAllBranchLocations(ctx context.Context, query pgtype.Text) ([]BranchLocation, error) {
rows, err := q.db.Query(ctx, GetAllBranchLocations, query)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BranchLocation
for rows.Next() {
var i BranchLocation
if err := rows.Scan(&i.Key, &i.Value); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

View File

@ -11,6 +11,11 @@ type Branch struct {
IsSelfOwned bool IsSelfOwned bool
} }
type BranchLocation struct {
Key string `json:"key" example:"addis_ababa" `
Name string `json:"name" example:"Addis Ababa"`
}
type BranchFilter struct { type BranchFilter struct {
CompanyID ValidInt64 CompanyID ValidInt64
IsActive ValidBool IsActive ValidBool

View File

@ -0,0 +1,30 @@
package repository
import (
"context"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
"github.com/jackc/pgx/v5/pgtype"
)
func (s *Store) GetAllBranchLocations (ctx context.Context, query domain.ValidString) ([]domain.BranchLocation, error) {
locations, err := s.queries.GetAllBranchLocations(ctx, pgtype.Text{
String: query.Value,
Valid: query.Valid,
})
if err != nil {
return nil, err
}
var result []domain.BranchLocation = make([]domain.BranchLocation, 0, len(locations))
for _, location := range locations {
result = append(result, domain.BranchLocation{
Key: location.Key,
Name: location.Value,
})
}
return result, nil
}

View File

@ -1033,7 +1033,7 @@ func (s *Service) ProcessBetCashback(ctx context.Context) error {
) )
continue continue
} }
cashbackAmount := math.Min(float64(settingsList.CashbackAmountCap), float64(calculateCashbackAmount(bet.Amount.Float32(), bet.TotalOdds))) cashbackAmount := math.Min(float64(settingsList.CashbackAmountCap.Float32()), float64(calculateCashbackAmount(bet.Amount.Float32(), bet.TotalOdds)))
_, err = s.walletSvc.AddToWallet(ctx, wallets.StaticID, domain.ToCurrency(float32(cashbackAmount)), domain.ValidInt64{}, domain.TRANSFER_DIRECT, _, err = s.walletSvc.AddToWallet(ctx, wallets.StaticID, domain.ToCurrency(float32(cashbackAmount)), domain.ValidInt64{}, domain.TRANSFER_DIRECT,
domain.PaymentDetails{}, fmt.Sprintf("cashback amount of %f added to users static wallet", cashbackAmount)) domain.PaymentDetails{}, fmt.Sprintf("cashback amount of %f added to users static wallet", cashbackAmount))

View File

@ -0,0 +1,11 @@
package branch
import (
"context"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
)
func (s *Service) GetAllBranchLocations(ctx context.Context, query domain.ValidString) ([]domain.BranchLocation, error) {
return s.branchStore.GetAllBranchLocations(ctx, query)
}

View File

@ -29,4 +29,6 @@ type BranchStore interface {
GetAllCompaniesBranch(ctx context.Context) ([]domain.Company, error) GetAllCompaniesBranch(ctx context.Context) ([]domain.Company, error)
GetBranchesByCompany(ctx context.Context, companyID int64) ([]domain.Branch, error) GetBranchesByCompany(ctx context.Context, companyID int64) ([]domain.Branch, error)
GetAllBranchLocations(ctx context.Context, query domain.ValidString) ([]domain.BranchLocation, error)
} }

View File

@ -78,3 +78,4 @@ func (s *Service) GetAllCompaniesBranch(ctx context.Context) ([]domain.Company,
func (s *Service) GetBranchesByCompany(ctx context.Context, companyID int64) ([]domain.Branch, error) { func (s *Service) GetBranchesByCompany(ctx context.Context, companyID int64) ([]domain.Branch, error) {
return s.branchStore.GetBranchesByCompany(ctx, companyID) return s.branchStore.GetBranchesByCompany(ctx, companyID)
} }

View File

@ -619,6 +619,39 @@ func (h *Handler) GetBranchOperations(c *fiber.Ctx) error {
return response.WriteJSON(c, fiber.StatusOK, "Branch Operations retrieved successfully", result, nil) return response.WriteJSON(c, fiber.StatusOK, "Branch Operations retrieved successfully", result, nil)
} }
// GetAllBranchLocations godoc
// @Summary Gets all branch locations
// @Description Gets all branch locations
// @Tags branch
// @Accept json
// @Produce json
// @Success 200 {array} domain.BranchLocation
// @Failure 400 {object} response.APIResponse
// @Failure 500 {object} response.APIResponse
// @Router /api/v1/branchLocation [get]
func (h *Handler) GetAllBranchLocations(c *fiber.Ctx) error {
searchQuery := c.Query("query")
searchString := domain.ValidString{
Value: searchQuery,
Valid: searchQuery != "",
}
locations, err := h.branchSvc.GetAllBranchLocations(c.Context(), searchString)
if err != nil {
h.mongoLoggerSvc.Error("Failed to get branch locations",
zap.Int("status_code", fiber.StatusInternalServerError),
zap.Error(err),
zap.Time("timestamp", time.Now()),
)
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return response.WriteJSON(c, fiber.StatusOK, "Branch Location successfully fetched", locations, nil)
}
// GetBranchCashiers godoc // GetBranchCashiers godoc
// @Summary Gets branch cashiers // @Summary Gets branch cashiers
// @Description Gets branch cashiers // @Description Gets branch cashiers

View File

@ -171,9 +171,10 @@ func (a *App) initAppRoutes() {
groupV1.Put("/branch/:id/set-active", a.authMiddleware, h.UpdateBranchStatus) groupV1.Put("/branch/:id/set-active", a.authMiddleware, h.UpdateBranchStatus)
groupV1.Put("/branch/:id/set-inactive", a.authMiddleware, h.UpdateBranchStatus) groupV1.Put("/branch/:id/set-inactive", a.authMiddleware, h.UpdateBranchStatus)
groupV1.Delete("/branch/:id", a.authMiddleware, h.DeleteBranch) groupV1.Delete("/branch/:id", a.authMiddleware, h.DeleteBranch)
groupV1.Get("/search/branch", a.authMiddleware, h.SearchBranch) groupV1.Get("/search/branch", a.authMiddleware, h.SearchBranch)
// /branch/search groupV1.Get("/branchLocation", a.authMiddleware, h.GetAllBranchLocations)
// branch/wallet
groupV1.Get("/branch/:id/cashiers", a.authMiddleware, h.GetBranchCashiers) groupV1.Get("/branch/:id/cashiers", a.authMiddleware, h.GetBranchCashiers)
groupV1.Get("/branchCashier", a.authMiddleware, h.GetBranchForCashier) groupV1.Get("/branchCashier", a.authMiddleware, h.GetBranchForCashier)