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"`
|
ID uuid.UUID `json:"id"`
|
||||||
OrganizationID uuid.UUID `json:"organization_id"`
|
OrganizationID uuid.UUID `json:"organization_id"`
|
||||||
CategoryID uuid.UUID `json:"category_id"`
|
CategoryID uuid.UUID `json:"category_id"`
|
||||||
|
CategoryName string `json:"category_name"`
|
||||||
SKU *string `json:"sku"`
|
SKU *string `json:"sku"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import (
|
|||||||
"apskel-pos-be/internal/constants"
|
"apskel-pos-be/internal/constants"
|
||||||
"apskel-pos-be/internal/entities"
|
"apskel-pos-be/internal/entities"
|
||||||
"apskel-pos-be/internal/models"
|
"apskel-pos-be/internal/models"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProductEntityToModel(entity *entities.Product) *models.Product {
|
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{
|
return &models.ProductResponse{
|
||||||
ID: entity.ID,
|
ID: entity.ID,
|
||||||
OrganizationID: entity.OrganizationID,
|
OrganizationID: entity.OrganizationID,
|
||||||
CategoryID: entity.CategoryID,
|
CategoryID: entity.CategoryID,
|
||||||
|
CategoryName: categoryName,
|
||||||
SKU: entity.SKU,
|
SKU: entity.SKU,
|
||||||
Name: entity.Name,
|
Name: entity.Name,
|
||||||
Description: entity.Description,
|
Description: entity.Description,
|
||||||
|
|||||||
@ -95,6 +95,7 @@ type ProductResponse struct {
|
|||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
OrganizationID uuid.UUID
|
OrganizationID uuid.UUID
|
||||||
CategoryID uuid.UUID
|
CategoryID uuid.UUID
|
||||||
|
CategoryName string
|
||||||
SKU *string
|
SKU *string
|
||||||
Name string
|
Name string
|
||||||
Description *string
|
Description *string
|
||||||
|
|||||||
@ -101,6 +101,7 @@ func ProductModelResponseToResponse(prod *models.ProductResponse) *contract.Prod
|
|||||||
ID: prod.ID,
|
ID: prod.ID,
|
||||||
OrganizationID: prod.OrganizationID,
|
OrganizationID: prod.OrganizationID,
|
||||||
CategoryID: prod.CategoryID,
|
CategoryID: prod.CategoryID,
|
||||||
|
CategoryName: prod.CategoryName,
|
||||||
SKU: prod.SKU,
|
SKU: prod.SKU,
|
||||||
Name: prod.Name,
|
Name: prod.Name,
|
||||||
Description: prod.Description,
|
Description: prod.Description,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user