feat[BE]: Refactor Chickin create and approvals support chickin growing and chickin laying, and create get one project flock kandang API

This commit is contained in:
aguhh18
2025-11-02 21:06:03 +07:00
parent 219a6a39ed
commit 20f1be2ef8
21 changed files with 1002 additions and 206 deletions
@@ -15,8 +15,8 @@ import (
// === DTO Structs (ordered) ===
type ChickinBaseDTO struct {
Id uint `json:"id"`
ProjectFlockKandang *ProjectFlockKandangDTO `json:"project_flock_kandang"`
Id uint `json:"id"`
ProjectFlockKandangId uint `json:"project_flock_kandang_id"`
ChickInDate time.Time `json:"chick_in_date"`
ProductWarehouseId uint `json:"product_warehouse_id"`
UsageQty float64 `json:"usage_qty"`
@@ -55,10 +55,9 @@ type ChickinSimpleDTO struct {
type ChickinListDTO struct {
ChickinBaseDTO
ProjectFlockKandang *ProjectFlockKandangDTO `json:"project_flock_kandang"`
CreatedUser *userBaseDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedUser *userBaseDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ChickinDetailDTO struct {
@@ -141,14 +140,17 @@ func ToProjectFlockKandangDTO(e entity.ProjectFlockKandang) ProjectFlockKandangD
}
func ToChickinBaseDTO(e entity.ProjectChickin) ChickinBaseDTO {
var pfk *ProjectFlockKandangDTO
var projectFlockKandangId uint
// Check if ProjectFlockKandang relation is loaded
if e.ProjectFlockKandang != nil && e.ProjectFlockKandang.Id != 0 {
mapped := ToProjectFlockKandangDTO(*e.ProjectFlockKandang)
pfk = &mapped
projectFlockKandangId = e.ProjectFlockKandang.Id
} else if e.ProjectFlockKandangId != 0 {
// If relation is not loaded but ID is available, use the ID
projectFlockKandangId = e.ProjectFlockKandangId
}
return ChickinBaseDTO{
Id: e.Id,
ProjectFlockKandang: pfk,
ProjectFlockKandangId: projectFlockKandangId,
ChickInDate: e.ChickInDate,
ProductWarehouseId: e.ProductWarehouseId,
UsageQty: e.UsageQty,
@@ -176,17 +178,11 @@ func ToChickinListDTO(e entity.ProjectChickin) ChickinListDTO {
mapped := userBaseDTO.ToUserBaseDTO(*e.CreatedUser)
createdUser = &mapped
}
var pfk *ProjectFlockKandangDTO
if e.ProjectFlockKandang != nil && e.ProjectFlockKandang.Id != 0 {
mapped := ToProjectFlockKandangDTO(*e.ProjectFlockKandang)
pfk = &mapped
}
return ChickinListDTO{
ChickinBaseDTO: ToChickinBaseDTO(e),
ProjectFlockKandang: pfk,
CreatedUser: createdUser,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
ChickinBaseDTO: ToChickinBaseDTO(e),
CreatedUser: createdUser,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
}
}