adjust response location to object

This commit is contained in:
giovanni-ce
2025-12-04 11:27:02 +07:00
parent 730fb22cc2
commit 33a9d7806e
2 changed files with 11 additions and 8 deletions
@@ -4,6 +4,7 @@ import (
"time" "time"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities" entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
locationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto"
productCategoryDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/product-categories/dto" productCategoryDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/product-categories/dto"
uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto" uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto"
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto" userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
@@ -47,13 +48,13 @@ type SupplierDTO struct {
} }
type ProductWarehouseDTO struct { type ProductWarehouseDTO struct {
Id uint `json:"id"` Id uint `json:"id"`
ProductId uint `json:"product_id"` ProductId uint `json:"product_id"`
WarehouseId uint `json:"warehouse_id"` WarehouseId uint `json:"warehouse_id"`
WarehouseName string `json:"warehouse_name"` WarehouseName string `json:"warehouse_name"`
Location string `json:"location"` Location *locationDTO.LocationRelationDTO `json:"location"`
CurrentStock float64 `json:"current_stock"` CurrentStock float64 `json:"current_stock"`
StockLogs []StockLogDetailDTO `json:"stock_logs"` StockLogs []StockLogDetailDTO `json:"stock_logs"`
} }
type StockLogDetailDTO struct { type StockLogDetailDTO struct {
@@ -166,7 +167,8 @@ func mapProductWarehouseDTOs(src []entity.ProductWarehouse) []ProductWarehouseDT
if pw.Warehouse.Id != 0 { if pw.Warehouse.Id != 0 {
dto.WarehouseName = pw.Warehouse.Name dto.WarehouseName = pw.Warehouse.Name
if pw.Warehouse.Location != nil { if pw.Warehouse.Location != nil {
dto.Location = pw.Warehouse.Location.Name mapped := locationDTO.ToLocationRelationDTO(*pw.Warehouse.Location)
dto.Location = &mapped
} }
} }
result = append(result, dto) result = append(result, dto)
@@ -45,6 +45,7 @@ func (s productStockService) withRelations(db *gorm.DB) *gorm.DB {
Preload("ProductWarehouses"). Preload("ProductWarehouses").
Preload("ProductWarehouses.Warehouse"). Preload("ProductWarehouses.Warehouse").
Preload("ProductWarehouses.Warehouse.Location"). Preload("ProductWarehouses.Warehouse.Location").
Preload("ProductWarehouses.Warehouse.Location.Area").
Preload("ProductWarehouses.StockLogs", func(db *gorm.DB) *gorm.DB { Preload("ProductWarehouses.StockLogs", func(db *gorm.DB) *gorm.DB {
return db.Order("created_at ASC") return db.Order("created_at ASC")
}). }).