mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
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
|
|
}
|
|
|
|
func ToKandangDetailDTO(e entity.Kandang) KandangDetailDTO {
|
|
return KandangDetailDTO{
|
|
KandangListDTO: ToKandangListDTO(e),
|
|
}
|
|
}
|