mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 23:35:43 +00:00
feat(BE): price-product-supplier
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"time"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
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"
|
||||
)
|
||||
@@ -23,7 +22,7 @@ type NonstockListDTO struct {
|
||||
Name string `json:"name"`
|
||||
Flags []string `json:"flags"`
|
||||
Uom *uomDTO.UomRelationDTO `json:"uom"`
|
||||
Suppliers []supplierDTO.SupplierRelationDTO `json:"suppliers"`
|
||||
Suppliers []NonstockSupplierDTO `json:"suppliers"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
@@ -33,6 +32,14 @@ type NonstockDetailDTO struct {
|
||||
NonstockListDTO
|
||||
}
|
||||
|
||||
type NonstockSupplierDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Alias string `json:"alias"`
|
||||
Category string `json:"category"`
|
||||
Price float64 `json:"price"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToNonstockRelationDTO(e entity.Nonstock) NonstockRelationDTO {
|
||||
@@ -99,21 +106,27 @@ func ToNonstockDetailDTO(e entity.Nonstock) NonstockDetailDTO {
|
||||
}
|
||||
}
|
||||
|
||||
func toNonstockSupplierDTOs(relations []entity.NonstockSupplier) []supplierDTO.SupplierRelationDTO {
|
||||
func toNonstockSupplierDTOs(relations []entity.NonstockSupplier) []NonstockSupplierDTO {
|
||||
if len(relations) == 0 {
|
||||
return make([]supplierDTO.SupplierRelationDTO, 0)
|
||||
return make([]NonstockSupplierDTO, 0)
|
||||
}
|
||||
|
||||
result := make([]supplierDTO.SupplierRelationDTO, 0, len(relations))
|
||||
result := make([]NonstockSupplierDTO, 0, len(relations))
|
||||
for _, relation := range relations {
|
||||
if relation.Supplier.Id == 0 {
|
||||
continue
|
||||
}
|
||||
result = append(result, supplierDTO.ToSupplierRelationDTO(relation.Supplier))
|
||||
result = append(result, NonstockSupplierDTO{
|
||||
Id: relation.Supplier.Id,
|
||||
Name: relation.Supplier.Name,
|
||||
Alias: relation.Supplier.Alias,
|
||||
Category: relation.Supplier.Category,
|
||||
Price: relation.Price,
|
||||
})
|
||||
}
|
||||
|
||||
if len(result) == 0 {
|
||||
return make([]supplierDTO.SupplierRelationDTO, 0)
|
||||
return make([]NonstockSupplierDTO, 0)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user