mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 15:55:44 +00:00
feat(BE-115,116,117): implement chickin CRUD, approve logic, and stock availabilit
This commit is contained in:
+2
-1
@@ -28,7 +28,6 @@ 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)
|
||||
@@ -72,3 +71,5 @@ func (u *ProductWarehouseController) GetOne(c *fiber.Ctx) error {
|
||||
Data: dto.ToProductWarehouseListDTO(*result),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-20
@@ -34,14 +34,7 @@ func NewProductWarehouseService(repo repository.ProductWarehouseRepository, vali
|
||||
}
|
||||
|
||||
func (s productWarehouseService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
return db.
|
||||
Preload("Product").
|
||||
Preload("Product.Flags").
|
||||
Preload("Warehouse").
|
||||
Preload("Warehouse.Location").
|
||||
Preload("Warehouse.Kandang").
|
||||
Preload("Warehouse.Area").
|
||||
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) {
|
||||
@@ -62,12 +55,6 @@ 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")
|
||||
})
|
||||
|
||||
@@ -75,11 +62,6 @@ func (s productWarehouseService) GetAll(c *fiber.Ctx, params *validation.Query)
|
||||
s.Log.Errorf("Failed to get productWarehouses: %+v", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if len(productWarehouses) == 0 {
|
||||
return nil, 0, fiber.NewError(fiber.StatusNotFound, "ProductWarehouses not found")
|
||||
}
|
||||
|
||||
return productWarehouses, total, nil
|
||||
}
|
||||
|
||||
@@ -88,7 +70,6 @@ func (s productWarehouseService) GetOne(c *fiber.Ctx, id uint) (*entity.ProductW
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, "ProductWarehouse not found")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed get productWarehouse by id: %+v", err)
|
||||
return nil, err
|
||||
|
||||
+4
-5
@@ -13,9 +13,8 @@ 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"`
|
||||
Flag string `query:"flag" validate:"omitempty"`
|
||||
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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user