package transaction import ( "context" "errors" "github.com/SamuelTariku/FortuneBet-Backend/internal/domain" ) var ( ErrUserHasNoCustomerWallet = errors.New("user has no customer wallet") ) func (s *Service) CreateShopDeposit(ctx context.Context, userID int64, role domain.Role, req domain.ShopDepositReq) (domain.ShopDeposit, error) { var branchID int64 var companyID int64 var senderID int64 switch role { case domain.RoleAdmin, domain.RoleBranchManager, domain.RoleSuperAdmin: if req.BranchID == nil { // h.logger.Error("CashoutReq Branch ID is required for this user role") return domain.ShopDeposit{}, ErrBranchRequiredForRole } branch, err := s.branchSvc.GetBranchByID(ctx, *req.BranchID) if err != nil { // h.logger.Error("CashoutReq no branches") return domain.ShopDeposit{}, ErrInvalidBetID } branchID = branch.ID companyID = branch.CompanyID senderID = branch.WalletID case domain.RoleCashier: branch, err := s.branchSvc.GetBranchByCashier(ctx, userID) if err != nil { // h.logger.Error("CashoutReq failed, branch id invalid") return domain.ShopDeposit{}, ErrInvalidBranchID } branchID = branch.ID companyID = branch.CompanyID senderID = branch.WalletID default: return domain.ShopDeposit{}, ErrCustomerRoleNotAuthorized } user, err := s.userSvc.GetUserByID(ctx, req.CustomerID) if err != nil { return domain.ShopDeposit{}, err } // if err != nil { // return domain.ShopDeposit{}, err // } newTransaction, err := s.CreateShopTransaction(ctx, domain.CreateShopTransaction{ Amount: domain.Currency(req.Amount), BranchID: branchID, CompanyID: companyID, UserID: userID, Type: domain.TRANSACTION_DEPOSIT, FullName: user.FirstName + " " + user.LastName, PhoneNumber: user.PhoneNumber, PaymentOption: req.PaymentOption, BankCode: domain.ValidString{ Value: req.BankCode, Valid: req.BankCode != "", }, BeneficiaryName: domain.ValidString{ Value: req.BeneficiaryName, Valid: req.BeneficiaryName != "", }, AccountName: domain.ValidString{ Value: req.AccountName, Valid: req.AccountName != "", }, AccountNumber: domain.ValidString{ Value: req.AccountNumber, Valid: req.AccountNumber != "", }, ReferenceNumber: domain.ValidString{ Value: req.ReferenceNumber, Valid: req.ReferenceNumber != "", }, Verified: false, ApprovedBy: domain.ValidInt64{ Value: userID, Valid: true, }, }) if err != nil { return domain.ShopDeposit{}, err } return s.transactionStore.CreateShopDeposit(ctx, domain.CreateShopDeposit{ ShopTransactionID: newTransaction.ID, CustomerID: req.CustomerID, BranchWalletID: senderID, }) } // func (s *Service) CreateShopDeposit(ctx context.Context, deposit domain.CreateShopDeposit) (domain.ShopDeposit, error) { // return s.transactionStore.CreateShopDeposit(ctx, deposit) // } func (s *Service) GetAllShopDeposit(ctx context.Context, filter domain.ShopDepositFilter) ([]domain.ShopDepositDetail, error) { return s.transactionStore.GetAllShopDeposit(ctx, filter) } func (s *Service) GetShopDepositByID(ctx context.Context, id int64) (domain.ShopDepositDetail, error) { return s.transactionStore.GetShopDepositByID(ctx, id) } func (s *Service) GetShopDepositByShopTransactionID(ctx context.Context, shopTransactionID int64) (domain.ShopDepositDetail, error) { return s.transactionStore.GetShopDepositByShopTransactionID(ctx, shopTransactionID) } func (s *Service) UpdateShopDepositTransferID(ctx context.Context, id int64, transferID domain.ValidInt64) error { return s.transactionStore.UpdateShopDepositTransferID(ctx, id, transferID) }