From bc0bf7fe16bbcb91da187cc865196a8d4d8c1afc Mon Sep 17 00:00:00 2001 From: "Hafizh A. Y" Date: Sat, 10 Jan 2026 18:25:04 +0700 Subject: [PATCH] fix(BE): not showed supplier in master data product --- .../master/products/dto/product.dto.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/internal/modules/master/products/dto/product.dto.go b/internal/modules/master/products/dto/product.dto.go index dfd4c86f..59f57034 100644 --- a/internal/modules/master/products/dto/product.dto.go +++ b/internal/modules/master/products/dto/product.dto.go @@ -5,6 +5,7 @@ import ( entity "gitlab.com/mbugroup/lti-api.git/internal/entities" productCategoryDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/product-categories/dto" + supplierDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/dto" uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto" userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto" ) @@ -19,6 +20,7 @@ type ProductRelationDTO struct { Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"` Flags *[]string `json:"flags,omitempty"` ProductCategory *productCategoryDTO.ProductCategoryRelationDTO `json:"product_category,omitempty"` + Suppliers []supplierDTO.SupplierRelationDTO `json:"suppliers"` } type ProductListDTO struct { @@ -33,6 +35,7 @@ type ProductListDTO struct { Flags []string `json:"flags"` Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"` ProductCategory *productCategoryDTO.ProductCategoryRelationDTO `json:"product_category,omitempty"` + Suppliers []supplierDTO.SupplierRelationDTO `json:"suppliers"` CreatedUser *userDTO.UserRelationDTO `json:"created_user"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` @@ -70,6 +73,7 @@ func ToProductRelationDTO(e entity.Product) ProductRelationDTO { Flags: &flags, Uom: uomRef, ProductCategory: categoryRef, + Suppliers: toProductSupplierDTOs(e.ProductSuppliers), } } @@ -112,6 +116,7 @@ func ToProductListDTO(e entity.Product) ProductListDTO { UpdatedAt: e.UpdatedAt, CreatedUser: createdUser, ProductCategory: categoryRef, + Suppliers: toProductSupplierDTOs(e.ProductSuppliers), } } @@ -128,3 +133,23 @@ func ToProductDetailDTO(e entity.Product) ProductDetailDTO { ProductListDTO: ToProductListDTO(e), } } + +func toProductSupplierDTOs(relations []entity.ProductSupplier) []supplierDTO.SupplierRelationDTO { + if len(relations) == 0 { + return make([]supplierDTO.SupplierRelationDTO, 0) + } + + result := make([]supplierDTO.SupplierRelationDTO, 0, len(relations)) + for _, relation := range relations { + if relation.Supplier.Id == 0 { + continue + } + result = append(result, supplierDTO.ToSupplierRelationDTO(relation.Supplier)) + } + + if len(result) == 0 { + return make([]supplierDTO.SupplierRelationDTO, 0) + } + + return result +}