mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-26 08:15:43 +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),
|
||||
ProductId: uint(c.QueryInt("product_id", 0)),
|
||||
WarehouseId: uint(c.QueryInt("warehouse_id", 0)),
|
||||
Flag: c.Query("flag"),
|
||||
}
|
||||
|
||||
result, totalResults, err := u.ProductWarehouseService.GetAll(c, query)
|
||||
@@ -71,5 +72,3 @@ func (u *ProductWarehouseController) GetOne(c *fiber.Ctx) error {
|
||||
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 {
|
||||
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) {
|
||||
@@ -55,6 +59,12 @@ func (s productWarehouseService) GetAll(c *fiber.Ctx, params *validation.Query)
|
||||
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")
|
||||
})
|
||||
|
||||
|
||||
+5
-4
@@ -13,8 +13,9 @@ type Update struct {
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
||||
ProductId uint `query:"product_id" validate:"omitempty,number,min=1"`
|
||||
WarehouseId uint `query:"warehouse_id" 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"`
|
||||
ProductId uint `query:"product_id" validate:"omitempty,number,min=1"`
|
||||
WarehouseId uint `query:"warehouse_id" validate:"omitempty,number,min=1"`
|
||||
Flag string `query:"flag" validate:"omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user