add new endpoints
This commit is contained in:
@@ -46,6 +46,10 @@ func (s *CartsService) UpdateCartName(user_id uint, cart_id uint, new_name strin
|
||||
return s.repo.UpdateCartName(user_id, cart_id, new_name)
|
||||
}
|
||||
|
||||
func (s *CartsService) RetrieveCartsInfo(user_id uint) ([]model.CustomerCart, error) {
|
||||
return s.repo.RetrieveCartsInfo(user_id)
|
||||
}
|
||||
|
||||
func (s *CartsService) RetrieveCart(user_id uint, cart_id uint) (*model.CustomerCart, error) {
|
||||
amt, err := s.repo.UserHasCart(user_id, cart_id)
|
||||
if err != nil {
|
||||
@@ -57,3 +61,23 @@ func (s *CartsService) RetrieveCart(user_id uint, cart_id uint) (*model.Customer
|
||||
|
||||
return s.repo.RetrieveCart(user_id, cart_id)
|
||||
}
|
||||
|
||||
func (s *CartsService) AddProduct(user_id uint, cart_id uint, product_id uint, product_attribute_id *uint, amount uint) error {
|
||||
amt, err := s.repo.UserHasCart(user_id, cart_id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if amt != 1 {
|
||||
return responseErrors.ErrUserHasNoSuchCart
|
||||
}
|
||||
|
||||
amt, err = s.repo.CheckProductExists(product_id, product_attribute_id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if amt != 1 {
|
||||
return responseErrors.ErrProductOrItsVariationDoesNotExist
|
||||
}
|
||||
|
||||
return s.repo.AddProduct(user_id, cart_id, product_id, product_attribute_id, amount)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user