fix(BE-273): add object nonstock and supplier in response get one and fix name base to relation in dto

This commit is contained in:
Hafizh A. Y
2025-11-20 14:59:50 +07:00
parent b4b860b9d4
commit 228aedc215
64 changed files with 964 additions and 3576 deletions
@@ -4,26 +4,26 @@ import (
"time"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
areaBaseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto"
fcrBaseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/fcrs/dto"
flockBaseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
kandangBaseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/dto"
locationBaseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto"
areaRelationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto"
fcrRelationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/fcrs/dto"
flockRelationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
kandangRelationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/dto"
locationRelationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto"
productDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/products/dto"
warehouseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/dto"
pfutils "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/utils"
userBaseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
userRelationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
)
// === DTO Structs (ordered) ===
type ProductWarehouseDTO struct {
Id uint `json:"id"`
Product *productDTO.ProductBaseDTO `json:"product,omitempty"`
Warehouse *warehouseDTO.WarehouseBaseDTO `json:"warehouse,omitempty"`
Id uint `json:"id"`
Product *productDTO.ProductRelationDTO `json:"product,omitempty"`
Warehouse *warehouseDTO.WarehouseRelationDTO `json:"warehouse,omitempty"`
}
type ChickinBaseDTO struct {
type ChickinRelationDTO struct {
Id uint `json:"id"`
ProjectFlockKandangId uint `json:"project_flock_kandang_id"`
ChickInDate time.Time `json:"chick_in_date"`
@@ -35,19 +35,19 @@ type ChickinBaseDTO struct {
}
type ProjectFlockDTO struct {
Id uint `json:"id"`
Period int `json:"period"`
Category string `json:"category"`
Flock *flockBaseDTO.FlockBaseDTO `json:"flock"`
Area *areaBaseDTO.AreaBaseDTO `json:"area"`
Fcr *fcrBaseDTO.FcrBaseDTO `json:"fcr"`
Location *locationBaseDTO.LocationBaseDTO `json:"location"`
Id uint `json:"id"`
Period int `json:"period"`
Category string `json:"category"`
Flock *flockRelationDTO.FlockRelationDTO `json:"flock"`
Area *areaRelationDTO.AreaRelationDTO `json:"area"`
Fcr *fcrRelationDTO.FcrRelationDTO `json:"fcr"`
Location *locationRelationDTO.LocationRelationDTO `json:"location"`
}
type ProjectFlockKandangDTO struct {
Id uint `json:"id"`
ProjectFlock *ProjectFlockDTO `json:"project_flock"`
Kandang *kandangBaseDTO.KandangBaseDTO `json:"kandang"`
Id uint `json:"id"`
ProjectFlock *ProjectFlockDTO `json:"project_flock"`
Kandang *kandangRelationDTO.KandangRelationDTO `json:"kandang"`
}
// gunakan base DTO dari package users
@@ -64,71 +64,71 @@ type ChickinSimpleDTO struct {
}
type ChickinListDTO struct {
ChickinBaseDTO
CreatedUser *userBaseDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ChickinRelationDTO
CreatedUser *userRelationDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ChickinDetailDTO struct {
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"`
PendingUsageQty float64 `json:"pending_usage_qty"`
Notes string `json:"notes"`
CreatedBy uint `json:"created_by"`
CreatedUser *userBaseDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
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"`
PendingUsageQty float64 `json:"pending_usage_qty"`
Notes string `json:"notes"`
CreatedBy uint `json:"created_by"`
CreatedUser *userRelationDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// === Mapper Functions (ordered) ===
func ToFlockDTO(e entity.Flock) flockBaseDTO.FlockBaseDTO {
return flockBaseDTO.ToFlockBaseDTO(e)
func ToFlockDTO(e entity.Flock) flockRelationDTO.FlockRelationDTO {
return flockRelationDTO.ToFlockRelationDTO(e)
}
func ToKandangDTO(e entity.Kandang) kandangBaseDTO.KandangBaseDTO {
return kandangBaseDTO.ToKandangBaseDTO(e)
func ToKandangDTO(e entity.Kandang) kandangRelationDTO.KandangRelationDTO {
return kandangRelationDTO.ToKandangRelationDTO(e)
}
func ToAreaDTO(e entity.Area) areaBaseDTO.AreaBaseDTO {
return areaBaseDTO.ToAreaBaseDTO(e)
func ToAreaDTO(e entity.Area) areaRelationDTO.AreaRelationDTO {
return areaRelationDTO.ToAreaRelationDTO(e)
}
func ToFcrDTO(e entity.Fcr) fcrBaseDTO.FcrBaseDTO {
return fcrBaseDTO.ToFcrBaseDTO(e)
func ToFcrDTO(e entity.Fcr) fcrRelationDTO.FcrRelationDTO {
return fcrRelationDTO.ToFcrRelationDTO(e)
}
func ToLocationDTO(e entity.Location) locationBaseDTO.LocationBaseDTO {
return locationBaseDTO.ToLocationBaseDTO(e)
func ToLocationDTO(e entity.Location) locationRelationDTO.LocationRelationDTO {
return locationRelationDTO.ToLocationRelationDTO(e)
}
func ToUserBaseDTO(e entity.User) userBaseDTO.UserBaseDTO {
return userBaseDTO.ToUserBaseDTO(e)
func ToUserRelationDTO(e entity.User) userRelationDTO.UserRelationDTO {
return userRelationDTO.ToUserRelationDTO(e)
}
func ToProjectFlockDTO(pfk entity.ProjectFlockKandang) ProjectFlockDTO {
e := pfk.ProjectFlock
var flock *flockBaseDTO.FlockBaseDTO
var flock *flockRelationDTO.FlockRelationDTO
if base := pfutils.DeriveBaseName(e.FlockName); base != "" {
summary := flockBaseDTO.FlockBaseDTO{Id: 0, Name: base}
summary := flockRelationDTO.FlockRelationDTO{Id: 0, Name: base}
flock = &summary
}
var area *areaBaseDTO.AreaBaseDTO
var area *areaRelationDTO.AreaRelationDTO
if e.Area.Id != 0 {
mapped := areaBaseDTO.ToAreaBaseDTO(e.Area)
mapped := areaRelationDTO.ToAreaRelationDTO(e.Area)
area = &mapped
}
var fcr *fcrBaseDTO.FcrBaseDTO
var fcr *fcrRelationDTO.FcrRelationDTO
if e.Fcr.Id != 0 {
mapped := fcrBaseDTO.ToFcrBaseDTO(e.Fcr)
mapped := fcrRelationDTO.ToFcrRelationDTO(e.Fcr)
fcr = &mapped
}
var location *locationBaseDTO.LocationBaseDTO
var location *locationRelationDTO.LocationRelationDTO
if e.Location.Id != 0 {
mapped := locationBaseDTO.ToLocationBaseDTO(e.Location)
mapped := locationRelationDTO.ToLocationRelationDTO(e.Location)
location = &mapped
}
return ProjectFlockDTO{
@@ -148,9 +148,9 @@ func ToProjectFlockKandangDTO(e entity.ProjectFlockKandang) ProjectFlockKandangD
mapped := ToProjectFlockDTO(e)
pf = &mapped
}
var kandang *kandangBaseDTO.KandangBaseDTO
var kandang *kandangRelationDTO.KandangRelationDTO
if e.Kandang.Id != 0 {
mapped := kandangBaseDTO.ToKandangBaseDTO(e.Kandang)
mapped := kandangRelationDTO.ToKandangRelationDTO(e.Kandang)
kandang = &mapped
}
return ProjectFlockKandangDTO{
@@ -160,7 +160,7 @@ func ToProjectFlockKandangDTO(e entity.ProjectFlockKandang) ProjectFlockKandangD
}
}
func ToChickinBaseDTO(e entity.ProjectChickin) ChickinBaseDTO {
func ToChickinRelationDTO(e entity.ProjectChickin) ChickinRelationDTO {
var projectFlockKandangId uint
// Check if ProjectFlockKandang relation is loaded
if e.ProjectFlockKandang != nil && e.ProjectFlockKandang.Id != 0 {
@@ -175,7 +175,7 @@ func ToChickinBaseDTO(e entity.ProjectChickin) ChickinBaseDTO {
productWarehouse = toProductWarehouseDTO(e.ProductWarehouse)
}
return ChickinBaseDTO{
return ChickinRelationDTO{
Id: e.Id,
ProjectFlockKandangId: projectFlockKandangId,
ChickInDate: e.ChickInDate,
@@ -201,16 +201,16 @@ func ToChickinSimpleDTO(e entity.ProjectChickin) ChickinSimpleDTO {
}
func ToChickinListDTO(e entity.ProjectChickin) ChickinListDTO {
var createdUser *userBaseDTO.UserBaseDTO
var createdUser *userRelationDTO.UserRelationDTO
if e.CreatedUser != nil && e.CreatedUser.Id != 0 {
mapped := userBaseDTO.ToUserBaseDTO(*e.CreatedUser)
mapped := userRelationDTO.ToUserRelationDTO(*e.CreatedUser)
createdUser = &mapped
}
return ChickinListDTO{
ChickinBaseDTO: ToChickinBaseDTO(e),
CreatedUser: createdUser,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
ChickinRelationDTO: ToChickinRelationDTO(e),
CreatedUser: createdUser,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
}
}
@@ -231,9 +231,9 @@ func ToChickinSimpleDTOs(e []entity.ProjectChickin) []ChickinSimpleDTO {
}
func ToChickinDetailDTO(e entity.ProjectChickin) ChickinDetailDTO {
var createdUser *userBaseDTO.UserBaseDTO
var createdUser *userRelationDTO.UserRelationDTO
if e.CreatedUser != nil && e.CreatedUser.Id != 0 {
mapped := userBaseDTO.ToUserBaseDTO(*e.CreatedUser)
mapped := userRelationDTO.ToUserRelationDTO(*e.CreatedUser)
createdUser = &mapped
}
@@ -268,8 +268,8 @@ func ToProductWarehouseDTO(pw *entity.ProductWarehouse) *ProductWarehouseDTO {
return nil
}
product := productDTO.ToProductBaseDTO(pw.Product)
warehouse := warehouseDTO.ToWarehouseBaseDTO(pw.Warehouse)
product := productDTO.ToProductRelationDTO(pw.Product)
warehouse := warehouseDTO.ToWarehouseRelationDTO(pw.Warehouse)
return &ProductWarehouseDTO{
Id: pw.Id,