mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
69 lines
1.8 KiB
Go
69 lines
1.8 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 uint64 `json:"id"`
|
|
PoNumber string `json:"po_number"`
|
|
ExpenseDate time.Time `json:"expense_date"`
|
|
GrandTotal float64 `json:"grand_total"`
|
|
}
|
|
|
|
type ExpenseListDTO struct {
|
|
Id uint64 `json:"id"`
|
|
ReferenceNumber string `json:"reference_number"`
|
|
PoNumber string `json:"po_number"`
|
|
Category string `json:"category"`
|
|
ExpenseDate time.Time `json:"expense_date"`
|
|
GrandTotal float64 `json:"grand_total"`
|
|
CreatedUser *userDTO.UserBaseDTO `json:"created_user,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// === Mapper Functions ===
|
|
|
|
func ToExpenseBaseDTO(e entity.Expense) ExpenseBaseDTO {
|
|
return ExpenseBaseDTO{
|
|
Id: e.Id,
|
|
PoNumber: e.PoNumber,
|
|
ExpenseDate: e.ExpenseDate,
|
|
GrandTotal: e.GrandTotal,
|
|
}
|
|
}
|
|
|
|
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,
|
|
ReferenceNumber: *e.ReferenceNumber,
|
|
PoNumber: e.PoNumber,
|
|
Category: e.Category,
|
|
ExpenseDate: e.ExpenseDate,
|
|
GrandTotal: e.GrandTotal,
|
|
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
|
|
}
|