package dto import ( "time" entity "gitlab.com/mbugroup/lti-api.git/internal/entities" locationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto" userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto" ) // === DTO Structs === type KandangBaseDTO struct { Id uint `json:"id"` Name string `json:"name"` Status string `json:"status"` Capacity float64 `json:"capacity"` Location locationDTO.LocationBaseDTO `json:"location,omitempty"` Pic userDTO.UserBaseDTO `json:"pic,omitempty"` } type KandangListDTO struct { Id uint `json:"id"` Name string `json:"name"` Status string `json:"status"` Capacity float64 `json:"capacity"` Location locationDTO.LocationBaseDTO `json:"location"` Pic userDTO.UserBaseDTO `json:"pic"` CreatedUser userDTO.UserBaseDTO `json:"created_user"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } type KandangDetailDTO struct { KandangListDTO } // === Mapper Functions === func ToKandangBaseDTO(e entity.Kandang) KandangBaseDTO { var location locationDTO.LocationBaseDTO if e.Location.Id != 0 { mapped := locationDTO.ToLocationBaseDTO(e.Location) location = mapped } var pic userDTO.UserBaseDTO if e.Pic.Id != 0 { mapped := userDTO.ToUserBaseDTO(e.Pic) pic = mapped } return KandangBaseDTO{ Id: e.Id, Name: e.Name, Status: e.Status, Capacity: e.Capacity, Location: location, Pic: pic, } } func ToKandangListDTO(e entity.Kandang) KandangListDTO { var location locationDTO.LocationBaseDTO if e.Location.Id != 0 { mapped := locationDTO.ToLocationBaseDTO(e.Location) location = mapped } var pic userDTO.UserBaseDTO if e.Pic.Id != 0 { mapped := userDTO.ToUserBaseDTO(e.Pic) pic = mapped } var createdUser userDTO.UserBaseDTO if e.CreatedUser.Id != 0 { mapped := userDTO.ToUserBaseDTO(e.CreatedUser) createdUser = mapped } return KandangListDTO{ Id: e.Id, Name: e.Name, Status: e.Status, Location: location, Pic: pic, CreatedAt: e.CreatedAt, UpdatedAt: e.UpdatedAt, CreatedUser: createdUser, } } func ToKandangListDTOs(e []entity.Kandang) []KandangListDTO { result := make([]KandangListDTO, len(e)) for i, r := range e { result[i] = ToKandangListDTO(r) } return result } func ToKandangDetailDTO(e entity.Kandang) KandangDetailDTO { return KandangDetailDTO{ KandangListDTO: ToKandangListDTO(e), } }