mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
51 lines
1.1 KiB
Cheetah
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}}
|