mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
add api get list stock log by product warehouse id
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/stock-logs/validations"
|
||||
stockLogDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/stock-logs/dto"
|
||||
stockLogService "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/stock-logs/services"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/response"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type StockLogController struct {
|
||||
StockLogService stockLogService.StockLogService
|
||||
}
|
||||
|
||||
func NewStockLogController(s stockLogService.StockLogService) *StockLogController {
|
||||
return &StockLogController{
|
||||
StockLogService: s,
|
||||
}
|
||||
}
|
||||
|
||||
func (u *StockLogController) GetAll(c *fiber.Ctx) error {
|
||||
query := &validation.Query{
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
ProductWarehouseID: uint(c.QueryInt("product_warehouse_id", 0)),
|
||||
}
|
||||
|
||||
if query.Page < 1 || query.Limit < 1 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||
}
|
||||
|
||||
// Export to Excel
|
||||
if strings.EqualFold(strings.TrimSpace(c.Query("export")), "excel") {
|
||||
if query.ProductWarehouseID == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "product_warehouse_id is required for export")
|
||||
}
|
||||
results, err := u.StockLogService.GetAllForExport(c, query.ProductWarehouseID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return exportStockLogListExcel(c, results)
|
||||
}
|
||||
|
||||
result, totalResults, err := u.StockLogService.GetAll(c, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.SuccessWithPaginate[stockLogDTO.StockLogListDTO]{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get all stock logs successfully",
|
||||
Meta: response.Meta{
|
||||
Page: query.Page,
|
||||
Limit: query.Limit,
|
||||
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
|
||||
TotalResults: totalResults,
|
||||
},
|
||||
Data: stockLogDTO.ToStockLogListDTOs(result),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user