mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
Feat(BE-36,37,38,39): finish master data management api
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
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 SupplierBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Alias string `json:"alias"`
|
||||
Category string `json:"category"`
|
||||
}
|
||||
|
||||
type SupplierListDTO struct {
|
||||
SupplierBaseDTO
|
||||
Pic string `json:"pic"`
|
||||
Type string `json:"type"`
|
||||
Hatchery *string `json:"hatchery,omitempty"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
Address string `json:"address"`
|
||||
Npwp *string `json:"npwp,omitempty"`
|
||||
AccountNumber *string `json:"account_number,omitempty"`
|
||||
Balance float64 `json:"balance"`
|
||||
DueDate int `json:"due_date"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type SupplierDetailDTO struct {
|
||||
SupplierListDTO
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToSupplierBaseDTO(e entity.Supplier) SupplierBaseDTO {
|
||||
return SupplierBaseDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Alias: e.Alias,
|
||||
Category: e.Category,
|
||||
}
|
||||
}
|
||||
|
||||
func ToSupplierListDTO(e entity.Supplier) SupplierListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return SupplierListDTO{
|
||||
Pic: e.Pic,
|
||||
Type: e.Type,
|
||||
Hatchery: e.Hatchery,
|
||||
Phone: e.Phone,
|
||||
Email: e.Email,
|
||||
Address: e.Address,
|
||||
Npwp: e.Npwp,
|
||||
AccountNumber: e.AccountNumber,
|
||||
Balance: e.Balance,
|
||||
DueDate: e.DueDate,
|
||||
SupplierBaseDTO: ToSupplierBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
func ToSupplierListDTOs(e []entity.Supplier) []SupplierListDTO {
|
||||
result := make([]SupplierListDTO, len(e))
|
||||
for i, r := range e {
|
||||
result[i] = ToSupplierListDTO(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ToSupplierDetailDTO(e entity.Supplier) SupplierDetailDTO {
|
||||
return SupplierDetailDTO{
|
||||
SupplierListDTO: ToSupplierListDTO(e),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user