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.
// TODO: well, permissions and all that.
func (h *OrdersHandler) ChangeOrderStatus(c fiber.Ctx) error {
user, ok := localeExtractor.GetCustomer(c)
if !ok {

View File

@@ -9,6 +9,7 @@ import (
type UICartsRepo interface {
CartsAmount(user_id uint) (uint, 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)
UpdateCartName(user_id uint, cart_id uint, new_name string) 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
}
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) {
var amt uint

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.
goc_daniel marked this conversation as resolved Outdated

after successful order placement we should either delete or deactivate the cart that is leftover

after successful order placement we should either delete or deactivate the cart that is leftover
// send email to admin
err = s.emailService.SendNewOrderPlacedNotification(user_id)
// if no error is returned, remove the cart. This should be smooth
goc_daniel marked this conversation as resolved Outdated

should be a goroutine to not stall the user from getting response from the server

should be a goroutine to not stall the user from getting response from the server
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
}