expand orders
This commit is contained in:
@@ -99,6 +99,7 @@ func (s *AuthService) Login(req *model.LoginRequest) (*model.AuthResponse, strin
|
||||
user.LangID = *req.LangID
|
||||
}
|
||||
|
||||
user.Country = nil
|
||||
s.db.Save(&user)
|
||||
|
||||
// Generate access token (JWT)
|
||||
@@ -210,6 +211,7 @@ func (s *AuthService) CompleteRegistration(req *model.CompleteRegistrationReques
|
||||
user.EmailVerificationToken = ""
|
||||
user.EmailVerificationExpires = nil
|
||||
|
||||
user.Country = nil
|
||||
if err := s.db.Save(&user).Error; err != nil {
|
||||
return nil, "", fmt.Errorf("failed to update user: %w", err)
|
||||
}
|
||||
@@ -278,6 +280,7 @@ func (s *AuthService) RequestPasswordReset(emailAddr string) error {
|
||||
user.PasswordResetToken = token
|
||||
user.PasswordResetExpires = &expiresAt
|
||||
user.LastPasswordResetRequest = &now
|
||||
user.Country = nil
|
||||
if err := s.db.Save(&user).Error; err != nil {
|
||||
return fmt.Errorf("failed to save reset token: %w", err)
|
||||
}
|
||||
@@ -328,6 +331,7 @@ func (s *AuthService) ResetPassword(token, newPassword string) error {
|
||||
user.PasswordResetToken = ""
|
||||
user.PasswordResetExpires = nil
|
||||
|
||||
user.Country = nil
|
||||
if err := s.db.Save(&user).Error; err != nil {
|
||||
return fmt.Errorf("failed to update password: %w", err)
|
||||
}
|
||||
@@ -539,6 +543,7 @@ func (s *AuthService) UpdateJWTToken(user *model.Customer) (string, error) {
|
||||
}
|
||||
|
||||
// Save the updated user
|
||||
user.Country = nil
|
||||
if err := s.db.Save(user).Error; err != nil {
|
||||
return "", fmt.Errorf("database error: %w", err)
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ func (s *AuthService) HandleGoogleCallback(code string) (*model.AuthResponse, st
|
||||
// Update last login
|
||||
now := time.Now()
|
||||
user.LastLoginAt = &now
|
||||
user.Country = nil
|
||||
s.db.Save(user)
|
||||
|
||||
// Generate access token (JWT)
|
||||
|
||||
@@ -8,8 +8,10 @@ import (
|
||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/repos/cartsRepo"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/repos/ordersRepo"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/repos/productsRepo"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/service/addressesService"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/service/emailService"
|
||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/find"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||
@@ -18,6 +20,7 @@ import (
|
||||
type OrderService struct {
|
||||
ordersRepo ordersRepo.UIOrdersRepo
|
||||
cartsRepo cartsRepo.UICartsRepo
|
||||
productsRepo productsRepo.UIProductsRepo
|
||||
addressesService *addressesService.AddressesService
|
||||
emailService *emailService.EmailService
|
||||
}
|
||||
@@ -26,6 +29,7 @@ func New() *OrderService {
|
||||
return &OrderService{
|
||||
ordersRepo: ordersRepo.New(),
|
||||
cartsRepo: cartsRepo.New(),
|
||||
productsRepo: productsRepo.New(),
|
||||
addressesService: addressesService.New(),
|
||||
emailService: emailService.NewEmailService(),
|
||||
}
|
||||
@@ -82,8 +86,10 @@ func (s *OrderService) PlaceNewOrder(user_id uint, cart_id uint, name string, co
|
||||
name = *cart.Name
|
||||
}
|
||||
|
||||
base_price, tax_incl, tax_excl, err := s.getOrderTotalPrice(user_id, cart_id, country_id)
|
||||
|
||||
// all checks passed
|
||||
err = s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info)
|
||||
err = s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info, base_price, tax_incl, tax_excl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -143,3 +149,27 @@ func (s *OrderService) ChangeOrderStatus(user *model.Customer, order_id uint, st
|
||||
|
||||
return s.ordersRepo.ChangeOrderStatus(order_id, status)
|
||||
}
|
||||
|
||||
func (s *OrderService) getOrderTotalPrice(user_id uint, cart_id uint, country_id uint) (float64, float64, float64, error) {
|
||||
cart, err := s.cartsRepo.RetrieveCart(user_id, cart_id)
|
||||
if err != nil {
|
||||
return 0.0, 0.0, 0.0, err
|
||||
}
|
||||
|
||||
base_price := 0.0
|
||||
tax_incl := 0.0
|
||||
tax_excl := 0.0
|
||||
|
||||
for _, product := range cart.Products {
|
||||
prices, err := s.productsRepo.GetPrice(product.ProductID, product.ProductAttributeID, constdata.SHOP_ID, user_id, country_id, product.Amount)
|
||||
if err != nil {
|
||||
return 0.0, 0.0, 0.0, err
|
||||
}
|
||||
|
||||
base_price += prices.Base
|
||||
tax_incl += prices.FinalTaxIncl
|
||||
tax_excl += prices.FinalTaxExcl
|
||||
}
|
||||
|
||||
return base_price, tax_incl, tax_excl, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user