mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
67 lines
1.4 KiB
Go
67 lines
1.4 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 ExpenseBaseDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type ExpenseListDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type ExpenseDetailDTO struct {
|
|
ExpenseListDTO
|
|
}
|
|
|
|
// === Mapper Functions ===
|
|
|
|
func ToExpenseBaseDTO(e entity.Expense) ExpenseBaseDTO {
|
|
return ExpenseBaseDTO{
|
|
Id: e.Id,
|
|
Name: e.Name,
|
|
}
|
|
}
|
|
|
|
func ToExpenseListDTO(e entity.Expense) ExpenseListDTO {
|
|
var createdUser *userDTO.UserBaseDTO
|
|
if e.CreatedUser.Id != 0 {
|
|
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
|
createdUser = &mapped
|
|
}
|
|
|
|
return ExpenseListDTO{
|
|
Id: e.Id,
|
|
Name: e.Name,
|
|
CreatedAt: e.CreatedAt,
|
|
UpdatedAt: e.UpdatedAt,
|
|
CreatedUser: createdUser,
|
|
}
|
|
}
|
|
|
|
func ToExpenseListDTOs(e []entity.Expense) []ExpenseListDTO {
|
|
result := make([]ExpenseListDTO, len(e))
|
|
for i, r := range e {
|
|
result[i] = ToExpenseListDTO(r)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ToExpenseDetailDTO(e entity.Expense) ExpenseDetailDTO {
|
|
return ExpenseDetailDTO{
|
|
ExpenseListDTO: ToExpenseListDTO(e),
|
|
}
|
|
}
|