mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE-278): unrestrict feat warehouse purchase,adding purchase upload document
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -24,13 +25,13 @@ func NewPurchaseController(s service.PurchaseService) *PurchaseController {
|
||||
|
||||
func (ctrl *PurchaseController) GetAll(c *fiber.Ctx) error {
|
||||
query := &validation.Query{
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
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)),
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
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)),
|
||||
}
|
||||
|
||||
@@ -86,7 +87,6 @@ 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
|
||||
@@ -161,10 +161,26 @@ func (ctrl *PurchaseController) ReceiveProducts(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
req := new(validation.ReceivePurchaseRequest)
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
||||
form, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid multipart form")
|
||||
}
|
||||
req.Action = c.FormValue("action")
|
||||
if notes := strings.TrimSpace(c.FormValue("notes")); notes != "" {
|
||||
req.Notes = ¬es
|
||||
}
|
||||
|
||||
itemsJSON := c.FormValue("items")
|
||||
if strings.TrimSpace(itemsJSON) != "" {
|
||||
if err := json.Unmarshal([]byte(itemsJSON), &req.Items); err != nil {
|
||||
var singleItem validation.ReceivePurchaseItemRequest
|
||||
if err := json.Unmarshal([]byte(itemsJSON), &singleItem); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid items JSON")
|
||||
}
|
||||
req.Items = []validation.ReceivePurchaseItemRequest{singleItem}
|
||||
}
|
||||
}
|
||||
req.TravelDocuments = form.File["documents"]
|
||||
result, err := ctrl.service.ReceiveProducts(c, uint(id), req)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user