basic orders are ready

This commit is contained in:
Daniel Goc
2026-04-10 14:53:40 +02:00
parent a03a2b461f
commit 33e9d016e9
15 changed files with 237 additions and 94 deletions

View File

@@ -29,7 +29,7 @@ func OrdersHandlerRoutes(r fiber.Router) fiber.Router {
handler := NewOrdersHandler()
r.Get("/list", handler.ListOrders)
r.Get("/place-new-order", handler.PlaceNewOrder)
r.Post("/place-new-order", handler.PlaceNewOrder)
r.Get("/change-order-address", handler.ChangeOrderAddress)
r.Get("/change-order-status", handler.ChangeOrderStatus)
@@ -82,7 +82,6 @@ func (h *OrdersHandler) PlaceNewOrder(c fiber.Ctx) error {
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
address_info := c.Query("address_info")
country_id_attribute := c.Query("country_id")
country_id, err := strconv.Atoi(country_id_attribute)
if err != nil {
@@ -90,6 +89,12 @@ func (h *OrdersHandler) PlaceNewOrder(c fiber.Ctx) error {
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
address_info := string(c.Body())
if address_info == "" {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
}
name := c.Query("name")
err = h.ordersService.PlaceNewOrder(userID, uint(cart_id), name, uint(country_id), address_info)
@@ -116,7 +121,6 @@ func (h *OrdersHandler) ChangeOrderAddress(c fiber.Ctx) error {
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
address_info := c.Query("address_info")
country_id_attribute := c.Query("country_id")
country_id, err := strconv.Atoi(country_id_attribute)
if err != nil {
@@ -124,6 +128,12 @@ func (h *OrdersHandler) ChangeOrderAddress(c fiber.Ctx) error {
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
address_info := string(c.Body())
if address_info == "" {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
}
err = h.ordersService.ChangeOrderAddress(user, uint(order_id), uint(country_id), address_info)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).