mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
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 DailyChecklistRelationDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type DailyChecklistListDTO 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 DailyChecklistDetailDTO struct {
|
|
DailyChecklistListDTO
|
|
}
|
|
|
|
// === Mapper Functions ===
|
|
|
|
func ToDailyChecklistRelationDTO(e entity.DailyChecklist) DailyChecklistRelationDTO {
|
|
var name string
|
|
if e.Name != nil {
|
|
name = *e.Name
|
|
}
|
|
|
|
return DailyChecklistRelationDTO{
|
|
Id: e.Id,
|
|
Name: name,
|
|
}
|
|
}
|
|
|
|
func ToDailyChecklistListDTO(e entity.DailyChecklist) DailyChecklistListDTO {
|
|
var createdUser *userDTO.UserRelationDTO
|
|
// if e.CreatedUser.Id != 0 {
|
|
// mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
|
// createdUser = &mapped
|
|
// }
|
|
|
|
var name string
|
|
if e.Name != nil {
|
|
name = *e.Name
|
|
}
|
|
|
|
return DailyChecklistListDTO{
|
|
Id: e.Id,
|
|
Name: name,
|
|
CreatedAt: e.CreatedAt,
|
|
UpdatedAt: e.UpdatedAt,
|
|
CreatedUser: createdUser,
|
|
}
|
|
}
|
|
|
|
func ToDailyChecklistListDTOs(e []entity.DailyChecklist) []DailyChecklistListDTO {
|
|
result := make([]DailyChecklistListDTO, len(e))
|
|
for i, r := range e {
|
|
result[i] = ToDailyChecklistListDTO(r)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ToDailyChecklistDetailDTO(e entity.DailyChecklist) DailyChecklistDetailDTO {
|
|
return DailyChecklistDetailDTO{
|
|
DailyChecklistListDTO: ToDailyChecklistListDTO(e),
|
|
}
|
|
}
|