mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'dev/gio' into 'feat/BE/Sprint-6'
adjust response inventory stock-product See merge request mbugroup/lti-api!79
This commit is contained in:
@@ -34,6 +34,7 @@ type ProductStockListDTO struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Suppliers []SupplierDTO `json:"suppliers,omitempty"`
|
||||
ProductWarehouses []ProductWarehouseDTO `json:"product_warehouses,omitempty"`
|
||||
TotalStock float64 `json:"total_stock"`
|
||||
}
|
||||
|
||||
type ProductStockDetailDTO struct {
|
||||
@@ -58,15 +59,16 @@ type ProductWarehouseDTO struct {
|
||||
}
|
||||
|
||||
type StockLogDetailDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Increase float64 `json:"increase"`
|
||||
Decrease float64 `json:"decrease"`
|
||||
LoggableType string `json:"loggable_type"`
|
||||
LoggableId uint `json:"loggable_id"`
|
||||
Notes *string `json:"notes"`
|
||||
ProductWarehouseId uint `json:"product_warehouse_id"`
|
||||
CreatedBy uint `json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Id uint `json:"id"`
|
||||
Increase float64 `json:"increase"`
|
||||
Decrease float64 `json:"decrease"`
|
||||
LoggableType string `json:"loggable_type"`
|
||||
LoggableId uint `json:"loggable_id"`
|
||||
Notes *string `json:"notes"`
|
||||
ProductWarehouseId uint `json:"product_warehouse_id"`
|
||||
CreatedBy uint `json:"created_by"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
@@ -110,6 +112,7 @@ func ToProductStockListDTO(e entity.Product) ProductStockListDTO {
|
||||
CreatedUser: createdUser,
|
||||
ProductCategory: categoryRef,
|
||||
Suppliers: mapSupplierDTOs(e.ProductSuppliers),
|
||||
TotalStock: calculateTotalStock(e.ProductWarehouses),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,8 +200,25 @@ func mapStockLogs(src []entity.StockLog) []StockLogDetailDTO {
|
||||
Notes: notes,
|
||||
ProductWarehouseId: log.ProductWarehouseId,
|
||||
CreatedBy: log.CreatedBy,
|
||||
CreatedUser: mapCreatedUser(log.CreatedUser),
|
||||
CreatedAt: log.CreatedAt,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func mapCreatedUser(user *entity.User) *userDTO.UserRelationDTO {
|
||||
if user == nil || user.Id == 0 {
|
||||
return nil
|
||||
}
|
||||
mapped := userDTO.ToUserRelationDTO(*user)
|
||||
return &mapped
|
||||
}
|
||||
|
||||
func calculateTotalStock(productWarehouses []entity.ProductWarehouse) float64 {
|
||||
var total float64
|
||||
for _, pw := range productWarehouses {
|
||||
total += pw.Quantity
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ func (s productStockService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
Preload("ProductWarehouses.StockLogs", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("created_at ASC")
|
||||
}).
|
||||
Preload("ProductWarehouses.StockLogs.CreatedUser").
|
||||
Preload("ProductSuppliers").
|
||||
Preload("ProductSuppliers.Supplier", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("suppliers.name ASC")
|
||||
|
||||
Reference in New Issue
Block a user