mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
fix: next period,purchase before bop, integration auth module,fix validation-master data
This commit is contained in:
@@ -23,21 +23,19 @@ func NewPurchaseController(s service.PurchaseService) *PurchaseController {
|
||||
}
|
||||
|
||||
func (ctrl *PurchaseController) GetAll(c *fiber.Ctx) error {
|
||||
query := &validation.PurchaseQuery{
|
||||
query := &validation.Query{
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: strings.TrimSpace(c.Query("search")),
|
||||
PrNumber: strings.TrimSpace(c.Query("pr_number")),
|
||||
CreatedFrom: strings.TrimSpace(c.Query("created_from")),
|
||||
CreatedTo: strings.TrimSpace(c.Query("created_to")),
|
||||
SupplierID: uint(c.QueryInt("supplier_id", 0)),
|
||||
AreaID: uint(c.QueryInt("area_id", 0)),
|
||||
LocationID: uint(c.QueryInt("location_id", 0)),
|
||||
ProductCategoryID: uint(c.QueryInt("product_category_id", 0)),
|
||||
}
|
||||
|
||||
if supplierID := c.QueryInt("supplier_id", 0); supplierID > 0 {
|
||||
query.SupplierID = uint(supplierID)
|
||||
}
|
||||
|
||||
if status := strings.TrimSpace(c.Query("status")); status != "" {
|
||||
query.Status = strings.ToUpper(status)
|
||||
if query.Page < 1 || query.Limit < 1 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||
}
|
||||
|
||||
results, total, err := ctrl.service.GetAll(c, query)
|
||||
@@ -45,24 +43,15 @@ func (ctrl *PurchaseController) GetAll(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
limit := query.Limit
|
||||
if limit <= 0 {
|
||||
limit = 10
|
||||
}
|
||||
page := query.Page
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.SuccessWithPaginate[dto.PurchaseListItemDTO]{
|
||||
JSON(response.SuccessWithPaginate[dto.PurchaseListDTO]{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Purchase fetched successfully",
|
||||
Meta: response.Meta{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
TotalPages: int64(math.Ceil(float64(total) / float64(limit))),
|
||||
Page: query.Page,
|
||||
Limit: query.Limit,
|
||||
TotalPages: int64(math.Ceil(float64(total) / float64(query.Limit))),
|
||||
TotalResults: total,
|
||||
},
|
||||
Data: dto.ToPurchaseListDTOs(results),
|
||||
@@ -71,12 +60,13 @@ func (ctrl *PurchaseController) GetAll(c *fiber.Ctx) error {
|
||||
|
||||
func (ctrl *PurchaseController) GetOne(c *fiber.Ctx) error {
|
||||
param := c.Params("id")
|
||||
id, err := strconv.ParseUint(param, 10, 64)
|
||||
|
||||
id, err := strconv.Atoi(param)
|
||||
if err != nil || id == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid purchase id")
|
||||
}
|
||||
|
||||
result, err := ctrl.service.GetOne(c, id)
|
||||
result, err := ctrl.service.GetOne(c, uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -96,7 +86,7 @@ func (ctrl *PurchaseController) CreateOne(c *fiber.Ctx) error {
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
||||
}
|
||||
|
||||
|
||||
result, err := ctrl.service.CreateOne(c, req)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -113,7 +103,7 @@ func (ctrl *PurchaseController) CreateOne(c *fiber.Ctx) error {
|
||||
|
||||
func (ctrl *PurchaseController) ApproveStaffPurchase(c *fiber.Ctx) error {
|
||||
param := c.Params("id")
|
||||
id, err := strconv.ParseUint(param, 10, 64)
|
||||
id, err := strconv.Atoi(param)
|
||||
if err != nil || id == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid purchase id")
|
||||
}
|
||||
@@ -123,7 +113,7 @@ func (ctrl *PurchaseController) ApproveStaffPurchase(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Invalid request body: %v", err))
|
||||
}
|
||||
|
||||
result, err := ctrl.service.ApproveStaffPurchase(c, id, req)
|
||||
result, err := ctrl.service.ApproveStaffPurchase(c, uint(id), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -137,10 +127,9 @@ func (ctrl *PurchaseController) ApproveStaffPurchase(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func (ctrl *PurchaseController) ApproveManagerPurchase(c *fiber.Ctx) error {
|
||||
param := c.Params("id")
|
||||
id, err := strconv.ParseUint(param, 10, 64)
|
||||
id, err := strconv.Atoi(param)
|
||||
if err != nil || id == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid purchase id")
|
||||
}
|
||||
@@ -150,7 +139,7 @@ func (ctrl *PurchaseController) ApproveManagerPurchase(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
||||
}
|
||||
|
||||
result, err := ctrl.service.ApproveManagerPurchase(c, id, req)
|
||||
result, err := ctrl.service.ApproveManagerPurchase(c, uint(id), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -166,7 +155,7 @@ func (ctrl *PurchaseController) ApproveManagerPurchase(c *fiber.Ctx) error {
|
||||
|
||||
func (ctrl *PurchaseController) ReceiveProducts(c *fiber.Ctx) error {
|
||||
param := c.Params("id")
|
||||
id, err := strconv.ParseUint(param, 10, 64)
|
||||
id, err := strconv.Atoi(param)
|
||||
if err != nil || id == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid purchase id")
|
||||
}
|
||||
@@ -176,7 +165,7 @@ func (ctrl *PurchaseController) ReceiveProducts(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
||||
}
|
||||
|
||||
result, err := ctrl.service.ReceiveProducts(c, id, req)
|
||||
result, err := ctrl.service.ReceiveProducts(c, uint(id), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -192,7 +181,7 @@ func (ctrl *PurchaseController) ReceiveProducts(c *fiber.Ctx) error {
|
||||
|
||||
func (ctrl *PurchaseController) DeleteItems(c *fiber.Ctx) error {
|
||||
param := c.Params("id")
|
||||
id, err := strconv.ParseUint(param, 10, 64)
|
||||
id, err := strconv.Atoi(param)
|
||||
if err != nil || id == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid purchase id")
|
||||
}
|
||||
@@ -202,7 +191,7 @@ func (ctrl *PurchaseController) DeleteItems(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
||||
}
|
||||
|
||||
result, err := ctrl.service.DeleteItems(c, id, req)
|
||||
result, err := ctrl.service.DeleteItems(c, uint(id), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -218,12 +207,12 @@ func (ctrl *PurchaseController) DeleteItems(c *fiber.Ctx) error {
|
||||
|
||||
func (ctrl *PurchaseController) DeletePurchase(c *fiber.Ctx) error {
|
||||
param := c.Params("id")
|
||||
id, err := strconv.ParseUint(param, 10, 64)
|
||||
id, err := strconv.Atoi(param)
|
||||
if err != nil || id == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid purchase id")
|
||||
}
|
||||
|
||||
if err := ctrl.service.DeletePurchase(c, id); err != nil {
|
||||
if err := ctrl.service.DeletePurchase(c, uint(id)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user