add category name at product response
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user