mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
package dto
|
|
|
|
import (
|
|
"time"
|
|
|
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
|
areaDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto"
|
|
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
|
)
|
|
|
|
// === DTO Structs ===
|
|
|
|
type LocationBaseDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
Address string `json:"address"`
|
|
Area *areaDTO.AreaBaseDTO `json:"area"`
|
|
}
|
|
|
|
type LocationListDTO struct {
|
|
LocationBaseDTO
|
|
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type LocationDetailDTO struct {
|
|
LocationListDTO
|
|
}
|
|
|
|
// === Mapper Functions ===
|
|
|
|
func ToLocationBaseDTO(e entity.Location) LocationBaseDTO {
|
|
var area *areaDTO.AreaBaseDTO
|
|
if e.Area.Id != 0 {
|
|
mapped := areaDTO.ToAreaBaseDTO(e.Area)
|
|
area = &mapped
|
|
}
|
|
|
|
return LocationBaseDTO{
|
|
Id: e.Id,
|
|
Name: e.Name,
|
|
Address: e.Address,
|
|
Area: area,
|
|
}
|
|
}
|
|
|
|
func ToLocationListDTO(e entity.Location) LocationListDTO {
|
|
var createdUser *userDTO.UserBaseDTO
|
|
if e.CreatedUser.Id != 0 {
|
|
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
|
createdUser = &mapped
|
|
}
|
|
|
|
return LocationListDTO{
|
|
LocationBaseDTO: ToLocationBaseDTO(e),
|
|
CreatedUser: createdUser,
|
|
CreatedAt: e.CreatedAt,
|
|
UpdatedAt: e.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func ToLocationListDTOs(e []entity.Location) []LocationListDTO {
|
|
result := make([]LocationListDTO, len(e))
|
|
for i, r := range e {
|
|
result[i] = ToLocationListDTO(r)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ToLocationDetailDTO(e entity.Location) LocationDetailDTO {
|
|
return LocationDetailDTO{
|
|
LocationListDTO: ToLocationListDTO(e),
|
|
}
|
|
}
|