fix: small fixes on setting
This commit is contained in:
parent
9ec7d0cfc1
commit
c4cd85fe00
|
|
@ -2,6 +2,7 @@ package repository
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
||||
|
|
@ -22,10 +23,11 @@ func GetDBSettingList(settings []dbgen.Setting) (domain.SettingList, error) {
|
|||
"max_number_of_outcomes": &dbSettingList.MaxNumberOfOutcomes,
|
||||
"bet_amount_limit": &dbSettingList.BetAmountLimit,
|
||||
"daily_ticket_limit": &dbSettingList.DailyTicketPerIP,
|
||||
"total_winnings_limit": &dbSettingList.DailyTicketPerIP,
|
||||
"total_winnings_limit": &dbSettingList.TotalWinningLimit,
|
||||
}
|
||||
|
||||
for _, setting := range settings {
|
||||
is_setting_unknown := true
|
||||
for key, dbSetting := range int64SettingsMap {
|
||||
if setting.Key == key {
|
||||
value, err := strconv.ParseInt(setting.Value, 10, 64)
|
||||
|
|
@ -36,14 +38,18 @@ func GetDBSettingList(settings []dbgen.Setting) (domain.SettingList, error) {
|
|||
Value: value,
|
||||
Valid: true,
|
||||
}
|
||||
} else {
|
||||
domain.MongoDBLogger.Error("unknown setting found on database", zap.String("setting", setting.Key))
|
||||
is_setting_unknown = false
|
||||
}
|
||||
}
|
||||
|
||||
if is_setting_unknown {
|
||||
domain.MongoDBLogger.Warn("unknown setting found on database", zap.String("setting", setting.Key))
|
||||
}
|
||||
}
|
||||
|
||||
for key, dbSetting := range int64SettingsMap {
|
||||
if !dbSetting.Valid {
|
||||
fmt.Printf("setting value not found on database: %v \n", key)
|
||||
domain.MongoDBLogger.Warn("setting value not found on database", zap.String("setting", key))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,34 +157,32 @@ func (s *Service) GenerateTicketOutcome(ctx context.Context, settings domain.Set
|
|||
func (s *Service) CreateTicket(ctx context.Context, req domain.CreateTicketReq, clientIP string) (domain.Ticket, int64, error) {
|
||||
settingsList, err := s.settingSvc.GetSettingList(ctx)
|
||||
|
||||
// s.mongoLogger.Info("Creating ticket")
|
||||
// TODO Validate Outcomes Here and make sure they didn't expire
|
||||
// Validation for creating tickets
|
||||
// Check to see if the number of outcomes is above a set limit
|
||||
if len(req.Outcomes) > int(settingsList.MaxNumberOfOutcomes) {
|
||||
// return response.WriteJSON(c, fiber.StatusBadRequest, "Too many odds/outcomes selected", nil, nil)
|
||||
return domain.Ticket{}, 0, ErrTooManyOutcomesForTicket
|
||||
|
||||
}
|
||||
|
||||
// Check to see if the amount is above a set limit
|
||||
if req.Amount > settingsList.BetAmountLimit.Float32() {
|
||||
// return response.WriteJSON(c, fiber.StatusBadRequest, "Cannot create a ticket with an amount above 100,000 birr", nil, nil)
|
||||
return domain.Ticket{}, 0, ErrTicketAmountTooHigh
|
||||
}
|
||||
|
||||
count, err := s.CountTicketByIP(ctx, clientIP)
|
||||
|
||||
if err != nil {
|
||||
// return response.WriteJSON(c, fiber.StatusInternalServerError, "Error fetching user info", nil, nil)
|
||||
s.mongoLogger.Error("failed to count number of ticket using ip",
|
||||
zap.Error(err),
|
||||
)
|
||||
return domain.Ticket{}, 0, err
|
||||
}
|
||||
|
||||
// Check to see how many tickets a single anonymous user has created
|
||||
if count > settingsList.DailyTicketPerIP {
|
||||
// return response.WriteJSON(c, fiber.StatusBadRequest, "Ticket Limit reached", nil, nil)
|
||||
|
||||
return domain.Ticket{}, 0, ErrTicketLimitForSingleUser
|
||||
}
|
||||
|
||||
var outcomes []domain.CreateTicketOutcome = make([]domain.CreateTicketOutcome, 0, len(req.Outcomes))
|
||||
var totalOdds float32 = 1
|
||||
for _, outcomeReq := range req.Outcomes {
|
||||
|
|
@ -202,9 +200,13 @@ func (s *Service) CreateTicket(ctx context.Context, req domain.CreateTicketReq,
|
|||
outcomes = append(outcomes, newOutcome)
|
||||
}
|
||||
totalWinnings := req.Amount * totalOdds
|
||||
|
||||
// Check to see if the total winning amount is over a set limit
|
||||
if totalWinnings > settingsList.TotalWinningLimit.Float32() {
|
||||
s.mongoLogger.Error("Total Winnings over limit", zap.Float32("Total Odds", totalOdds), zap.Float32("amount", req.Amount))
|
||||
// return response.WriteJSON(c, fiber.StatusBadRequest, "Cannot create a ticket with 1,000,000 winnings", nil, nil)
|
||||
s.mongoLogger.Error("Total Winnings over limit",
|
||||
zap.Float32("Total Odds", totalOdds),
|
||||
zap.Float32("amount", req.Amount),
|
||||
zap.Float32("limit", settingsList.TotalWinningLimit.Float32()))
|
||||
return domain.Ticket{}, 0, ErrTicketWinningTooHigh
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S
|
|||
}
|
||||
|
||||
for _, job := range schedule {
|
||||
job.task()
|
||||
// job.task()
|
||||
if _, err := c.AddFunc(job.spec, job.task); err != nil {
|
||||
log.Fatalf("Failed to schedule cron job: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user