add category name at product response
This commit is contained in:
parent
80a78137a0
commit
d3dddea1c7
@ -59,6 +59,7 @@ type ProductResponse struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
OrganizationID uuid.UUID `json:"organization_id"`
|
||||
CategoryID uuid.UUID `json:"category_id"`
|
||||
CategoryName string `json:"category_name"`
|
||||
SKU *string `json:"sku"`
|
||||
Name string `json:"name"`
|
||||
Description *string `json:"description"`
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -95,6 +95,7 @@ type ProductResponse struct {
|
||||
ID uuid.UUID
|
||||
OrganizationID uuid.UUID
|
||||
CategoryID uuid.UUID
|
||||
CategoryName string
|
||||
SKU *string
|
||||
Name string
|
||||
Description *string
|
||||
|
||||
@ -101,6 +101,7 @@ func ProductModelResponseToResponse(prod *models.ProductResponse) *contract.Prod
|
||||
ID: prod.ID,
|
||||
OrganizationID: prod.OrganizationID,
|
||||
CategoryID: prod.CategoryID,
|
||||
CategoryName: prod.CategoryName,
|
||||
SKU: prod.SKU,
|
||||
Name: prod.Name,
|
||||
Description: prod.Description,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user