go routine and removing cart

This commit is contained in:
Daniel Goc
2026-04-13 09:21:33 +02:00
parent d4d55e2757
commit 1f6d5ecb72
4 changed files with 35 additions and 3 deletions

View File

@@ -34,6 +34,18 @@ func (s *CartsService) CreateNewCart(user_id uint) (model.CustomerCart, error) {
return cart, nil
}
func (s *CartsService) RemoveCart(user_id uint, cart_id uint) error {
exists, err := s.repo.UserHasCart(user_id, cart_id)
if err != nil {
return err
}
if !exists {
return responseErrors.ErrUserHasNoSuchCart
}
return s.repo.RemoveCart(user_id, cart_id)
}
func (s *CartsService) UpdateCartName(user_id uint, cart_id uint, new_name string) error {
exists, err := s.repo.UserHasCart(user_id, cart_id)
if err != nil {

View File

@@ -87,14 +87,24 @@ func (s *OrderService) PlaceNewOrder(user_id uint, cart_id uint, name string, co
if err != nil {
return err
}
// from this point onward we do not cancel this order.
// send email to admin
err = s.emailService.SendNewOrderPlacedNotification(user_id)
// if no error is returned, remove the cart. This should be smooth
err = s.cartsRepo.RemoveCart(user_id, cart_id)
if err != nil {
// Log error but don't fail placing order???
// Log error but don't fail placing order
_ = err
}
// send email to admin
go func(user_id uint) {
err := s.emailService.SendNewOrderPlacedNotification(user_id)
if err != nil {
// Log error but don't fail placing order
_ = err
}
}(user_id)
return nil
}