Files
lti-api/tools/templates/dto.tmpl
T
2025-09-30 14:45:54 +07:00

51 lines
1.1 KiB
Cheetah

{{define "dto"}}package dto
import (
"time"
model "gitlab.com/mbugroup/lti-api.git/internal/modules/{{Kebab .FeatName}}s/models"
)
// === DTO Structs ===
type {{Pascal .Entity}}BaseDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
}
type {{Pascal .Entity}}ListDTO struct {
{{Pascal .Entity}}BaseDTO
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}}BaseDTO(m model.{{Pascal .Entity}}) {{Pascal .Entity}}BaseDTO {
return {{Pascal .Entity}}BaseDTO{
Id: m.Id,
Name: m.Name,
}
}
func To{{Pascal .Entity}}ListDTO(m model.{{Pascal .Entity}}) {{Pascal .Entity}}ListDTO {
return {{Pascal .Entity}}ListDTO{
{{Pascal .Entity}}BaseDTO: To{{Pascal .Entity}}BaseDTO(m),
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
func To{{Pascal .Entity}}ListDTOs(m []model.{{Pascal .Entity}}) []{{Pascal .Entity}}ListDTO {
result := make([]{{Pascal .Entity}}ListDTO, len(m))
for i, r := range m {
result[i] = To{{Pascal .Entity}}ListDTO(r)
}
return result
}
{{end}}