mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Feat(BE-36,37,38,39): master area, customer, kandang, location, warehouse
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
locationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto"
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type KandangBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Location *locationDTO.LocationBaseDTO `json:"location"`
|
||||
Pic *userDTO.UserBaseDTO `json:"pic"`
|
||||
}
|
||||
|
||||
type KandangListDTO struct {
|
||||
KandangBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type KandangDetailDTO struct {
|
||||
KandangListDTO
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToKandangBaseDTO(e entity.Kandang) KandangBaseDTO {
|
||||
var location *locationDTO.LocationBaseDTO
|
||||
if e.Location.Id != 0 {
|
||||
mapped := locationDTO.ToLocationBaseDTO(e.Location)
|
||||
location = &mapped
|
||||
}
|
||||
|
||||
var pic *userDTO.UserBaseDTO
|
||||
if e.Pic.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.Pic)
|
||||
pic = &mapped
|
||||
}
|
||||
|
||||
return KandangBaseDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Location: location,
|
||||
Pic: pic,
|
||||
}
|
||||
}
|
||||
|
||||
func ToKandangListDTO(e entity.Kandang) KandangListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return KandangListDTO{
|
||||
KandangBaseDTO: ToKandangBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
func ToKandangListDTOs(e []entity.Kandang) []KandangListDTO {
|
||||
result := make([]KandangListDTO, len(e))
|
||||
for i, r := range e {
|
||||
result[i] = ToKandangListDTO(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user