mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix(BE): add missing product json in transfer get all & support flag param filter in product warehouses
This commit is contained in:
+1
-2
@@ -28,6 +28,7 @@ func (u *ProductWarehouseController) GetAll(c *fiber.Ctx) error {
|
|||||||
Limit: c.QueryInt("limit", 10),
|
Limit: c.QueryInt("limit", 10),
|
||||||
ProductId: uint(c.QueryInt("product_id", 0)),
|
ProductId: uint(c.QueryInt("product_id", 0)),
|
||||||
WarehouseId: uint(c.QueryInt("warehouse_id", 0)),
|
WarehouseId: uint(c.QueryInt("warehouse_id", 0)),
|
||||||
|
Flag: c.Query("flag"),
|
||||||
}
|
}
|
||||||
|
|
||||||
result, totalResults, err := u.ProductWarehouseService.GetAll(c, query)
|
result, totalResults, err := u.ProductWarehouseService.GetAll(c, query)
|
||||||
@@ -71,5 +72,3 @@ func (u *ProductWarehouseController) GetOne(c *fiber.Ctx) error {
|
|||||||
Data: dto.ToProductWarehouseListDTO(*result),
|
Data: dto.ToProductWarehouseListDTO(*result),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -34,7 +34,11 @@ func NewProductWarehouseService(repo repository.ProductWarehouseRepository, vali
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s productWarehouseService) withRelations(db *gorm.DB) *gorm.DB {
|
func (s productWarehouseService) withRelations(db *gorm.DB) *gorm.DB {
|
||||||
return db.Preload("Product.Flags").Preload("Product").Preload("Warehouse").Preload("CreatedUser")
|
return db.
|
||||||
|
Preload("Product.Flags").
|
||||||
|
Preload("Product").
|
||||||
|
Preload("Warehouse").
|
||||||
|
Preload("CreatedUser")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s productWarehouseService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.ProductWarehouse, int64, error) {
|
func (s productWarehouseService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.ProductWarehouse, int64, error) {
|
||||||
@@ -55,6 +59,12 @@ func (s productWarehouseService) GetAll(c *fiber.Ctx, params *validation.Query)
|
|||||||
db = db.Where("warehouse_id = ?", params.WarehouseId)
|
db = db.Where("warehouse_id = ?", params.WarehouseId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if params.Flag != "" {
|
||||||
|
db = db.Joins("JOIN products ON products.id = product_warehouses.product_id")
|
||||||
|
db = db.Joins("JOIN flags ON flags.flagable_id = products.id AND flags.flagable_type = ?", "products")
|
||||||
|
db = db.Where("flags.name = ?", params.Flag)
|
||||||
|
}
|
||||||
|
|
||||||
return db.Order("created_at DESC").Order("updated_at DESC")
|
return db.Order("created_at DESC").Order("updated_at DESC")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -13,8 +13,9 @@ type Update struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Query struct {
|
type Query struct {
|
||||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
||||||
ProductId uint `query:"product_id" validate:"omitempty,number,min=1"`
|
ProductId uint `query:"product_id" validate:"omitempty,number,min=1"`
|
||||||
WarehouseId uint `query:"warehouse_id" validate:"omitempty,number,min=1"`
|
WarehouseId uint `query:"warehouse_id" validate:"omitempty,number,min=1"`
|
||||||
|
Flag string `query:"flag" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,17 +57,17 @@ type TransferDetailDTO struct {
|
|||||||
|
|
||||||
// Detail produk
|
// Detail produk
|
||||||
type TransferDetailItemDTO struct {
|
type TransferDetailItemDTO struct {
|
||||||
Id uint64 `json:"id"`
|
Id uint64 `json:"id"`
|
||||||
ProductId uint64 `json:"product_id"`
|
Product *ProductDTO `json:"product,omitempty"`
|
||||||
Quantity float64 `json:"quantity"`
|
Quantity float64 `json:"quantity"`
|
||||||
BeforeQuantity float64 `json:"before_quantity"`
|
BeforeQuantity float64 `json:"before_quantity"`
|
||||||
AfterQuantity float64 `json:"after_quantity"`
|
AfterQuantity float64 `json:"after_quantity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delivery ekspedisi
|
// Delivery ekspedisi
|
||||||
type TransferDeliveryDTO struct {
|
type TransferDeliveryDTO struct {
|
||||||
Id uint64 `json:"id"`
|
Id uint64 `json:"id"`
|
||||||
SupplierId uint64 `json:"supplier_id"`
|
Supplier *SupplierDTO `json:"supplier,omitempty"`
|
||||||
VehiclePlate string `json:"vehicle_plate"`
|
VehiclePlate string `json:"vehicle_plate"`
|
||||||
DriverName string `json:"driver_name"`
|
DriverName string `json:"driver_name"`
|
||||||
DocumentNumber string `json:"document_number"`
|
DocumentNumber string `json:"document_number"`
|
||||||
@@ -83,6 +83,16 @@ type TransferDeliveryItemDTO struct {
|
|||||||
Quantity float64 `json:"quantity"`
|
Quantity float64 `json:"quantity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProductDTO struct {
|
||||||
|
Id uint64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SupplierDTO struct {
|
||||||
|
Id uint64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
// === Mapper Functions ===
|
// === Mapper Functions ===
|
||||||
|
|
||||||
func ToTransferBaseDTO(e entity.StockTransfer) TransferBaseDTO {
|
func ToTransferBaseDTO(e entity.StockTransfer) TransferBaseDTO {
|
||||||
@@ -114,6 +124,26 @@ func toAreaDTO(a *entity.Area) *AreaDTO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toProductDTO(p *entity.Product) *ProductDTO {
|
||||||
|
if p == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &ProductDTO{
|
||||||
|
Id: uint64(p.Id),
|
||||||
|
Name: p.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func toSupplierDTO(s *entity.Supplier) *SupplierDTO {
|
||||||
|
if s == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &SupplierDTO{
|
||||||
|
Id: uint64(s.Id),
|
||||||
|
Name: s.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func toLocationDTO(l *entity.Location) *LocationDTO {
|
func toLocationDTO(l *entity.Location) *LocationDTO {
|
||||||
if l == nil {
|
if l == nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -142,19 +172,19 @@ func ToTransferListDTO(e entity.StockTransfer) TransferListDTO {
|
|||||||
mapped := userDTO.ToUserBaseDTO(*e.CreatedUser)
|
mapped := userDTO.ToUserBaseDTO(*e.CreatedUser)
|
||||||
createdUser = &mapped
|
createdUser = &mapped
|
||||||
}
|
}
|
||||||
// Map details
|
|
||||||
var details []TransferDetailItemDTO
|
var details []TransferDetailItemDTO
|
||||||
for _, d := range e.Details {
|
for _, d := range e.Details {
|
||||||
details = append(details, TransferDetailItemDTO{
|
details = append(details, TransferDetailItemDTO{
|
||||||
Id: d.Id,
|
Id: d.Id,
|
||||||
ProductId: d.ProductId,
|
Product: toProductDTO(d.Product),
|
||||||
Quantity: d.Quantity,
|
Quantity: d.Quantity,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Map deliveries
|
|
||||||
var deliveries []TransferDeliveryDTO
|
var deliveries []TransferDeliveryDTO
|
||||||
for _, del := range e.Deliveries {
|
for _, del := range e.Deliveries {
|
||||||
// Map delivery items
|
|
||||||
var items []TransferDeliveryItemDTO
|
var items []TransferDeliveryItemDTO
|
||||||
for _, item := range del.Items {
|
for _, item := range del.Items {
|
||||||
items = append(items, TransferDeliveryItemDTO{
|
items = append(items, TransferDeliveryItemDTO{
|
||||||
@@ -165,8 +195,8 @@ func ToTransferListDTO(e entity.StockTransfer) TransferListDTO {
|
|||||||
}
|
}
|
||||||
deliveries = append(deliveries, TransferDeliveryDTO{
|
deliveries = append(deliveries, TransferDeliveryDTO{
|
||||||
Id: del.Id,
|
Id: del.Id,
|
||||||
SupplierId: del.SupplierId,
|
|
||||||
VehiclePlate: del.VehiclePlate,
|
VehiclePlate: del.VehiclePlate,
|
||||||
|
Supplier: toSupplierDTO(del.Supplier),
|
||||||
DriverName: del.DriverName,
|
DriverName: del.DriverName,
|
||||||
DocumentNumber: del.DocumentNumber,
|
DocumentNumber: del.DocumentNumber,
|
||||||
DocumentPath: del.DocumentPath,
|
DocumentPath: del.DocumentPath,
|
||||||
@@ -198,9 +228,9 @@ func ToTransferDetailDTO(e entity.StockTransfer) TransferDetailDTO {
|
|||||||
var details []TransferDetailItemDTO
|
var details []TransferDetailItemDTO
|
||||||
for _, d := range e.Details {
|
for _, d := range e.Details {
|
||||||
details = append(details, TransferDetailItemDTO{
|
details = append(details, TransferDetailItemDTO{
|
||||||
Id: d.Id,
|
Id: d.Id,
|
||||||
ProductId: d.ProductId,
|
Product: toProductDTO(d.Product),
|
||||||
Quantity: d.Quantity,
|
Quantity: d.Quantity,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Map deliveries
|
// Map deliveries
|
||||||
@@ -208,7 +238,7 @@ func ToTransferDetailDTO(e entity.StockTransfer) TransferDetailDTO {
|
|||||||
for _, del := range e.Deliveries {
|
for _, del := range e.Deliveries {
|
||||||
deliveries = append(deliveries, TransferDeliveryDTO{
|
deliveries = append(deliveries, TransferDeliveryDTO{
|
||||||
Id: del.Id,
|
Id: del.Id,
|
||||||
SupplierId: del.SupplierId,
|
Supplier: toSupplierDTO(del.Supplier),
|
||||||
VehiclePlate: del.VehiclePlate,
|
VehiclePlate: del.VehiclePlate,
|
||||||
DriverName: del.DriverName,
|
DriverName: del.DriverName,
|
||||||
DocumentNumber: del.DocumentNumber,
|
DocumentNumber: del.DocumentNumber,
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ func (s transferService) withRelations(db *gorm.DB) *gorm.DB {
|
|||||||
Preload("ToWarehouse.Location").
|
Preload("ToWarehouse.Location").
|
||||||
Preload("ToWarehouse.Area").
|
Preload("ToWarehouse.Area").
|
||||||
Preload("Details").
|
Preload("Details").
|
||||||
|
Preload("Details.Product").
|
||||||
|
Preload("Deliveries.Supplier").
|
||||||
Preload("Deliveries.Items")
|
Preload("Deliveries.Items")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user