mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
4107cf19ec
- Implement CreateOne for stock transfer with multi-delivery and validation - Preload warehouse, location, and area relations in transfer response - Add audit log for transfer - Improve transaction handling and error management
104 lines
2.6 KiB
Go
104 lines
2.6 KiB
Go
package controller
|
|
|
|
import (
|
|
"encoding/json"
|
|
"math"
|
|
"strconv"
|
|
|
|
"gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/transfers/dto"
|
|
service "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/transfers/services"
|
|
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/transfers/validations"
|
|
"gitlab.com/mbugroup/lti-api.git/internal/response"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type TransferController struct {
|
|
TransferService service.TransferService
|
|
}
|
|
|
|
func NewTransferController(transferService service.TransferService) *TransferController {
|
|
return &TransferController{
|
|
TransferService: transferService,
|
|
}
|
|
}
|
|
|
|
func (u *TransferController) GetAll(c *fiber.Ctx) error {
|
|
query := &validation.Query{
|
|
Page: c.QueryInt("page", 1),
|
|
Limit: c.QueryInt("limit", 10),
|
|
Search: c.Query("search", ""),
|
|
}
|
|
|
|
result, totalResults, err := u.TransferService.GetAll(c, query)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).
|
|
JSON(response.SuccessWithPaginate[dto.TransferListDTO]{
|
|
Code: fiber.StatusOK,
|
|
Status: "success",
|
|
Message: "Get all transfers successfully",
|
|
Meta: response.Meta{
|
|
Page: query.Page,
|
|
Limit: query.Limit,
|
|
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
|
|
TotalResults: totalResults,
|
|
},
|
|
Data: dto.ToTransferListDTOs(result),
|
|
})
|
|
}
|
|
|
|
func (u *TransferController) GetOne(c *fiber.Ctx) error {
|
|
param := c.Params("id")
|
|
|
|
id, err := strconv.Atoi(param)
|
|
if err != nil {
|
|
return fiber.NewError(fiber.StatusBadRequest, "Invalid Id")
|
|
}
|
|
|
|
result, err := u.TransferService.GetOne(c, uint(id))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).
|
|
JSON(response.Success{
|
|
Code: fiber.StatusOK,
|
|
Status: "success",
|
|
Message: "Get transfer successfully",
|
|
Data: dto.ToTransferListDTO(*result),
|
|
})
|
|
}
|
|
|
|
func (u *TransferController) CreateOne(c *fiber.Ctx) error {
|
|
data := c.FormValue("data")
|
|
|
|
var req validation.TransferRequest
|
|
if err := json.Unmarshal([]byte(data), &req); err != nil {
|
|
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
|
}
|
|
|
|
// ambil file
|
|
form, err := c.MultipartForm()
|
|
if err != nil {
|
|
return fiber.NewError(fiber.StatusBadRequest, "Invalid multipart form")
|
|
}
|
|
_ = form.File["documents"]
|
|
// todo: tunggu ada aws baru proses
|
|
|
|
result, err := u.TransferService.CreateOne(c, &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return c.Status(fiber.StatusCreated).
|
|
JSON(response.Success{
|
|
Code: fiber.StatusCreated,
|
|
Status: "success",
|
|
Message: "Create transfer successfully",
|
|
Data: dto.ToTransferListDTO(*result),
|
|
})
|
|
}
|