mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
71 lines
1.5 KiB
Go
71 lines
1.5 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 BankRelationDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
Alias string `json:"alias"`
|
|
Owner *string `json:"owner"`
|
|
AccountNumber string `json:"account_number"`
|
|
}
|
|
|
|
type BankListDTO struct {
|
|
BankRelationDTO
|
|
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type BankDetailDTO struct {
|
|
BankListDTO
|
|
}
|
|
|
|
// === Mapper Functions ===
|
|
|
|
func ToBankRelationDTO(e entity.Bank) BankRelationDTO {
|
|
return BankRelationDTO{
|
|
Id: e.Id,
|
|
Name: e.Name,
|
|
Alias: e.Alias,
|
|
Owner: e.Owner,
|
|
AccountNumber: e.AccountNumber,
|
|
}
|
|
}
|
|
|
|
func ToBankListDTO(e entity.Bank) BankListDTO {
|
|
var createdUser *userDTO.UserRelationDTO
|
|
if e.CreatedUser.Id != 0 {
|
|
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
|
createdUser = &mapped
|
|
}
|
|
|
|
return BankListDTO{
|
|
BankRelationDTO: ToBankRelationDTO(e),
|
|
CreatedAt: e.CreatedAt,
|
|
UpdatedAt: e.UpdatedAt,
|
|
CreatedUser: createdUser,
|
|
}
|
|
}
|
|
|
|
func ToBankListDTOs(e []entity.Bank) []BankListDTO {
|
|
result := make([]BankListDTO, len(e))
|
|
for i, r := range e {
|
|
result[i] = ToBankListDTO(r)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ToBankDetailDTO(e entity.Bank) BankDetailDTO {
|
|
return BankDetailDTO{
|
|
BankListDTO: ToBankListDTO(e),
|
|
}
|
|
}
|