orders #58

Merged
goc_daniel merged 13 commits from orders into main 2026-04-14 11:20:06 +00:00
4 changed files with 35 additions and 3 deletions
Showing only changes of commit 1f6d5ecb72 - Show all commits

View File

@@ -144,6 +144,7 @@ func (h *OrdersHandler) ChangeOrderAddress(c fiber.Ctx) error {
} }
// we base permissions and user based on target user only. // we base permissions and user based on target user only.
// TODO: well, permissions and all that.
func (h *OrdersHandler) ChangeOrderStatus(c fiber.Ctx) error { func (h *OrdersHandler) ChangeOrderStatus(c fiber.Ctx) error {
user, ok := localeExtractor.GetCustomer(c) user, ok := localeExtractor.GetCustomer(c)
if !ok { if !ok {

View File

@@ -9,6 +9,7 @@ import (
type UICartsRepo interface { type UICartsRepo interface {
CartsAmount(user_id uint) (uint, error) CartsAmount(user_id uint) (uint, error)
CreateNewCart(user_id uint) (model.CustomerCart, error) CreateNewCart(user_id uint) (model.CustomerCart, error)
RemoveCart(user_id uint, cart_id uint) error
UserHasCart(user_id uint, cart_id uint) (bool, error) UserHasCart(user_id uint, cart_id uint) (bool, error)
UpdateCartName(user_id uint, cart_id uint, new_name string) error UpdateCartName(user_id uint, cart_id uint, new_name string) error
RetrieveCartsInfo(user_id uint) ([]model.CustomerCart, error) RetrieveCartsInfo(user_id uint) ([]model.CustomerCart, error)
@@ -49,6 +50,14 @@ func (repo *CartsRepo) CreateNewCart(user_id uint) (model.CustomerCart, error) {
return cart, err return cart, err
} }
func (repo *CartsRepo) RemoveCart(user_id uint, cart_id uint) error {
return db.DB.
Table("b2b_customer_carts").
Where("cart_id = ? AND user_id = ?", cart_id, user_id).
Delete(nil).
Error
}
func (repo *CartsRepo) UserHasCart(user_id uint, cart_id uint) (bool, error) { func (repo *CartsRepo) UserHasCart(user_id uint, cart_id uint) (bool, error) {
var amt uint var amt uint

View File

@@ -34,6 +34,18 @@ func (s *CartsService) CreateNewCart(user_id uint) (model.CustomerCart, error) {
return cart, nil 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 { func (s *CartsService) UpdateCartName(user_id uint, cart_id uint, new_name string) error {
exists, err := s.repo.UserHasCart(user_id, cart_id) exists, err := s.repo.UserHasCart(user_id, cart_id)
if err != nil { 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 { if err != nil {
return err return err
} }
// from this point onward we do not cancel this order.
// send email to admin // if no error is returned, remove the cart. This should be smooth
err = s.emailService.SendNewOrderPlacedNotification(user_id) err = s.cartsRepo.RemoveCart(user_id, cart_id)
if err != nil { if err != nil {
// Log error but don't fail placing order??? // Log error but don't fail placing order
_ = err _ = 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 return nil
} }