Files
lti-api/internal/modules/master/uoms/dto/uom.dto.go
T
2025-11-14 16:43:01 +07:00

67 lines
1.3 KiB
Go

package dto
import (
"time"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
)
// === DTO Structs ===
type UomBaseDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
}
type UomListDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type UomDetailDTO struct {
UomListDTO
}
// === Mapper Functions ===
func ToUomBaseDTO(e entity.Uom) UomBaseDTO {
return UomBaseDTO{
Id: e.Id,
Name: e.Name,
}
}
func ToUomListDTO(e entity.Uom) UomListDTO {
var createdUser *userDTO.UserBaseDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
createdUser = &mapped
}
return UomListDTO{
Id: e.Id,
Name: e.Name,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
}
}
func ToUomListDTOs(e []entity.Uom) []UomListDTO {
result := make([]UomListDTO, len(e))
for i, r := range e {
result[i] = ToUomListDTO(r)
}
return result
}
func ToUomDetailDTO(e entity.Uom) UomDetailDTO {
return UomDetailDTO{
UomListDTO: ToUomListDTO(e),
}
}