mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 14:03:45 +03:00
[hw-1] implement cart service
This commit is contained in:
37
cart/internal/app/server/delete_cart_handler.go
Normal file
37
cart/internal/app/server/delete_cart_handler.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"route256/cart/internal/domain/entity"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (s *Server) DeleteItemsByUserIDHandler(w http.ResponseWriter, r *http.Request) {
|
||||
strUserID := r.PathValue("user_id")
|
||||
userID, err := strconv.ParseInt(strUserID, 10, 64)
|
||||
if err != nil || userID <= 0 {
|
||||
if err == nil {
|
||||
err = fmt.Errorf("user_id must be greater than 0")
|
||||
}
|
||||
|
||||
makeErrorResponse(w, err, http.StatusBadRequest)
|
||||
|
||||
log.Trace().Err(err).Msgf("user_id=`%s`", strUserID)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.cartService.DeleteItemsByUserID(r.Context(), entity.UID(userID)); err != nil {
|
||||
makeErrorResponse(w, err, http.StatusBadRequest)
|
||||
|
||||
log.Trace().Err(err).Msgf("cartService.DeleteItemFromCart failed for uid=%d: %d", userID, http.StatusBadRequest)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
Reference in New Issue
Block a user