mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
adjust kandangs
This commit is contained in:
@@ -11,24 +11,32 @@ import (
|
|||||||
// === DTO Structs ===
|
// === DTO Structs ===
|
||||||
|
|
||||||
type KandangRelationDTO struct {
|
type KandangRelationDTO struct {
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Capacity float64 `json:"capacity"`
|
Capacity float64 `json:"capacity"`
|
||||||
Location *locationDTO.LocationRelationDTO `json:"location,omitempty"`
|
KandangGroup *KandangGroupRelationDTO `json:"kandang_group,omitempty"`
|
||||||
Pic *userDTO.UserRelationDTO `json:"pic,omitempty"`
|
Location *locationDTO.LocationRelationDTO `json:"location,omitempty"`
|
||||||
|
Pic *userDTO.UserRelationDTO `json:"pic,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type KandangGroupRelationDTO struct {
|
||||||
|
Id uint `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KandangListDTO struct {
|
type KandangListDTO struct {
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Capacity float64 `json:"capacity"`
|
Capacity float64 `json:"capacity"`
|
||||||
Location locationDTO.LocationRelationDTO `json:"location"`
|
KandangGroup KandangGroupRelationDTO `json:"kandang_group"`
|
||||||
Pic userDTO.UserRelationDTO `json:"pic"`
|
Location locationDTO.LocationRelationDTO `json:"location"`
|
||||||
CreatedUser userDTO.UserRelationDTO `json:"created_user"`
|
Pic userDTO.UserRelationDTO `json:"pic"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedUser userDTO.UserRelationDTO `json:"created_user"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KandangDetailDTO struct {
|
type KandangDetailDTO struct {
|
||||||
@@ -38,6 +46,12 @@ type KandangDetailDTO struct {
|
|||||||
// === Mapper Functions ===
|
// === Mapper Functions ===
|
||||||
|
|
||||||
func ToKandangRelationDTO(e entity.Kandang) KandangRelationDTO {
|
func ToKandangRelationDTO(e entity.Kandang) KandangRelationDTO {
|
||||||
|
var kandangGroup *KandangGroupRelationDTO
|
||||||
|
if e.KandangGroup.Id != 0 {
|
||||||
|
mapped := ToKandangGroupRelationDTO(e.KandangGroup)
|
||||||
|
kandangGroup = &mapped
|
||||||
|
}
|
||||||
|
|
||||||
var location *locationDTO.LocationRelationDTO
|
var location *locationDTO.LocationRelationDTO
|
||||||
if e.Location.Id != 0 {
|
if e.Location.Id != 0 {
|
||||||
mapped := locationDTO.ToLocationRelationDTO(e.Location)
|
mapped := locationDTO.ToLocationRelationDTO(e.Location)
|
||||||
@@ -51,16 +65,31 @@ func ToKandangRelationDTO(e entity.Kandang) KandangRelationDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return KandangRelationDTO{
|
return KandangRelationDTO{
|
||||||
Id: e.Id,
|
Id: e.Id,
|
||||||
Name: e.Name,
|
Name: e.Name,
|
||||||
Status: e.Status,
|
Status: e.Status,
|
||||||
Capacity: e.Capacity,
|
Capacity: e.Capacity,
|
||||||
Location: location,
|
KandangGroup: kandangGroup,
|
||||||
Pic: pic,
|
Location: location,
|
||||||
|
Pic: pic,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ToKandangGroupRelationDTO(e entity.KandangGroup) KandangGroupRelationDTO {
|
||||||
|
return KandangGroupRelationDTO{
|
||||||
|
Id: e.Id,
|
||||||
|
Name: e.Name,
|
||||||
|
Status: e.Status,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToKandangListDTO(e entity.Kandang) KandangListDTO {
|
func ToKandangListDTO(e entity.Kandang) KandangListDTO {
|
||||||
|
var kandangGroup KandangGroupRelationDTO
|
||||||
|
if e.KandangGroup.Id != 0 {
|
||||||
|
mapped := ToKandangGroupRelationDTO(e.KandangGroup)
|
||||||
|
kandangGroup = mapped
|
||||||
|
}
|
||||||
|
|
||||||
var location locationDTO.LocationRelationDTO
|
var location locationDTO.LocationRelationDTO
|
||||||
if e.Location.Id != 0 {
|
if e.Location.Id != 0 {
|
||||||
mapped := locationDTO.ToLocationRelationDTO(e.Location)
|
mapped := locationDTO.ToLocationRelationDTO(e.Location)
|
||||||
@@ -80,15 +109,16 @@ func ToKandangListDTO(e entity.Kandang) KandangListDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return KandangListDTO{
|
return KandangListDTO{
|
||||||
Id: e.Id,
|
Id: e.Id,
|
||||||
Name: e.Name,
|
Name: e.Name,
|
||||||
Status: e.Status,
|
Status: e.Status,
|
||||||
Location: location,
|
Location: location,
|
||||||
Capacity: e.Capacity,
|
KandangGroup: kandangGroup,
|
||||||
Pic: pic,
|
Capacity: e.Capacity,
|
||||||
CreatedAt: e.CreatedAt,
|
Pic: pic,
|
||||||
UpdatedAt: e.UpdatedAt,
|
CreatedAt: e.CreatedAt,
|
||||||
CreatedUser: createdUser,
|
UpdatedAt: e.UpdatedAt,
|
||||||
|
CreatedUser: createdUser,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func NewKandangService(repo repository.KandangRepository, validate *validator.Va
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s kandangService) withRelations(db *gorm.DB) *gorm.DB {
|
func (s kandangService) withRelations(db *gorm.DB) *gorm.DB {
|
||||||
return db.Preload("CreatedUser").Preload("Location").Preload("Pic").Preload("ProjectFlockKandangs.ProjectFlock")
|
return db.Preload("CreatedUser").Preload("Location").Preload("KandangGroup").Preload("Pic").Preload("ProjectFlockKandangs.ProjectFlock")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user