feat(BE): add product flags to product warehouse response

This commit is contained in:
aguhh18
2025-10-16 12:51:41 +07:00
parent f6f62246c6
commit 9f26d5c784
2 changed files with 15 additions and 8 deletions
@@ -10,10 +10,10 @@ import (
// === DTO Structs === // === DTO Structs ===
type ProductWarehouseBaseDTO struct { type ProductWarehouseBaseDTO 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"`
Quantity float64 `json:"quantity"` Quantity float64 `json:"quantity"`
} }
type ProductWarehouseListDTO struct { type ProductWarehouseListDTO struct {
@@ -31,9 +31,10 @@ type ProductWarehouseDetailDTO struct {
// Nested DTOs for relations // Nested DTOs for relations
type ProductBaseDTO struct { type ProductBaseDTO struct {
Id uint `json:"id"` Id uint `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Sku string `json:"sku"` Sku string `json:"sku"`
Flags []string `json:"flags"`
} }
type WarehouseBaseDTO struct { type WarehouseBaseDTO struct {
@@ -68,6 +69,12 @@ func ToProductWarehouseListDTO(e entity.ProductWarehouse) ProductWarehouseListDT
if e.Product.Sku != nil { if e.Product.Sku != nil {
product.Sku = *e.Product.Sku product.Sku = *e.Product.Sku
} }
// Map flags from Product relation
if len(e.Product.Flags) > 0 {
for _, f := range e.Product.Flags {
product.Flags = append(product.Flags, f.Name)
}
}
dto.Product = &product dto.Product = &product
} }
@@ -34,7 +34,7 @@ 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").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) {