add category name at product response

This commit is contained in:
Efril
2026-04-20 14:21:27 +07:00
parent 80a78137a0
commit d3dddea1c7
4 changed files with 12 additions and 0 deletions
+9
View File
@@ -4,6 +4,8 @@ import (
"apskel-pos-be/internal/constants"
"apskel-pos-be/internal/entities"
"apskel-pos-be/internal/models"
"github.com/google/uuid"
)
func ProductEntityToModel(entity *entities.Product) *models.Product {
@@ -118,10 +120,17 @@ func ProductEntityToResponse(entity *entities.Product) *models.ProductResponse {
}
}
// Get category name from the Category relation
categoryName := ""
if entity.Category.ID != uuid.Nil {
categoryName = entity.Category.Name
}
return &models.ProductResponse{
ID: entity.ID,
OrganizationID: entity.OrganizationID,
CategoryID: entity.CategoryID,
CategoryName: categoryName,
SKU: entity.SKU,
Name: entity.Name,
Description: entity.Description,