mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 23:05:44 +00:00
Feat(BE-36,37,38,39): master area, customer, kandang, location, warehouse
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
areaDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto"
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type LocationBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Area *areaDTO.AreaBaseDTO `json:"area"`
|
||||
}
|
||||
|
||||
type LocationListDTO struct {
|
||||
LocationBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type LocationDetailDTO struct {
|
||||
LocationListDTO
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToLocationBaseDTO(e entity.Location) LocationBaseDTO {
|
||||
var area *areaDTO.AreaBaseDTO
|
||||
if e.Area.Id != 0 {
|
||||
mapped := areaDTO.ToAreaBaseDTO(e.Area)
|
||||
area = &mapped
|
||||
}
|
||||
|
||||
return LocationBaseDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Address: e.Address,
|
||||
Area: area,
|
||||
}
|
||||
}
|
||||
|
||||
func ToLocationListDTO(e entity.Location) LocationListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return LocationListDTO{
|
||||
LocationBaseDTO: ToLocationBaseDTO(e),
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func ToLocationListDTOs(e []entity.Location) []LocationListDTO {
|
||||
result := make([]LocationListDTO, len(e))
|
||||
for i, r := range e {
|
||||
result[i] = ToLocationListDTO(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user