mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
68 lines
1.7 KiB
Cheetah
68 lines
1.7 KiB
Cheetah
{{define "dto"}}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 {{Pascal .Entity}}RelationDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type {{Pascal .Entity}}ListDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type {{Pascal .Entity}}DetailDTO struct {
|
|
{{Pascal .Entity}}ListDTO
|
|
}
|
|
|
|
// === Mapper Functions ===
|
|
|
|
func To{{Pascal .Entity}}RelationDTO(e entity.{{Pascal .Entity}}) {{Pascal .Entity}}RelationDTO {
|
|
return {{Pascal .Entity}}RelationDTO{
|
|
Id: e.Id,
|
|
Name: e.Name,
|
|
}
|
|
}
|
|
|
|
func To{{Pascal .Entity}}ListDTO(e entity.{{Pascal .Entity}}) {{Pascal .Entity}}ListDTO {
|
|
var createdUser *userDTO.UserRelationDTO
|
|
if e.CreatedUser.Id != 0 {
|
|
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
|
createdUser = &mapped
|
|
}
|
|
|
|
return {{Pascal .Entity}}ListDTO{
|
|
Id: e.Id,
|
|
Name: e.Name,
|
|
CreatedAt: e.CreatedAt,
|
|
UpdatedAt: e.UpdatedAt,
|
|
CreatedUser: createdUser,
|
|
}
|
|
}
|
|
|
|
func To{{Pascal .Entity}}ListDTOs(e []entity.{{Pascal .Entity}}) []{{Pascal .Entity}}ListDTO {
|
|
result := make([]{{Pascal .Entity}}ListDTO, len(e))
|
|
for i, r := range e {
|
|
result[i] = To{{Pascal .Entity}}ListDTO(r)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func To{{Pascal .Entity}}DetailDTO(e entity.{{Pascal .Entity}}) {{Pascal .Entity}}DetailDTO {
|
|
return {{Pascal .Entity}}DetailDTO{
|
|
{{Pascal .Entity}}ListDTO: To{{Pascal .Entity}}ListDTO(e),
|
|
}
|
|
}
|
|
{{end}}
|