mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
Feat[BE]: adding project flock kandang id into project flock get one projecct flock api
This commit is contained in:
@@ -23,25 +23,23 @@ type ProjectFlockBaseDTO struct {
|
|||||||
FlockName string `json:"flock_name"`
|
FlockName string `json:"flock_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KandangWithProjectFlockIdDTO struct {
|
|
||||||
Id uint `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
ProjectFlockKandangId uint `json:"project_flock_kandang_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProjectFlockListDTO struct {
|
type ProjectFlockListDTO struct {
|
||||||
ProjectFlockBaseDTO
|
ProjectFlockBaseDTO
|
||||||
// Flock *flockDTO.FlockBaseDTO `json:"flock,omitempty"`
|
// Flock *flockDTO.FlockBaseDTO `json:"flock,omitempty"`
|
||||||
Area *areaDTO.AreaBaseDTO `json:"area,omitempty"`
|
Area *areaDTO.AreaBaseDTO `json:"area,omitempty"`
|
||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Fcr *fcrDTO.FcrBaseDTO `json:"fcr,omitempty"`
|
Fcr *fcrDTO.FcrBaseDTO `json:"fcr,omitempty"`
|
||||||
Location *locationDTO.LocationBaseDTO `json:"location,omitempty"`
|
Location *locationDTO.LocationBaseDTO `json:"location,omitempty"`
|
||||||
Kandangs []kandangDTO.KandangBaseDTO `json:"kandangs,omitempty"`
|
Kandangs []KandangWithProjectFlockIdDTO `json:"kandangs,omitempty"`
|
||||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
Approval approvalDTO.ApprovalBaseDTO `json:"approval"`
|
Approval approvalDTO.ApprovalBaseDTO `json:"approval"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type KandangWithProjectFlockIdDTO struct {
|
||||||
|
kandangDTO.KandangBaseDTO
|
||||||
|
ProjectFlockKandangId uint `json:"project_flock_kandang_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProjectFlockDetailDTO struct {
|
type ProjectFlockDetailDTO struct {
|
||||||
@@ -60,11 +58,22 @@ func ToProjectFlockListDTO(e entity.ProjectFlock) ProjectFlockListDTO {
|
|||||||
createdUser = &mapped
|
createdUser = &mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
var kandangSummaries []kandangDTO.KandangBaseDTO
|
var kandangSummaries []KandangWithProjectFlockIdDTO
|
||||||
if len(e.Kandangs) > 0 {
|
if len(e.Kandangs) > 0 {
|
||||||
kandangSummaries = make([]kandangDTO.KandangBaseDTO, len(e.Kandangs))
|
kandangSummaries = make([]KandangWithProjectFlockIdDTO, len(e.Kandangs))
|
||||||
for i, kandang := range e.Kandangs {
|
for i, kandang := range e.Kandangs {
|
||||||
kandangSummaries[i] = kandangDTO.ToKandangBaseDTO(kandang)
|
// Find project_flock_kandang_id dari KandangHistory
|
||||||
|
var pfkId uint
|
||||||
|
for _, kh := range e.KandangHistory {
|
||||||
|
if kh.KandangId == kandang.Id {
|
||||||
|
pfkId = kh.Id
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kandangSummaries[i] = KandangWithProjectFlockIdDTO{
|
||||||
|
KandangBaseDTO: kandangDTO.ToKandangBaseDTO(kandang),
|
||||||
|
ProjectFlockKandangId: pfkId,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,9 @@ func (r *ProjectflockRepositoryImpl) withDefaultRelations(db *gorm.DB) *gorm.DB
|
|||||||
Preload("Area").
|
Preload("Area").
|
||||||
Preload("Fcr").
|
Preload("Fcr").
|
||||||
Preload("Location").
|
Preload("Location").
|
||||||
Preload("Kandangs")
|
Preload("Kandangs").
|
||||||
|
Preload("KandangHistory").
|
||||||
|
Preload("KandangHistory.Kandang")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ProjectflockRepositoryImpl) applyQueryFilters(db *gorm.DB, params *validation.Query) *gorm.DB {
|
func (r *ProjectflockRepositoryImpl) applyQueryFilters(db *gorm.DB, params *validation.Query) *gorm.DB {
|
||||||
|
|||||||
Reference in New Issue
Block a user