mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
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:
@@ -85,7 +85,7 @@ func (u *ApprovalController) GetAll(c *fiber.Ctx) error {
|
||||
|
||||
flat := dto.ToApprovalDTOs(records)
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.SuccessWithPaginate[dto.ApprovalBaseDTO]{
|
||||
JSON(response.SuccessWithPaginate[dto.ApprovalRelationDTO]{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get All approvals successfully",
|
||||
|
||||
@@ -10,24 +10,24 @@ import (
|
||||
approvalutils "gitlab.com/mbugroup/lti-api.git/internal/utils/approvals"
|
||||
)
|
||||
|
||||
type ApprovalBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
StepNumber uint16 `json:"step_number"`
|
||||
StepName string `json:"step_name"`
|
||||
Action *string `json:"action"`
|
||||
Notes *string `json:"notes"`
|
||||
ActionBy userDTO.UserBaseDTO `json:"action_by"`
|
||||
ActionAt time.Time `json:"action_at"`
|
||||
type ApprovalRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
StepNumber uint16 `json:"step_number"`
|
||||
StepName string `json:"step_name"`
|
||||
Action *string `json:"action"`
|
||||
Notes *string `json:"notes"`
|
||||
ActionBy userDTO.UserRelationDTO `json:"action_by"`
|
||||
ActionAt time.Time `json:"action_at"`
|
||||
}
|
||||
|
||||
type ApprovalGroupDTO struct {
|
||||
StepNumber uint16 `json:"step_number"`
|
||||
StepName string `json:"step_name"`
|
||||
Approvals []ApprovalBaseDTO `json:"approvals"`
|
||||
StepNumber uint16 `json:"step_number"`
|
||||
StepName string `json:"step_name"`
|
||||
Approvals []ApprovalRelationDTO `json:"approvals"`
|
||||
}
|
||||
|
||||
func ToApprovalDTO(e entity.Approval) ApprovalBaseDTO {
|
||||
dto := ApprovalBaseDTO{
|
||||
func ToApprovalDTO(e entity.Approval) ApprovalRelationDTO {
|
||||
dto := ApprovalRelationDTO{
|
||||
Id: e.Id,
|
||||
Notes: e.Notes,
|
||||
}
|
||||
@@ -54,10 +54,10 @@ func ToApprovalDTO(e entity.Approval) ApprovalBaseDTO {
|
||||
}
|
||||
|
||||
if e.ActionUser != nil && e.ActionUser.Id != 0 {
|
||||
user := userDTO.ToUserBaseDTO(*e.ActionUser)
|
||||
user := userDTO.ToUserRelationDTO(*e.ActionUser)
|
||||
dto.ActionBy = user
|
||||
} else if e.ActionBy != nil && *e.ActionBy != 0 {
|
||||
dto.ActionBy = userDTO.UserBaseDTO{
|
||||
dto.ActionBy = userDTO.UserRelationDTO{
|
||||
Id: *e.ActionBy,
|
||||
IdUser: int64(*e.ActionBy),
|
||||
}
|
||||
@@ -71,8 +71,8 @@ func ToApprovalDTO(e entity.Approval) ApprovalBaseDTO {
|
||||
return dto
|
||||
}
|
||||
|
||||
func ToApprovalDTOs(items []entity.Approval) []ApprovalBaseDTO {
|
||||
result := make([]ApprovalBaseDTO, len(items))
|
||||
func ToApprovalDTOs(items []entity.Approval) []ApprovalRelationDTO {
|
||||
result := make([]ApprovalRelationDTO, len(items))
|
||||
for i, item := range items {
|
||||
result[i] = ToApprovalDTO(item)
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func ToApprovalGroupDTOs(items []entity.Approval) []ApprovalGroupDTO {
|
||||
|
||||
type groupAccumulator struct {
|
||||
StepName string
|
||||
Approvals []ApprovalBaseDTO
|
||||
Approvals []ApprovalRelationDTO
|
||||
}
|
||||
|
||||
groups := make(map[uint16]*groupAccumulator)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type ExpenseBaseDTO struct {
|
||||
type ExpenseRelationDTO struct {
|
||||
Id uint64 `json:"id"`
|
||||
PoNumber string `json:"po_number"`
|
||||
ExpenseDate time.Time `json:"expense_date"`
|
||||
@@ -17,21 +17,21 @@ type ExpenseBaseDTO struct {
|
||||
}
|
||||
|
||||
type ExpenseListDTO struct {
|
||||
Id uint64 `json:"id"`
|
||||
ReferenceNumber string `json:"reference_number"`
|
||||
PoNumber string `json:"po_number"`
|
||||
Category string `json:"category"`
|
||||
ExpenseDate time.Time `json:"expense_date"`
|
||||
GrandTotal float64 `json:"grand_total"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Id uint64 `json:"id"`
|
||||
ReferenceNumber string `json:"reference_number"`
|
||||
PoNumber string `json:"po_number"`
|
||||
Category string `json:"category"`
|
||||
ExpenseDate time.Time `json:"expense_date"`
|
||||
GrandTotal float64 `json:"grand_total"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToExpenseBaseDTO(e entity.Expense) ExpenseBaseDTO {
|
||||
return ExpenseBaseDTO{
|
||||
func ToExpenseRelationDTO(e entity.Expense) ExpenseRelationDTO {
|
||||
return ExpenseRelationDTO{
|
||||
Id: e.Id,
|
||||
PoNumber: e.PoNumber,
|
||||
ExpenseDate: e.ExpenseDate,
|
||||
@@ -40,9 +40,9 @@ func ToExpenseBaseDTO(e entity.Expense) ExpenseBaseDTO {
|
||||
}
|
||||
|
||||
func ToExpenseListDTO(e entity.Expense) ExpenseListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(*e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(*e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
|
||||
@@ -10,28 +10,28 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type ProductBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SKU string `json:"sku"`
|
||||
ProductCategory *productCategoryDTO.ProductCategoryBaseDTO `json:"product_category,omitempty"`
|
||||
type ProductRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SKU string `json:"sku"`
|
||||
ProductCategory *productCategoryDTO.ProductCategoryRelationDTO `json:"product_category,omitempty"`
|
||||
}
|
||||
|
||||
type WarehouseBaseDTO struct {
|
||||
type WarehouseRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type ProductWarehouseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
ProductId uint `json:"product_id"`
|
||||
WarehouseId uint `json:"warehouse_id"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Product *ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
Id uint `json:"id"`
|
||||
ProductId uint `json:"product_id"`
|
||||
WarehouseId uint `json:"warehouse_id"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Product *ProductRelationDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseRelationDTO `json:"warehouse,omitempty"`
|
||||
}
|
||||
|
||||
type AdjustmentBaseDTO struct {
|
||||
type AdjustmentRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
TransactionType string `json:"transaction_type"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
@@ -43,9 +43,9 @@ type AdjustmentBaseDTO struct {
|
||||
}
|
||||
|
||||
type AdjustmentListDTO struct {
|
||||
AdjustmentBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
AdjustmentRelationDTO
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type AdjustmentDetailDTO struct {
|
||||
@@ -55,7 +55,7 @@ type AdjustmentDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToProductBaseDTO(e *entity.Product) *ProductBaseDTO {
|
||||
func ToProductRelationDTO(e *entity.Product) *ProductRelationDTO {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -64,13 +64,13 @@ func ToProductBaseDTO(e *entity.Product) *ProductBaseDTO {
|
||||
sku = *e.Sku
|
||||
}
|
||||
|
||||
var category *productCategoryDTO.ProductCategoryBaseDTO
|
||||
var category *productCategoryDTO.ProductCategoryRelationDTO
|
||||
if e.ProductCategory.Id != 0 {
|
||||
mapped := productCategoryDTO.ToProductCategoryBaseDTO(e.ProductCategory)
|
||||
mapped := productCategoryDTO.ToProductCategoryRelationDTO(e.ProductCategory)
|
||||
category = &mapped
|
||||
}
|
||||
|
||||
return &ProductBaseDTO{
|
||||
return &ProductRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
SKU: sku,
|
||||
@@ -78,11 +78,11 @@ func ToProductBaseDTO(e *entity.Product) *ProductBaseDTO {
|
||||
}
|
||||
}
|
||||
|
||||
func ToWarehouseBaseDTO(e *entity.Warehouse) *WarehouseBaseDTO {
|
||||
func ToWarehouseRelationDTO(e *entity.Warehouse) *WarehouseRelationDTO {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
return &WarehouseBaseDTO{
|
||||
return &WarehouseRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
@@ -97,13 +97,13 @@ func ToProductWarehouseDTO(e *entity.ProductWarehouse) *ProductWarehouseDTO {
|
||||
ProductId: e.ProductId,
|
||||
WarehouseId: e.WarehouseId,
|
||||
Quantity: e.Quantity,
|
||||
Product: ToProductBaseDTO(&e.Product),
|
||||
Warehouse: ToWarehouseBaseDTO(&e.Warehouse),
|
||||
Product: ToProductRelationDTO(&e.Product),
|
||||
Warehouse: ToWarehouseRelationDTO(&e.Warehouse),
|
||||
}
|
||||
}
|
||||
|
||||
func ToAdjustmentBaseDTO(e *entity.StockLog) AdjustmentBaseDTO {
|
||||
return AdjustmentBaseDTO{
|
||||
func ToAdjustmentRelationDTO(e *entity.StockLog) AdjustmentRelationDTO {
|
||||
return AdjustmentRelationDTO{
|
||||
Id: e.Id,
|
||||
TransactionType: e.TransactionType,
|
||||
Quantity: e.Quantity,
|
||||
@@ -116,9 +116,9 @@ func ToAdjustmentBaseDTO(e *entity.StockLog) AdjustmentBaseDTO {
|
||||
}
|
||||
|
||||
func ToAdjustmentListDTO(e *entity.StockLog) AdjustmentListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser != nil {
|
||||
createdUser = &userDTO.UserBaseDTO{
|
||||
createdUser = &userDTO.UserRelationDTO{
|
||||
Id: e.CreatedUser.Id,
|
||||
IdUser: e.CreatedUser.IdUser,
|
||||
Email: e.CreatedUser.Email,
|
||||
@@ -127,9 +127,9 @@ func ToAdjustmentListDTO(e *entity.StockLog) AdjustmentListDTO {
|
||||
}
|
||||
|
||||
return AdjustmentListDTO{
|
||||
AdjustmentBaseDTO: ToAdjustmentBaseDTO(e),
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: e.CreatedAt,
|
||||
AdjustmentRelationDTO: ToAdjustmentRelationDTO(e),
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: e.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type ProductWarehouseBaseDTO struct {
|
||||
type ProductWarehouseRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
ProductId uint `json:"product_id"`
|
||||
WarehouseId uint `json:"warehouse_id"`
|
||||
@@ -17,21 +17,21 @@ type ProductWarehouseBaseDTO struct {
|
||||
}
|
||||
|
||||
type ProductWarehousNestedDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Product *productDTO.ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
Id uint `json:"id"`
|
||||
Product *productDTO.ProductRelationDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseRelationDTO `json:"warehouse,omitempty"`
|
||||
}
|
||||
|
||||
type ProductWarehouseListDTO struct {
|
||||
ProductWarehouseBaseDTO
|
||||
Product *productDTO.ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
CreatedUser *UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ProductWarehouseRelationDTO
|
||||
Product *productDTO.ProductRelationDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseRelationDTO `json:"warehouse,omitempty"`
|
||||
CreatedUser *UserRelationDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type UserBaseDTO struct {
|
||||
type UserRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
@@ -41,40 +41,40 @@ type ProductWarehouseDetailDTO struct {
|
||||
}
|
||||
|
||||
// Nested DTOs for relations
|
||||
type ProductBaseDTO struct {
|
||||
type ProductRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Sku string `json:"sku"`
|
||||
Flags []string `json:"flags"`
|
||||
}
|
||||
|
||||
type WarehouseBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Kandang *KandangBaseDTO `json:"kandang,omitempty"`
|
||||
Location *LocationBaseDTO `json:"location,omitempty"`
|
||||
Area *AreaBaseDTO `json:"area,omitempty"`
|
||||
type WarehouseRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Kandang *KandangRelationDTO `json:"kandang,omitempty"`
|
||||
Location *LocationRelationDTO `json:"location,omitempty"`
|
||||
Area *AreaRelationDTO `json:"area,omitempty"`
|
||||
}
|
||||
|
||||
type KandangBaseDTO struct {
|
||||
type KandangRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type LocationBaseDTO struct {
|
||||
type LocationRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type AreaBaseDTO struct {
|
||||
type AreaRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToProductWarehouseBaseDTO(e entity.ProductWarehouse) ProductWarehouseBaseDTO {
|
||||
return ProductWarehouseBaseDTO{
|
||||
func ToProductWarehouseRelationDTO(e entity.ProductWarehouse) ProductWarehouseRelationDTO {
|
||||
return ProductWarehouseRelationDTO{
|
||||
Id: e.Id,
|
||||
ProductId: e.ProductId, // Field yang benar dari entity
|
||||
WarehouseId: e.WarehouseId, // Field yang benar dari entity
|
||||
@@ -83,12 +83,12 @@ func ToProductWarehouseBaseDTO(e entity.ProductWarehouse) ProductWarehouseBaseDT
|
||||
}
|
||||
|
||||
func ToProductWarehouseNestedDTO(e entity.ProductWarehouse) ProductWarehousNestedDTO {
|
||||
product := productDTO.ToProductBaseDTO(e.Product)
|
||||
product := productDTO.ToProductRelationDTO(e.Product)
|
||||
|
||||
return ProductWarehousNestedDTO{
|
||||
Id: e.Id,
|
||||
Product: &product,
|
||||
Warehouse: &WarehouseBaseDTO{
|
||||
Warehouse: &WarehouseRelationDTO{
|
||||
Id: e.Warehouse.Id,
|
||||
Name: e.Warehouse.Name,
|
||||
},
|
||||
@@ -97,40 +97,40 @@ func ToProductWarehouseNestedDTO(e entity.ProductWarehouse) ProductWarehousNeste
|
||||
|
||||
func ToProductWarehouseListDTO(e entity.ProductWarehouse) ProductWarehouseListDTO {
|
||||
dto := ProductWarehouseListDTO{
|
||||
ProductWarehouseBaseDTO: ToProductWarehouseBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
ProductWarehouseRelationDTO: ToProductWarehouseRelationDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
}
|
||||
|
||||
// Map Product relation jika ada
|
||||
if e.Product.Id != 0 {
|
||||
product := productDTO.ToProductBaseDTO(e.Product)
|
||||
product := productDTO.ToProductRelationDTO(e.Product)
|
||||
dto.Product = &product
|
||||
}
|
||||
|
||||
// Map Warehouse relation jika ada
|
||||
if e.Warehouse.Id != 0 {
|
||||
warehouse := WarehouseBaseDTO{
|
||||
warehouse := WarehouseRelationDTO{
|
||||
Id: e.Warehouse.Id,
|
||||
Name: e.Warehouse.Name,
|
||||
}
|
||||
// Map Kandang jika ada
|
||||
if e.Warehouse.Kandang != nil && e.Warehouse.Kandang.Id != 0 {
|
||||
warehouse.Kandang = &KandangBaseDTO{
|
||||
warehouse.Kandang = &KandangRelationDTO{
|
||||
Id: e.Warehouse.Kandang.Id,
|
||||
Name: e.Warehouse.Kandang.Name,
|
||||
}
|
||||
}
|
||||
// Map Location jika ada
|
||||
if e.Warehouse.Location != nil && e.Warehouse.Location.Id != 0 {
|
||||
warehouse.Location = &LocationBaseDTO{
|
||||
warehouse.Location = &LocationRelationDTO{
|
||||
Id: e.Warehouse.Location.Id,
|
||||
Name: e.Warehouse.Location.Name,
|
||||
}
|
||||
}
|
||||
|
||||
if e.Warehouse.Area.Id != 0 {
|
||||
warehouse.Area = &AreaBaseDTO{
|
||||
warehouse.Area = &AreaRelationDTO{
|
||||
Id: e.Warehouse.Area.Id,
|
||||
Name: e.Warehouse.Area.Name,
|
||||
}
|
||||
@@ -141,7 +141,7 @@ func ToProductWarehouseListDTO(e entity.ProductWarehouse) ProductWarehouseListDT
|
||||
|
||||
// Map CreatedUser relation jika ada
|
||||
if e.CreatedUser.Id != 0 {
|
||||
user := UserBaseDTO{
|
||||
user := UserRelationDTO{
|
||||
Id: e.CreatedUser.Id,
|
||||
Username: e.CreatedUser.Name,
|
||||
}
|
||||
@@ -165,22 +165,22 @@ func ToProductWarehouseDetailDTO(e entity.ProductWarehouse) ProductWarehouseDeta
|
||||
}
|
||||
}
|
||||
|
||||
func ToKandangBaseDTO(e entity.Kandang) KandangBaseDTO {
|
||||
return KandangBaseDTO{
|
||||
func ToKandangRelationDTO(e entity.Kandang) KandangRelationDTO {
|
||||
return KandangRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToLocationBaseDTO(e entity.Location) LocationBaseDTO {
|
||||
return LocationBaseDTO{
|
||||
func ToLocationRelationDTO(e entity.Location) LocationRelationDTO {
|
||||
return LocationRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToAreaBaseDTO(e entity.Area) AreaBaseDTO {
|
||||
return AreaBaseDTO{
|
||||
func ToAreaRelationDTO(e entity.Area) AreaRelationDTO {
|
||||
return AreaRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type TransferBaseDTO struct {
|
||||
type TransferRelationDTO struct {
|
||||
Id uint64 `json:"id"`
|
||||
TransferReason string `json:"transfer_reason"`
|
||||
TransferDate string `json:"transfer_date"`
|
||||
@@ -51,12 +51,12 @@ type WarehouseDetailDTO struct {
|
||||
}
|
||||
|
||||
type TransferListDTO struct {
|
||||
TransferBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Details []TransferDetailItemDTO `json:"details"`
|
||||
Deliveries []TransferDeliveryDTO `json:"deliveries"`
|
||||
TransferRelationDTO
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Details []TransferDetailItemDTO `json:"details"`
|
||||
Deliveries []TransferDeliveryDTO `json:"deliveries"`
|
||||
}
|
||||
|
||||
type TransferDetailDTO struct {
|
||||
@@ -93,7 +93,7 @@ type TransferDeliveryItemDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToTransferBaseDTO(e entity.StockTransfer) TransferBaseDTO {
|
||||
func ToTransferRelationDTO(e entity.StockTransfer) TransferRelationDTO {
|
||||
|
||||
var sourceWarehouse *WarehouseDetailDTO
|
||||
if e.FromWarehouse != nil && e.FromWarehouse.Id != 0 {
|
||||
@@ -103,7 +103,7 @@ func ToTransferBaseDTO(e entity.StockTransfer) TransferBaseDTO {
|
||||
if e.ToWarehouse != nil && e.ToWarehouse.Id != 0 {
|
||||
destinationWarehouse = toWarehouseDetailDTO(e.ToWarehouse)
|
||||
}
|
||||
return TransferBaseDTO{
|
||||
return TransferRelationDTO{
|
||||
Id: e.Id,
|
||||
TransferReason: e.Reason,
|
||||
TransferDate: e.CreatedAt.Format("2006-01-02"),
|
||||
@@ -145,9 +145,9 @@ func toWarehouseDetailDTO(w *entity.Warehouse) *WarehouseDetailDTO {
|
||||
}
|
||||
|
||||
func ToTransferListDTO(e entity.StockTransfer) TransferListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser != nil {
|
||||
mapped := userDTO.ToUserBaseDTO(*e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(*e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
// Map details
|
||||
@@ -190,12 +190,12 @@ func ToTransferListDTO(e entity.StockTransfer) TransferListDTO {
|
||||
})
|
||||
}
|
||||
return TransferListDTO{
|
||||
TransferBaseDTO: ToTransferBaseDTO(e),
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
Details: details,
|
||||
Deliveries: deliveries,
|
||||
TransferRelationDTO: ToTransferRelationDTO(e),
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
Details: details,
|
||||
Deliveries: deliveries,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
)
|
||||
|
||||
type MarketingBaseDTO struct {
|
||||
type MarketingRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
SoNumber string `json:"so_number"`
|
||||
SoDate time.Time `json:"so_date"`
|
||||
@@ -20,28 +20,28 @@ type MarketingBaseDTO struct {
|
||||
}
|
||||
|
||||
type MarketingListDTO struct {
|
||||
MarketingBaseDTO
|
||||
Customer *customerDTO.CustomerBaseDTO `json:"customer,omitempty"`
|
||||
SalesPerson *userDTO.UserBaseDTO `json:"sales_person,omitempty"`
|
||||
SoDocs string `json:"so_docs,omitempty"`
|
||||
SalesOrder []MarketingProductDTO `json:"sales_order,omitempty"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
LatestApproval *approvalDTO.ApprovalBaseDTO `json:"latest_approval,omitempty"`
|
||||
MarketingRelationDTO
|
||||
Customer *customerDTO.CustomerRelationDTO `json:"customer,omitempty"`
|
||||
SalesPerson *userDTO.UserRelationDTO `json:"sales_person,omitempty"`
|
||||
SoDocs string `json:"so_docs,omitempty"`
|
||||
SalesOrder []MarketingProductDTO `json:"sales_order,omitempty"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
LatestApproval *approvalDTO.ApprovalRelationDTO `json:"latest_approval,omitempty"`
|
||||
}
|
||||
|
||||
type MarketingDetailDTO struct {
|
||||
MarketingBaseDTO
|
||||
Customer *customerDTO.CustomerBaseDTO `json:"customer,omitempty"`
|
||||
SalesPerson *userDTO.UserBaseDTO `json:"sales_person,omitempty"`
|
||||
SoDocs string `json:"so_docs,omitempty"`
|
||||
SalesOrder []MarketingProductDTO `json:"sales_order,omitempty"`
|
||||
DeliveryOrder []DeliveryGroupDTO `json:"delivery_order,omitempty"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
LatestApproval *approvalDTO.ApprovalBaseDTO `json:"latest_approval,omitempty"`
|
||||
MarketingRelationDTO
|
||||
Customer *customerDTO.CustomerRelationDTO `json:"customer,omitempty"`
|
||||
SalesPerson *userDTO.UserRelationDTO `json:"sales_person,omitempty"`
|
||||
SoDocs string `json:"so_docs,omitempty"`
|
||||
SalesOrder []MarketingProductDTO `json:"sales_order,omitempty"`
|
||||
DeliveryOrder []DeliveryGroupDTO `json:"delivery_order,omitempty"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
LatestApproval *approvalDTO.ApprovalRelationDTO `json:"latest_approval,omitempty"`
|
||||
}
|
||||
type MarketingDeliveryProductDTO struct {
|
||||
Id uint `json:"id"`
|
||||
@@ -67,10 +67,10 @@ type DeliveryItemDTO struct {
|
||||
}
|
||||
|
||||
type DeliveryGroupDTO struct {
|
||||
DoNumber string `json:"do_number"`
|
||||
DeliveryDate *time.Time `json:"delivery_date"`
|
||||
Warehouse *productwarehouseDTO.WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
Deliveries []DeliveryItemDTO `json:"deliveries"`
|
||||
DoNumber string `json:"do_number"`
|
||||
DeliveryDate *time.Time `json:"delivery_date"`
|
||||
Warehouse *productwarehouseDTO.WarehouseRelationDTO `json:"warehouse,omitempty"`
|
||||
Deliveries []DeliveryItemDTO `json:"deliveries"`
|
||||
}
|
||||
|
||||
type MarketingProductDTO struct {
|
||||
@@ -86,8 +86,8 @@ type MarketingProductDTO struct {
|
||||
VehicleNumber string `json:"vehicle_number,omitempty"`
|
||||
}
|
||||
|
||||
func ToMarketingBaseDTO(marketing *entity.Marketing) MarketingBaseDTO {
|
||||
return MarketingBaseDTO{
|
||||
func ToMarketingRelationDTO(marketing *entity.Marketing) MarketingRelationDTO {
|
||||
return MarketingRelationDTO{
|
||||
Id: marketing.Id,
|
||||
SoNumber: marketing.SoNumber,
|
||||
SoDate: marketing.SoDate,
|
||||
@@ -131,25 +131,25 @@ func ToMarketingDeliveryProductDTO(e entity.MarketingDeliveryProduct) MarketingD
|
||||
}
|
||||
|
||||
func ToMarketingListDTO(marketing *entity.Marketing, deliveryProducts []entity.MarketingDeliveryProduct) MarketingListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if marketing.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(marketing.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(marketing.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
var customer *customerDTO.CustomerBaseDTO
|
||||
var customer *customerDTO.CustomerRelationDTO
|
||||
if marketing.Customer.Id != 0 {
|
||||
mapped := customerDTO.ToCustomerBaseDTO(marketing.Customer)
|
||||
mapped := customerDTO.ToCustomerRelationDTO(marketing.Customer)
|
||||
customer = &mapped
|
||||
}
|
||||
|
||||
var salesPerson *userDTO.UserBaseDTO
|
||||
var salesPerson *userDTO.UserRelationDTO
|
||||
if marketing.SalesPerson.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(marketing.SalesPerson)
|
||||
mapped := userDTO.ToUserRelationDTO(marketing.SalesPerson)
|
||||
salesPerson = &mapped
|
||||
}
|
||||
|
||||
var latestApproval *approvalDTO.ApprovalBaseDTO
|
||||
var latestApproval *approvalDTO.ApprovalRelationDTO
|
||||
if marketing.LatestApproval != nil {
|
||||
mapped := approvalDTO.ToApprovalDTO(*marketing.LatestApproval)
|
||||
latestApproval = &mapped
|
||||
@@ -164,34 +164,34 @@ func ToMarketingListDTO(marketing *entity.Marketing, deliveryProducts []entity.M
|
||||
}
|
||||
|
||||
return MarketingListDTO{
|
||||
MarketingBaseDTO: ToMarketingBaseDTO(marketing),
|
||||
Customer: customer,
|
||||
SalesPerson: salesPerson,
|
||||
SoDocs: marketing.SoDocs,
|
||||
SalesOrder: salesOrderProducts,
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: marketing.CreatedAt,
|
||||
UpdatedAt: marketing.UpdatedAt,
|
||||
LatestApproval: latestApproval,
|
||||
MarketingRelationDTO: ToMarketingRelationDTO(marketing),
|
||||
Customer: customer,
|
||||
SalesPerson: salesPerson,
|
||||
SoDocs: marketing.SoDocs,
|
||||
SalesOrder: salesOrderProducts,
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: marketing.CreatedAt,
|
||||
UpdatedAt: marketing.UpdatedAt,
|
||||
LatestApproval: latestApproval,
|
||||
}
|
||||
}
|
||||
|
||||
func ToMarketingDetailDTO(marketing *entity.Marketing, deliveryProducts []entity.MarketingDeliveryProduct) MarketingDetailDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if marketing.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(marketing.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(marketing.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
var customer *customerDTO.CustomerBaseDTO
|
||||
var customer *customerDTO.CustomerRelationDTO
|
||||
if marketing.Customer.Id != 0 {
|
||||
mapped := customerDTO.ToCustomerBaseDTO(marketing.Customer)
|
||||
mapped := customerDTO.ToCustomerRelationDTO(marketing.Customer)
|
||||
customer = &mapped
|
||||
}
|
||||
|
||||
var salesPerson *userDTO.UserBaseDTO
|
||||
var salesPerson *userDTO.UserRelationDTO
|
||||
if marketing.SalesPerson.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(marketing.SalesPerson)
|
||||
mapped := userDTO.ToUserRelationDTO(marketing.SalesPerson)
|
||||
salesPerson = &mapped
|
||||
}
|
||||
|
||||
@@ -214,23 +214,23 @@ func ToMarketingDetailDTO(marketing *entity.Marketing, deliveryProducts []entity
|
||||
|
||||
deliveryGroups := groupDeliveryProducts(deliveryProductsDTOs, marketing.SoNumber)
|
||||
|
||||
var latestApproval *approvalDTO.ApprovalBaseDTO
|
||||
var latestApproval *approvalDTO.ApprovalRelationDTO
|
||||
if marketing.LatestApproval != nil {
|
||||
mapped := approvalDTO.ToApprovalDTO(*marketing.LatestApproval)
|
||||
latestApproval = &mapped
|
||||
}
|
||||
|
||||
return MarketingDetailDTO{
|
||||
MarketingBaseDTO: ToMarketingBaseDTO(marketing),
|
||||
SoDocs: marketing.SoDocs,
|
||||
Customer: customer,
|
||||
SalesPerson: salesPerson,
|
||||
SalesOrder: salesOrderProducts,
|
||||
DeliveryOrder: deliveryGroups,
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: marketing.CreatedAt,
|
||||
UpdatedAt: marketing.UpdatedAt,
|
||||
LatestApproval: latestApproval,
|
||||
MarketingRelationDTO: ToMarketingRelationDTO(marketing),
|
||||
SoDocs: marketing.SoDocs,
|
||||
Customer: customer,
|
||||
SalesPerson: salesPerson,
|
||||
SalesOrder: salesOrderProducts,
|
||||
DeliveryOrder: deliveryGroups,
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: marketing.CreatedAt,
|
||||
UpdatedAt: marketing.UpdatedAt,
|
||||
LatestApproval: latestApproval,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ func groupDeliveryProducts(products []MarketingDeliveryProductDTO, soNumber stri
|
||||
if !exists {
|
||||
group = &DeliveryGroupDTO{
|
||||
DeliveryDate: product.DeliveryDate,
|
||||
Warehouse: &productwarehouseDTO.WarehouseBaseDTO{
|
||||
Warehouse: &productwarehouseDTO.WarehouseRelationDTO{
|
||||
Id: warehouseId,
|
||||
Name: warehouseName,
|
||||
},
|
||||
|
||||
@@ -9,16 +9,16 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type AreaBaseDTO struct {
|
||||
type AreaRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type AreaListDTO struct {
|
||||
AreaBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
AreaRelationDTO
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type AreaDetailDTO struct {
|
||||
@@ -27,25 +27,25 @@ type AreaDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToAreaBaseDTO(e entity.Area) AreaBaseDTO {
|
||||
return AreaBaseDTO{
|
||||
func ToAreaRelationDTO(e entity.Area) AreaRelationDTO {
|
||||
return AreaRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToAreaListDTO(e entity.Area) AreaListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return AreaListDTO{
|
||||
AreaBaseDTO: ToAreaBaseDTO(e),
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
AreaRelationDTO: ToAreaRelationDTO(e),
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type BankBaseDTO struct {
|
||||
type BankRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Alias string `json:"alias"`
|
||||
@@ -18,10 +18,10 @@ type BankBaseDTO struct {
|
||||
}
|
||||
|
||||
type BankListDTO struct {
|
||||
BankBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
BankRelationDTO
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type BankDetailDTO struct {
|
||||
@@ -30,8 +30,8 @@ type BankDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToBankBaseDTO(e entity.Bank) BankBaseDTO {
|
||||
return BankBaseDTO{
|
||||
func ToBankRelationDTO(e entity.Bank) BankRelationDTO {
|
||||
return BankRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Alias: e.Alias,
|
||||
@@ -41,17 +41,17 @@ func ToBankBaseDTO(e entity.Bank) BankBaseDTO {
|
||||
}
|
||||
|
||||
func ToBankListDTO(e entity.Bank) BankListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return BankListDTO{
|
||||
BankBaseDTO: ToBankBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
BankRelationDTO: ToBankRelationDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type CustomerBaseDTO struct {
|
||||
type CustomerRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
PicId uint `json:"pic_id"`
|
||||
@@ -20,14 +20,14 @@ type CustomerBaseDTO struct {
|
||||
AccountNumber string `json:"account_number"`
|
||||
Balance float64 `json:"balance"`
|
||||
|
||||
Pic *userDTO.UserBaseDTO `json:"pic,omitempty"`
|
||||
Pic *userDTO.UserRelationDTO `json:"pic,omitempty"`
|
||||
}
|
||||
|
||||
type CustomerListDTO struct {
|
||||
CustomerBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
CustomerRelationDTO
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type CustomerDetailDTO struct {
|
||||
@@ -36,14 +36,14 @@ type CustomerDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToCustomerBaseDTO(e entity.Customer) CustomerBaseDTO {
|
||||
var pic *userDTO.UserBaseDTO
|
||||
func ToCustomerRelationDTO(e entity.Customer) CustomerRelationDTO {
|
||||
var pic *userDTO.UserRelationDTO
|
||||
if e.Pic.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.Pic)
|
||||
mapped := userDTO.ToUserRelationDTO(e.Pic)
|
||||
pic = &mapped
|
||||
}
|
||||
|
||||
return CustomerBaseDTO{
|
||||
return CustomerRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
PicId: e.PicId,
|
||||
@@ -57,17 +57,17 @@ func ToCustomerBaseDTO(e entity.Customer) CustomerBaseDTO {
|
||||
}
|
||||
|
||||
func ToCustomerListDTO(e entity.Customer) CustomerListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return CustomerListDTO{
|
||||
CustomerBaseDTO: ToCustomerBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
CustomerRelationDTO: ToCustomerRelationDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type FcrBaseDTO struct {
|
||||
type FcrRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
@@ -22,10 +22,10 @@ type FcrStandardDTO struct {
|
||||
}
|
||||
|
||||
type FcrListDTO struct {
|
||||
FcrBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
FcrRelationDTO
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type FcrDetailDTO struct {
|
||||
@@ -35,25 +35,25 @@ type FcrDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToFcrBaseDTO(e entity.Fcr) FcrBaseDTO {
|
||||
return FcrBaseDTO{
|
||||
func ToFcrRelationDTO(e entity.Fcr) FcrRelationDTO {
|
||||
return FcrRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToFcrListDTO(e entity.Fcr) FcrListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return FcrListDTO{
|
||||
FcrBaseDTO: ToFcrBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
FcrRelationDTO: ToFcrRelationDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,16 +9,16 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type FlockBaseDTO struct {
|
||||
type FlockRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type FlockListDTO struct {
|
||||
FlockBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
FlockRelationDTO
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type FlockDetailDTO struct {
|
||||
@@ -27,25 +27,25 @@ type FlockDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToFlockBaseDTO(e entity.Flock) FlockBaseDTO {
|
||||
return FlockBaseDTO{
|
||||
func ToFlockRelationDTO(e entity.Flock) FlockRelationDTO {
|
||||
return FlockRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToFlockListDTO(e entity.Flock) FlockListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return FlockListDTO{
|
||||
FlockBaseDTO: ToFlockBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
FlockRelationDTO: ToFlockRelationDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,25 +10,25 @@ import (
|
||||
|
||||
// === 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 KandangRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Capacity float64 `json:"capacity"`
|
||||
Location locationDTO.LocationRelationDTO `json:"location,omitempty"`
|
||||
Pic userDTO.UserRelationDTO `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"`
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Capacity float64 `json:"capacity"`
|
||||
Location locationDTO.LocationRelationDTO `json:"location"`
|
||||
Pic userDTO.UserRelationDTO `json:"pic"`
|
||||
CreatedUser userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type KandangDetailDTO struct {
|
||||
@@ -37,20 +37,20 @@ type KandangDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToKandangBaseDTO(e entity.Kandang) KandangBaseDTO {
|
||||
var location locationDTO.LocationBaseDTO
|
||||
func ToKandangRelationDTO(e entity.Kandang) KandangRelationDTO {
|
||||
var location locationDTO.LocationRelationDTO
|
||||
if e.Location.Id != 0 {
|
||||
mapped := locationDTO.ToLocationBaseDTO(e.Location)
|
||||
mapped := locationDTO.ToLocationRelationDTO(e.Location)
|
||||
location = mapped
|
||||
}
|
||||
|
||||
var pic userDTO.UserBaseDTO
|
||||
var pic userDTO.UserRelationDTO
|
||||
if e.Pic.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.Pic)
|
||||
mapped := userDTO.ToUserRelationDTO(e.Pic)
|
||||
pic = mapped
|
||||
}
|
||||
|
||||
return KandangBaseDTO{
|
||||
return KandangRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Status: e.Status,
|
||||
@@ -61,21 +61,21 @@ func ToKandangBaseDTO(e entity.Kandang) KandangBaseDTO {
|
||||
}
|
||||
|
||||
func ToKandangListDTO(e entity.Kandang) KandangListDTO {
|
||||
var location locationDTO.LocationBaseDTO
|
||||
var location locationDTO.LocationRelationDTO
|
||||
if e.Location.Id != 0 {
|
||||
mapped := locationDTO.ToLocationBaseDTO(e.Location)
|
||||
mapped := locationDTO.ToLocationRelationDTO(e.Location)
|
||||
location = mapped
|
||||
}
|
||||
|
||||
var pic userDTO.UserBaseDTO
|
||||
var pic userDTO.UserRelationDTO
|
||||
if e.Pic.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.Pic)
|
||||
mapped := userDTO.ToUserRelationDTO(e.Pic)
|
||||
pic = mapped
|
||||
}
|
||||
|
||||
var createdUser userDTO.UserBaseDTO
|
||||
var createdUser userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = mapped
|
||||
}
|
||||
|
||||
|
||||
@@ -10,21 +10,21 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type LocationBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Area *areaDTO.AreaBaseDTO `json:"area,omitempty"`
|
||||
type LocationRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Area *areaDTO.AreaRelationDTO `json:"area,omitempty"`
|
||||
}
|
||||
|
||||
type LocationListDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Area *areaDTO.AreaBaseDTO `json:"area"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Area *areaDTO.AreaRelationDTO `json:"area"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type LocationDetailDTO struct {
|
||||
@@ -33,14 +33,14 @@ type LocationDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToLocationBaseDTO(e entity.Location) LocationBaseDTO {
|
||||
var area *areaDTO.AreaBaseDTO
|
||||
func ToLocationRelationDTO(e entity.Location) LocationRelationDTO {
|
||||
var area *areaDTO.AreaRelationDTO
|
||||
if e.Area.Id != 0 {
|
||||
mapped := areaDTO.ToAreaBaseDTO(e.Area)
|
||||
mapped := areaDTO.ToAreaRelationDTO(e.Area)
|
||||
area = &mapped
|
||||
}
|
||||
|
||||
return LocationBaseDTO{
|
||||
return LocationRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Address: e.Address,
|
||||
@@ -49,15 +49,15 @@ func ToLocationBaseDTO(e entity.Location) LocationBaseDTO {
|
||||
}
|
||||
|
||||
func ToLocationListDTO(e entity.Location) LocationListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
var area *areaDTO.AreaBaseDTO
|
||||
var area *areaDTO.AreaRelationDTO
|
||||
if e.Area.Id != 0 {
|
||||
mapped := areaDTO.ToAreaBaseDTO(e.Area)
|
||||
mapped := areaDTO.ToAreaRelationDTO(e.Area)
|
||||
area = &mapped
|
||||
}
|
||||
|
||||
|
||||
@@ -4,41 +4,39 @@ import (
|
||||
"time"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
supplierDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/dto"
|
||||
uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto"
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type NonstockBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Uom *uomDTO.UomBaseDTO `json:"uom,omitempty"`
|
||||
Flags []string `json:"flags"`
|
||||
type NonstockRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
|
||||
Flags []string `json:"flags"`
|
||||
}
|
||||
|
||||
type NonstockListDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Uom *uomDTO.UomBaseDTO `json:"uom"`
|
||||
Suppliers []supplierDTO.SupplierBaseDTO `json:"suppliers"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Flags []string `json:"flags"`
|
||||
Uom *uomDTO.UomRelationDTO `json:"uom"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type NonstockDetailDTO struct {
|
||||
NonstockListDTO
|
||||
Flags []string `json:"flags"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToNonstockBaseDTO(e entity.Nonstock) NonstockBaseDTO {
|
||||
var uomRef *uomDTO.UomBaseDTO
|
||||
func ToNonstockRelationDTO(e entity.Nonstock) NonstockRelationDTO {
|
||||
var uomRef *uomDTO.UomRelationDTO
|
||||
if e.Uom.Id != 0 {
|
||||
mapped := uomDTO.ToUomBaseDTO(e.Uom)
|
||||
mapped := uomDTO.ToUomRelationDTO(e.Uom)
|
||||
uomRef = &mapped
|
||||
}
|
||||
|
||||
@@ -47,7 +45,7 @@ func ToNonstockBaseDTO(e entity.Nonstock) NonstockBaseDTO {
|
||||
flags[i] = f.Name
|
||||
}
|
||||
|
||||
return NonstockBaseDTO{
|
||||
return NonstockRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Uom: uomRef,
|
||||
@@ -56,23 +54,18 @@ func ToNonstockBaseDTO(e entity.Nonstock) NonstockBaseDTO {
|
||||
}
|
||||
|
||||
func ToNonstockListDTO(e entity.Nonstock) NonstockListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
var uomRef *uomDTO.UomBaseDTO
|
||||
var uomRef *uomDTO.UomRelationDTO
|
||||
if e.Uom.Id != 0 {
|
||||
mapped := uomDTO.ToUomBaseDTO(e.Uom)
|
||||
mapped := uomDTO.ToUomRelationDTO(e.Uom)
|
||||
uomRef = &mapped
|
||||
}
|
||||
|
||||
suppliers := make([]supplierDTO.SupplierBaseDTO, len(e.Suppliers))
|
||||
for i, s := range e.Suppliers {
|
||||
suppliers[i] = supplierDTO.ToSupplierBaseDTO(s)
|
||||
}
|
||||
|
||||
flags := make([]string, len(e.Flags))
|
||||
for i, f := range e.Flags {
|
||||
flags[i] = f.Name
|
||||
@@ -81,11 +74,11 @@ func ToNonstockListDTO(e entity.Nonstock) NonstockListDTO {
|
||||
return NonstockListDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Flags: flags,
|
||||
Uom: uomRef,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
Suppliers: suppliers,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,13 +91,7 @@ func ToNonstockListDTOs(e []entity.Nonstock) []NonstockListDTO {
|
||||
}
|
||||
|
||||
func ToNonstockDetailDTO(e entity.Nonstock) NonstockDetailDTO {
|
||||
flags := make([]string, len(e.Flags))
|
||||
for i, f := range e.Flags {
|
||||
flags[i] = f.Name
|
||||
}
|
||||
|
||||
return NonstockDetailDTO{
|
||||
NonstockListDTO: ToNonstockListDTO(e),
|
||||
Flags: flags,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (r *NonstockRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm
|
||||
|
||||
existingMap := make(map[uint]struct{}, len(existing))
|
||||
for _, rel := range existing {
|
||||
existingMap[rel.SupplierID] = struct{}{}
|
||||
existingMap[rel.SupplierId] = struct{}{}
|
||||
}
|
||||
|
||||
incomingMap := make(map[uint]struct{}, len(supplierIDs))
|
||||
@@ -66,16 +66,16 @@ func (r *NonstockRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm
|
||||
if _, exists := existingMap[id]; exists {
|
||||
continue
|
||||
}
|
||||
record := entity.NonstockSupplier{NonstockID: nonstockID, SupplierID: id}
|
||||
record := entity.NonstockSupplier{NonstockId: nonstockID, SupplierId: id}
|
||||
if err := db.WithContext(ctx).Create(&record).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, rel := range existing {
|
||||
if _, keep := incomingMap[rel.SupplierID]; !keep {
|
||||
if _, keep := incomingMap[rel.SupplierId]; !keep {
|
||||
if err := db.WithContext(ctx).
|
||||
Where("nonstock_id = ? AND supplier_id = ?", nonstockID, rel.SupplierID).
|
||||
Where("nonstock_id = ? AND supplier_id = ?", nonstockID, rel.SupplierId).
|
||||
Delete(&entity.NonstockSupplier{}).
|
||||
Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
|
||||
@@ -44,7 +44,8 @@ func (s nonstockService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
Preload("CreatedUser").
|
||||
Preload("Uom").
|
||||
Preload("Flags").
|
||||
Preload("Suppliers", func(db *gorm.DB) *gorm.DB {
|
||||
Preload("NonstockSuppliers").
|
||||
Preload("NonstockSuppliers.Supplier", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("suppliers.name ASC")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,17 +9,17 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type ProductCategoryBaseDTO struct {
|
||||
type ProductCategoryRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type ProductCategoryListDTO struct {
|
||||
ProductCategoryBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ProductCategoryRelationDTO
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type ProductCategoryDetailDTO struct {
|
||||
@@ -28,8 +28,8 @@ type ProductCategoryDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToProductCategoryBaseDTO(e entity.ProductCategory) ProductCategoryBaseDTO {
|
||||
return ProductCategoryBaseDTO{
|
||||
func ToProductCategoryRelationDTO(e entity.ProductCategory) ProductCategoryRelationDTO {
|
||||
return ProductCategoryRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Code: e.Code,
|
||||
@@ -37,17 +37,17 @@ func ToProductCategoryBaseDTO(e entity.ProductCategory) ProductCategoryBaseDTO {
|
||||
}
|
||||
|
||||
func ToProductCategoryListDTO(e entity.ProductCategory) ProductCategoryListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return ProductCategoryListDTO{
|
||||
ProductCategoryBaseDTO: ToProductCategoryBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
ProductCategoryRelationDTO: ToProductCategoryRelationDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,55 +5,57 @@ import (
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
productCategoryDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/product-categories/dto"
|
||||
supplierDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/dto"
|
||||
uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto"
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type ProductBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Uom *uomDTO.UomBaseDTO `json:"uom,omitempty"`
|
||||
Flags []string `json:"flags"`
|
||||
type ProductRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ProductPrice float64 `gorm:"type:numeric(15,3);not null"`
|
||||
SellingPrice *float64 `gorm:"type:numeric(15,3)"`
|
||||
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
|
||||
Flags []string `json:"flags"`
|
||||
}
|
||||
|
||||
type ProductListDTO struct {
|
||||
ProductBaseDTO
|
||||
Brand string `json:"brand"`
|
||||
Sku *string `json:"sku,omitempty"`
|
||||
ProductPrice float64 `json:"product_price"`
|
||||
SellingPrice *float64 `json:"selling_price,omitempty"`
|
||||
Tax *float64 `json:"tax,omitempty"`
|
||||
ExpiryPeriod *int `json:"expiry_period,omitempty"`
|
||||
ProductCategory *productCategoryDTO.ProductCategoryBaseDTO `json:"product_category,omitempty"`
|
||||
Suppliers []supplierDTO.SupplierBaseDTO `json:"suppliers"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Brand string `json:"brand"`
|
||||
Sku *string `json:"sku,omitempty"`
|
||||
ProductPrice float64 `json:"product_price"`
|
||||
SellingPrice *float64 `json:"selling_price,omitempty"`
|
||||
Tax *float64 `json:"tax,omitempty"`
|
||||
ExpiryPeriod *int `json:"expiry_period,omitempty"`
|
||||
Flags []string `json:"flags"`
|
||||
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
|
||||
ProductCategory *productCategoryDTO.ProductCategoryRelationDTO `json:"product_category,omitempty"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type ProductDetailDTO struct {
|
||||
ProductListDTO
|
||||
Flags []string `json:"flags"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToProductBaseDTO(e entity.Product) ProductBaseDTO {
|
||||
func ToProductRelationDTO(e entity.Product) ProductRelationDTO {
|
||||
flags := make([]string, len(e.Flags))
|
||||
for i, f := range e.Flags {
|
||||
flags[i] = f.Name
|
||||
}
|
||||
|
||||
var uomRef *uomDTO.UomBaseDTO
|
||||
var uomRef *uomDTO.UomRelationDTO
|
||||
if e.Uom.Id != 0 {
|
||||
mapped := uomDTO.ToUomBaseDTO(e.Uom)
|
||||
mapped := uomDTO.ToUomRelationDTO(e.Uom)
|
||||
uomRef = &mapped
|
||||
}
|
||||
|
||||
return ProductBaseDTO{
|
||||
return ProductRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Flags: flags,
|
||||
@@ -62,36 +64,44 @@ func ToProductBaseDTO(e entity.Product) ProductBaseDTO {
|
||||
}
|
||||
|
||||
func ToProductListDTO(e entity.Product) ProductListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
var categoryRef *productCategoryDTO.ProductCategoryBaseDTO
|
||||
var categoryRef *productCategoryDTO.ProductCategoryRelationDTO
|
||||
if e.ProductCategory.Id != 0 {
|
||||
mapped := productCategoryDTO.ToProductCategoryBaseDTO(e.ProductCategory)
|
||||
mapped := productCategoryDTO.ToProductCategoryRelationDTO(e.ProductCategory)
|
||||
categoryRef = &mapped
|
||||
}
|
||||
|
||||
suppliers := make([]supplierDTO.SupplierBaseDTO, len(e.Suppliers))
|
||||
for i, s := range e.Suppliers {
|
||||
suppliers[i] = supplierDTO.ToSupplierBaseDTO(s)
|
||||
flags := make([]string, len(e.Flags))
|
||||
for i, f := range e.Flags {
|
||||
flags[i] = f.Name
|
||||
}
|
||||
|
||||
var uomRef *uomDTO.UomRelationDTO
|
||||
if e.Uom.Id != 0 {
|
||||
mapped := uomDTO.ToUomRelationDTO(e.Uom)
|
||||
uomRef = &mapped
|
||||
}
|
||||
|
||||
return ProductListDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Flags: flags,
|
||||
Uom: uomRef,
|
||||
Brand: e.Brand,
|
||||
Sku: e.Sku,
|
||||
ProductPrice: e.ProductPrice,
|
||||
SellingPrice: e.SellingPrice,
|
||||
Tax: e.Tax,
|
||||
ExpiryPeriod: e.ExpiryPeriod,
|
||||
ProductBaseDTO: ToProductBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
ProductCategory: categoryRef,
|
||||
Suppliers: suppliers,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,13 +114,7 @@ func ToProductListDTOs(e []entity.Product) []ProductListDTO {
|
||||
}
|
||||
|
||||
func ToProductDetailDTO(e entity.Product) ProductDetailDTO {
|
||||
flags := make([]string, len(e.Flags))
|
||||
for i, f := range e.Flags {
|
||||
flags[i] = f.Name
|
||||
}
|
||||
|
||||
return ProductDetailDTO{
|
||||
ProductListDTO: ToProductListDTO(e),
|
||||
Flags: flags,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,13 +102,13 @@ func (r *ProductRepositoryImpl) IsLinkedToSupplier(ctx context.Context, productI
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (r *ProductRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm.DB, productID uint, supplierIDs []uint) error {
|
||||
func (r *ProductRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm.DB, productID uint, supplierIds []uint) error {
|
||||
db := tx
|
||||
if db == nil {
|
||||
db = r.DB()
|
||||
}
|
||||
|
||||
if supplierIDs == nil {
|
||||
if supplierIds == nil {
|
||||
return db.WithContext(ctx).
|
||||
Where("product_id = ?", productID).
|
||||
Delete(&entity.ProductSupplier{}).
|
||||
@@ -125,25 +125,25 @@ func (r *ProductRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm.
|
||||
|
||||
existingMap := make(map[uint]struct{}, len(existing))
|
||||
for _, rel := range existing {
|
||||
existingMap[rel.SupplierID] = struct{}{}
|
||||
existingMap[rel.SupplierId] = struct{}{}
|
||||
}
|
||||
|
||||
incomingMap := make(map[uint]struct{}, len(supplierIDs))
|
||||
for _, id := range supplierIDs {
|
||||
incomingMap := make(map[uint]struct{}, len(supplierIds))
|
||||
for _, id := range supplierIds {
|
||||
incomingMap[id] = struct{}{}
|
||||
if _, exists := existingMap[id]; exists {
|
||||
continue
|
||||
}
|
||||
record := entity.ProductSupplier{ProductID: productID, SupplierID: id}
|
||||
record := entity.ProductSupplier{ProductId: productID, SupplierId: id}
|
||||
if err := db.WithContext(ctx).Create(&record).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, rel := range existing {
|
||||
if _, keep := incomingMap[rel.SupplierID]; !keep {
|
||||
if _, keep := incomingMap[rel.SupplierId]; !keep {
|
||||
if err := db.WithContext(ctx).
|
||||
Where("product_id = ? AND supplier_id = ?", productID, rel.SupplierID).
|
||||
Where("product_id = ? AND supplier_id = ?", productID, rel.SupplierId).
|
||||
Delete(&entity.ProductSupplier{}).
|
||||
Error; err != nil {
|
||||
return err
|
||||
|
||||
@@ -55,7 +55,8 @@ func (s productService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
Preload("Uom").
|
||||
Preload("ProductCategory").
|
||||
Preload("Flags").
|
||||
Preload("Suppliers", func(db *gorm.DB) *gorm.DB {
|
||||
Preload("ProductSuppliers").
|
||||
Preload("ProductSuppliers.Supplier", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("suppliers.name ASC")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -24,9 +24,10 @@ func NewSupplierController(supplierService service.SupplierService) *SupplierCon
|
||||
|
||||
func (u *SupplierController) GetAll(c *fiber.Ctx) error {
|
||||
query := &validation.Query{
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
Page: c.QueryInt("page", 1),
|
||||
Limit: c.QueryInt("limit", 10),
|
||||
Search: c.Query("search", ""),
|
||||
Category: c.Query("category", ""),
|
||||
}
|
||||
|
||||
if query.Page < 1 || query.Limit < 1 {
|
||||
@@ -71,7 +72,7 @@ func (u *SupplierController) GetOne(c *fiber.Ctx) error {
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get supplier successfully",
|
||||
Data: dto.ToSupplierListDTO(*result),
|
||||
Data: dto.ToSupplierDetailDTO(*result),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type SupplierBaseDTO struct {
|
||||
type SupplierRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Alias string `json:"alias"`
|
||||
@@ -17,30 +17,32 @@ type SupplierBaseDTO struct {
|
||||
}
|
||||
|
||||
type SupplierListDTO struct {
|
||||
SupplierBaseDTO
|
||||
Pic string `json:"pic"`
|
||||
Type string `json:"type"`
|
||||
Hatchery *string `json:"hatchery,omitempty"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
Address string `json:"address"`
|
||||
Npwp *string `json:"npwp,omitempty"`
|
||||
AccountNumber *string `json:"account_number,omitempty"`
|
||||
Balance float64 `json:"balance"`
|
||||
DueDate int `json:"due_date"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
SupplierRelationDTO
|
||||
Pic string `json:"pic"`
|
||||
Type string `json:"type"`
|
||||
Hatchery *string `json:"hatchery,omitempty"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
Address string `json:"address"`
|
||||
Npwp *string `json:"npwp,omitempty"`
|
||||
AccountNumber *string `json:"account_number,omitempty"`
|
||||
Balance float64 `json:"balance"`
|
||||
DueDate int `json:"due_date"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type SupplierDetailDTO struct {
|
||||
SupplierListDTO
|
||||
Products []SupplierProductDTO `json:"products"`
|
||||
Nonstocks []SupplierNonstockDTO `json:"nonstocks"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToSupplierBaseDTO(e entity.Supplier) SupplierBaseDTO {
|
||||
return SupplierBaseDTO{
|
||||
func ToSupplierRelationDTO(e entity.Supplier) SupplierRelationDTO {
|
||||
return SupplierRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Alias: e.Alias,
|
||||
@@ -49,27 +51,27 @@ func ToSupplierBaseDTO(e entity.Supplier) SupplierBaseDTO {
|
||||
}
|
||||
|
||||
func ToSupplierListDTO(e entity.Supplier) SupplierListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return SupplierListDTO{
|
||||
Pic: e.Pic,
|
||||
Type: e.Type,
|
||||
Hatchery: e.Hatchery,
|
||||
Phone: e.Phone,
|
||||
Email: e.Email,
|
||||
Address: e.Address,
|
||||
Npwp: e.Npwp,
|
||||
AccountNumber: e.AccountNumber,
|
||||
Balance: e.Balance,
|
||||
DueDate: e.DueDate,
|
||||
SupplierBaseDTO: ToSupplierBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
Pic: e.Pic,
|
||||
Type: e.Type,
|
||||
Hatchery: e.Hatchery,
|
||||
Phone: e.Phone,
|
||||
Email: e.Email,
|
||||
Address: e.Address,
|
||||
Npwp: e.Npwp,
|
||||
AccountNumber: e.AccountNumber,
|
||||
Balance: e.Balance,
|
||||
DueDate: e.DueDate,
|
||||
SupplierRelationDTO: ToSupplierRelationDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,5 +86,7 @@ func ToSupplierListDTOs(e []entity.Supplier) []SupplierListDTO {
|
||||
func ToSupplierDetailDTO(e entity.Supplier) SupplierDetailDTO {
|
||||
return SupplierDetailDTO{
|
||||
SupplierListDTO: ToSupplierListDTO(e),
|
||||
Products: toSupplierProductDTOs(e.ProductSuppliers),
|
||||
Nonstocks: toSupplierNonstockDTOs(e.NonstockSuppliers),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type SupplierNonstockDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
|
||||
Flags []string `json:"flags"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func toSupplierNonstockDTOs(relations []entity.NonstockSupplier) []SupplierNonstockDTO {
|
||||
if len(relations) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]SupplierNonstockDTO, 0, len(relations))
|
||||
for _, relation := range relations {
|
||||
Nonstock := relation.Nonstock
|
||||
if Nonstock.Id == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
flags := make([]string, len(Nonstock.Flags))
|
||||
for i, f := range Nonstock.Flags {
|
||||
flags[i] = f.Name
|
||||
}
|
||||
|
||||
var uomRef *uomDTO.UomRelationDTO
|
||||
if Nonstock.Uom.Id != 0 {
|
||||
mapped := uomDTO.ToUomRelationDTO(Nonstock.Uom)
|
||||
uomRef = &mapped
|
||||
}
|
||||
|
||||
result = append(result, SupplierNonstockDTO{
|
||||
Id: Nonstock.Id,
|
||||
Name: Nonstock.Name,
|
||||
Uom: uomRef,
|
||||
Flags: flags,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type SupplierProductDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ProductPrice float64 `gorm:"type:numeric(15,3);not null"`
|
||||
SellingPrice *float64 `gorm:"type:numeric(15,3)"`
|
||||
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
|
||||
Flags []string `json:"flags"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func toSupplierProductDTOs(relations []entity.ProductSupplier) []SupplierProductDTO {
|
||||
if len(relations) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]SupplierProductDTO, 0, len(relations))
|
||||
for _, relation := range relations {
|
||||
product := relation.Product
|
||||
if product.Id == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
flags := make([]string, len(product.Flags))
|
||||
for i, f := range product.Flags {
|
||||
flags[i] = f.Name
|
||||
}
|
||||
|
||||
var uomRef *uomDTO.UomRelationDTO
|
||||
if product.Uom.Id != 0 {
|
||||
mapped := uomDTO.ToUomRelationDTO(product.Uom)
|
||||
uomRef = &mapped
|
||||
}
|
||||
|
||||
result = append(result, SupplierProductDTO{
|
||||
Id: product.Id,
|
||||
Name: product.Name,
|
||||
ProductPrice: product.ProductPrice,
|
||||
SellingPrice: product.SellingPrice,
|
||||
Uom: uomRef,
|
||||
Flags: flags,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package suppliers
|
||||
|
||||
import (
|
||||
m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
// m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
controller "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/controllers"
|
||||
supplier "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/services"
|
||||
user "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services"
|
||||
@@ -13,7 +13,7 @@ func SupplierRoutes(v1 fiber.Router, u user.UserService, s supplier.SupplierServ
|
||||
ctrl := controller.NewSupplierController(s)
|
||||
|
||||
route := v1.Group("/suppliers")
|
||||
route.Use(m.Auth(u))
|
||||
// route.Use(m.Auth(u))
|
||||
|
||||
route.Get("/", ctrl.GetAll)
|
||||
route.Post("/", ctrl.CreateOne)
|
||||
|
||||
@@ -39,7 +39,12 @@ func NewSupplierService(repo repository.SupplierRepository, validate *validator.
|
||||
}
|
||||
|
||||
func (s supplierService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
return db.Preload("CreatedUser")
|
||||
return db.
|
||||
Preload("CreatedUser").
|
||||
Preload("ProductSuppliers.Product.Uom").
|
||||
Preload("ProductSuppliers.Product.Flags").
|
||||
Preload("NonstockSuppliers.Nonstock.Uom").
|
||||
Preload("NonstockSuppliers.Nonstock.Flags")
|
||||
}
|
||||
|
||||
func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.Supplier, int64, error) {
|
||||
@@ -47,6 +52,14 @@ func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if params.Category != "" {
|
||||
category := strings.ToUpper(params.Category)
|
||||
if category != "BOP" && category != "SAPRONAK" {
|
||||
return nil, 0, fiber.NewError(fiber.StatusBadRequest, "Invalid supplier category")
|
||||
}
|
||||
params.Category = category
|
||||
}
|
||||
|
||||
offset := (params.Page - 1) * params.Limit
|
||||
|
||||
suppliers, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
|
||||
@@ -54,6 +67,11 @@ func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
||||
if params.Search != "" {
|
||||
return db.Where("name LIKE ?", "%"+params.Search+"%")
|
||||
}
|
||||
|
||||
if params.Category != "" {
|
||||
db = db.Where("category LIKE ?", "%"+params.Category+"%")
|
||||
}
|
||||
|
||||
return db.Order("created_at DESC").Order("updated_at DESC")
|
||||
})
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ type Update struct {
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
Page int `query:"page" validate:"omitempty,number,min=1"`
|
||||
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
|
||||
Search string `query:"search" validate:"omitempty,max=50"`
|
||||
Category string `query:"category" validate:"omitempty,max=50"`
|
||||
}
|
||||
|
||||
@@ -9,17 +9,17 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type UomBaseDTO struct {
|
||||
type UomRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type UomListDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type UomDetailDTO struct {
|
||||
@@ -28,17 +28,17 @@ type UomDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToUomBaseDTO(e entity.Uom) UomBaseDTO {
|
||||
return UomBaseDTO{
|
||||
func ToUomRelationDTO(e entity.Uom) UomRelationDTO {
|
||||
return UomRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToUomListDTO(e entity.Uom) UomListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
|
||||
@@ -12,25 +12,25 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type WarehouseBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Area *areaDTO.AreaBaseDTO `json:"area,omitempty"`
|
||||
Location *locationDTO.LocationBaseDTO `json:"location,omitempty"`
|
||||
Kandang *kandangDTO.KandangBaseDTO `json:"kandang,omitempty"`
|
||||
type WarehouseRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Area *areaDTO.AreaRelationDTO `json:"area,omitempty"`
|
||||
Location *locationDTO.LocationRelationDTO `json:"location,omitempty"`
|
||||
Kandang *kandangDTO.KandangRelationDTO `json:"kandang,omitempty"`
|
||||
}
|
||||
|
||||
type WarehouseListDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Area *areaDTO.AreaBaseDTO `json:"area"`
|
||||
Location *locationDTO.LocationBaseDTO `json:"location"`
|
||||
Kandang *kandangDTO.KandangBaseDTO `json:"kandang"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Area *areaDTO.AreaRelationDTO `json:"area"`
|
||||
Location *locationDTO.LocationRelationDTO `json:"location"`
|
||||
Kandang *kandangDTO.KandangRelationDTO `json:"kandang"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type WarehouseDetailDTO struct {
|
||||
@@ -39,26 +39,26 @@ type WarehouseDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToWarehouseBaseDTO(e entity.Warehouse) WarehouseBaseDTO {
|
||||
var area *areaDTO.AreaBaseDTO
|
||||
func ToWarehouseRelationDTO(e entity.Warehouse) WarehouseRelationDTO {
|
||||
var area *areaDTO.AreaRelationDTO
|
||||
if e.Area.Id != 0 {
|
||||
mapped := areaDTO.ToAreaBaseDTO(e.Area)
|
||||
mapped := areaDTO.ToAreaRelationDTO(e.Area)
|
||||
area = &mapped
|
||||
}
|
||||
|
||||
var location *locationDTO.LocationBaseDTO
|
||||
var location *locationDTO.LocationRelationDTO
|
||||
if e.Location != nil && e.Location.Id != 0 {
|
||||
mapped := locationDTO.ToLocationBaseDTO(*e.Location)
|
||||
mapped := locationDTO.ToLocationRelationDTO(*e.Location)
|
||||
location = &mapped
|
||||
}
|
||||
|
||||
var kandang *kandangDTO.KandangBaseDTO
|
||||
var kandang *kandangDTO.KandangRelationDTO
|
||||
if e.Kandang != nil && e.Kandang.Id != 0 {
|
||||
mapped := kandangDTO.ToKandangBaseDTO(*e.Kandang)
|
||||
mapped := kandangDTO.ToKandangRelationDTO(*e.Kandang)
|
||||
kandang = &mapped
|
||||
}
|
||||
|
||||
return WarehouseBaseDTO{
|
||||
return WarehouseRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
Type: e.Type,
|
||||
@@ -69,27 +69,27 @@ func ToWarehouseBaseDTO(e entity.Warehouse) WarehouseBaseDTO {
|
||||
}
|
||||
|
||||
func ToWarehouseListDTO(e entity.Warehouse) WarehouseListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
var area *areaDTO.AreaBaseDTO
|
||||
var area *areaDTO.AreaRelationDTO
|
||||
if e.Area.Id != 0 {
|
||||
mapped := areaDTO.ToAreaBaseDTO(e.Area)
|
||||
mapped := areaDTO.ToAreaRelationDTO(e.Area)
|
||||
area = &mapped
|
||||
}
|
||||
|
||||
var location *locationDTO.LocationBaseDTO
|
||||
var location *locationDTO.LocationRelationDTO
|
||||
if e.Location != nil && e.Location.Id != 0 {
|
||||
mapped := locationDTO.ToLocationBaseDTO(*e.Location)
|
||||
mapped := locationDTO.ToLocationRelationDTO(*e.Location)
|
||||
location = &mapped
|
||||
}
|
||||
|
||||
var kandang *kandangDTO.KandangBaseDTO
|
||||
var kandang *kandangDTO.KandangRelationDTO
|
||||
if e.Kandang != nil && e.Kandang.Id != 0 {
|
||||
mapped := kandangDTO.ToKandangBaseDTO(*e.Kandang)
|
||||
mapped := kandangDTO.ToKandangRelationDTO(*e.Kandang)
|
||||
kandang = &mapped
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ func (u *ProjectFlockKandangController) GetAll(c *fiber.Ctx) error {
|
||||
|
||||
data := make([]dto.ProjectFlockKandangListDTO, 0)
|
||||
for _, result := range results {
|
||||
var flock *flockDTO.FlockBaseDTO
|
||||
var flock *flockDTO.FlockRelationDTO
|
||||
if flockMap != nil {
|
||||
flock = flockMap[result.ProjectFlock.Id]
|
||||
}
|
||||
|
||||
+56
-56
@@ -18,24 +18,24 @@ import (
|
||||
|
||||
// === DTO Structs (ordered) ===
|
||||
|
||||
type ProjectFlockKandangBaseDTO struct {
|
||||
type ProjectFlockKandangRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
KandangId uint `json:"kandang_id"`
|
||||
ProjectFlockId uint `json:"project_flock_id"`
|
||||
}
|
||||
|
||||
type ProjectFlockDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"flock_name,omitempty"`
|
||||
Period int `json:"period"`
|
||||
Flock *flockDTO.FlockBaseDTO `json:"flock,omitempty"`
|
||||
Area *areaDTO.AreaBaseDTO `json:"area,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Fcr *fcrDTO.FcrBaseDTO `json:"fcr,omitempty"`
|
||||
Location *locationDTO.LocationBaseDTO `json:"location,omitempty"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"flock_name,omitempty"`
|
||||
Period int `json:"period"`
|
||||
Flock *flockDTO.FlockRelationDTO `json:"flock,omitempty"`
|
||||
Area *areaDTO.AreaRelationDTO `json:"area,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Fcr *fcrDTO.FcrRelationDTO `json:"fcr,omitempty"`
|
||||
Location *locationDTO.LocationRelationDTO `json:"location,omitempty"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type KandangDTO struct {
|
||||
@@ -45,9 +45,9 @@ type KandangDTO struct {
|
||||
}
|
||||
|
||||
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 AvailableQtyDTO struct {
|
||||
@@ -56,24 +56,24 @@ type AvailableQtyDTO struct {
|
||||
}
|
||||
|
||||
type ProjectFlockKandangListDTO struct {
|
||||
ProjectFlockKandangBaseDTO
|
||||
ProjectFlock *ProjectFlockDTO `json:"project_flock,omitempty"`
|
||||
Kandang *KandangDTO `json:"kandang,omitempty"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Approval *approvalDTO.ApprovalBaseDTO `json:"approval,omitempty"`
|
||||
ProjectFlockKandangRelationDTO
|
||||
ProjectFlock *ProjectFlockDTO `json:"project_flock,omitempty"`
|
||||
Kandang *KandangDTO `json:"kandang,omitempty"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Approval *approvalDTO.ApprovalRelationDTO `json:"approval,omitempty"`
|
||||
}
|
||||
|
||||
type ProjectFlockKandangDetailDTO struct {
|
||||
ProjectFlockKandangListDTO
|
||||
Chickins []chickinDTO.ChickinBaseDTO `json:"chickins,omitempty"`
|
||||
AvailableQtys []AvailableQtyDTO `json:"available_qtys,omitempty"`
|
||||
Chickins []chickinDTO.ChickinRelationDTO `json:"chickins,omitempty"`
|
||||
AvailableQtys []AvailableQtyDTO `json:"available_qtys,omitempty"`
|
||||
}
|
||||
|
||||
// === Mapper Functions (ordered) ===
|
||||
|
||||
func ToProjectFlockKandangBaseDTO(e entity.ProjectFlockKandang) ProjectFlockKandangBaseDTO {
|
||||
return ProjectFlockKandangBaseDTO{
|
||||
func ToProjectFlockKandangRelationDTO(e entity.ProjectFlockKandang) ProjectFlockKandangRelationDTO {
|
||||
return ProjectFlockKandangRelationDTO{
|
||||
Id: e.Id,
|
||||
KandangId: e.KandangId,
|
||||
ProjectFlockId: e.ProjectFlockId,
|
||||
@@ -104,20 +104,20 @@ func ToProjectFlockKandangDetailDTOWithAvailableQty(e entity.ProjectFlockKandang
|
||||
return ToProjectFlockKandangDetailDTOWithAvailableQtyAndFlock(e, availableQtyMap, productWarehouses, nil)
|
||||
}
|
||||
|
||||
func ToProjectFlockKandangDetailDTOWithAvailableQtyAndFlock(e entity.ProjectFlockKandang, availableQtyMap map[uint]float64, productWarehouses []entity.ProductWarehouse, flock *flockDTO.FlockBaseDTO) ProjectFlockKandangDetailDTO {
|
||||
func ToProjectFlockKandangDetailDTOWithAvailableQtyAndFlock(e entity.ProjectFlockKandang, availableQtyMap map[uint]float64, productWarehouses []entity.ProductWarehouse, flock *flockDTO.FlockRelationDTO) ProjectFlockKandangDetailDTO {
|
||||
var projectFlockSummary *projectFlockDTO.ProjectFlockListDTO
|
||||
if e.ProjectFlock.Id != 0 {
|
||||
mapped := projectFlockDTO.ToProjectFlockListDTO(e.ProjectFlock, flock)
|
||||
mapped := projectFlockDTO.ToProjectFlockListDTO(e.ProjectFlock)
|
||||
projectFlockSummary = &mapped
|
||||
}
|
||||
|
||||
listDTO := ProjectFlockKandangListDTO{
|
||||
ProjectFlockKandangBaseDTO: ToProjectFlockKandangBaseDTO(e),
|
||||
ProjectFlock: toProjectFlockDTO(projectFlockSummary),
|
||||
Kandang: toKandangDTO(e.Kandang),
|
||||
CreatedAt: e.CreatedAt,
|
||||
CreatedUser: toCreatedUserDTO(e.ProjectFlock),
|
||||
Approval: toApprovalDTO(e),
|
||||
ProjectFlockKandangRelationDTO: ToProjectFlockKandangRelationDTO(e),
|
||||
ProjectFlock: toProjectFlockDTO(projectFlockSummary),
|
||||
Kandang: toKandangDTO(e.Kandang),
|
||||
CreatedAt: e.CreatedAt,
|
||||
CreatedUser: toCreatedUserDTO(e.ProjectFlock),
|
||||
Approval: toApprovalDTO(e),
|
||||
}
|
||||
|
||||
return ProjectFlockKandangDetailDTO{
|
||||
@@ -139,18 +139,18 @@ func toKandangDTO(kandang entity.Kandang) *KandangDTO {
|
||||
}
|
||||
}
|
||||
|
||||
func toFlockDTO(flock *entity.Flock) *flockDTO.FlockBaseDTO {
|
||||
if flock == nil || flock.Id == 0 {
|
||||
return nil
|
||||
}
|
||||
// func toFlockDTO(flock *entity.Flock) *flockDTO.FlockRelationDTO {
|
||||
// if flock == nil || flock.Id == 0 {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
return &flockDTO.FlockBaseDTO{
|
||||
Id: flock.Id,
|
||||
Name: flock.Name,
|
||||
}
|
||||
}
|
||||
// return &flockDTO.FlockRelationDTO{
|
||||
// Id: flock.Id,
|
||||
// Name: flock.Name,
|
||||
// }
|
||||
// }
|
||||
|
||||
func toApprovalDTO(e entity.ProjectFlockKandang) *approvalDTO.ApprovalBaseDTO {
|
||||
func toApprovalDTO(e entity.ProjectFlockKandang) *approvalDTO.ApprovalRelationDTO {
|
||||
if e.LatestApproval != nil {
|
||||
mapped := approvalDTO.ToApprovalDTO(*e.LatestApproval)
|
||||
return &mapped
|
||||
@@ -162,7 +162,7 @@ func ToProjectFlockKandangListDTO(e entity.ProjectFlockKandang) ProjectFlockKand
|
||||
return ToProjectFlockKandangListDTOWithFlock(e, nil)
|
||||
}
|
||||
|
||||
func ToProjectFlockKandangListDTOWithFlock(e entity.ProjectFlockKandang, flock *flockDTO.FlockBaseDTO) ProjectFlockKandangListDTO {
|
||||
func ToProjectFlockKandangListDTOWithFlock(e entity.ProjectFlockKandang, flock *flockDTO.FlockRelationDTO) ProjectFlockKandangListDTO {
|
||||
var projectFlockSummary *projectFlockDTO.ProjectFlockListDTO
|
||||
if e.ProjectFlock.Id != 0 {
|
||||
mapped := projectFlockDTO.ToProjectFlockListDTOWithFlock(e.ProjectFlock, flock)
|
||||
@@ -170,12 +170,12 @@ func ToProjectFlockKandangListDTOWithFlock(e entity.ProjectFlockKandang, flock *
|
||||
}
|
||||
|
||||
return ProjectFlockKandangListDTO{
|
||||
ProjectFlockKandangBaseDTO: ToProjectFlockKandangBaseDTO(e),
|
||||
ProjectFlock: toProjectFlockDTO(projectFlockSummary),
|
||||
Kandang: toKandangDTO(e.Kandang),
|
||||
CreatedAt: e.CreatedAt,
|
||||
CreatedUser: toCreatedUserDTO(e.ProjectFlock),
|
||||
Approval: toApprovalDTO(e),
|
||||
ProjectFlockKandangRelationDTO: ToProjectFlockKandangRelationDTO(e),
|
||||
ProjectFlock: toProjectFlockDTO(projectFlockSummary),
|
||||
Kandang: toKandangDTO(e.Kandang),
|
||||
CreatedAt: e.CreatedAt,
|
||||
CreatedUser: toCreatedUserDTO(e.ProjectFlock),
|
||||
Approval: toApprovalDTO(e),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,12 +187,12 @@ func ToProjectFlockKandangListDTOs(e []entity.ProjectFlockKandang) []ProjectFloc
|
||||
return result
|
||||
}
|
||||
|
||||
func toCreatedUserDTO(pf entity.ProjectFlock) *userDTO.UserBaseDTO {
|
||||
func toCreatedUserDTO(pf entity.ProjectFlock) *userDTO.UserRelationDTO {
|
||||
if pf.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(pf.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(pf.CreatedUser)
|
||||
return &mapped
|
||||
} else if pf.CreatedBy != 0 {
|
||||
return &userDTO.UserBaseDTO{
|
||||
return &userDTO.UserRelationDTO{
|
||||
Id: pf.CreatedBy,
|
||||
IdUser: int64(pf.CreatedBy),
|
||||
}
|
||||
@@ -200,14 +200,14 @@ func toCreatedUserDTO(pf entity.ProjectFlock) *userDTO.UserBaseDTO {
|
||||
return nil
|
||||
}
|
||||
|
||||
func toChickinDTOs(chickins []entity.ProjectChickin) []chickinDTO.ChickinBaseDTO {
|
||||
func toChickinDTOs(chickins []entity.ProjectChickin) []chickinDTO.ChickinRelationDTO {
|
||||
if len(chickins) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]chickinDTO.ChickinBaseDTO, len(chickins))
|
||||
result := make([]chickinDTO.ChickinRelationDTO, len(chickins))
|
||||
for i, ch := range chickins {
|
||||
result[i] = chickinDTO.ToChickinBaseDTO(ch)
|
||||
result[i] = chickinDTO.ToChickinRelationDTO(ch)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
+8
-8
@@ -21,8 +21,8 @@ import (
|
||||
)
|
||||
|
||||
type ProjectFlockKandangService interface {
|
||||
GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlockKandang, int64, map[uint]*flockDTO.FlockBaseDTO, error)
|
||||
GetOne(ctx *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, *flockDTO.FlockBaseDTO, error)
|
||||
GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlockKandang, int64, map[uint]*flockDTO.FlockRelationDTO, error)
|
||||
GetOne(ctx *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, *flockDTO.FlockRelationDTO, error)
|
||||
}
|
||||
|
||||
// Note: map[uint]float64 adalah mapping dari ProductWarehouse ID ke calculated available quantity
|
||||
@@ -51,7 +51,7 @@ func NewProjectFlockKandangService(repo repository.ProjectFlockKandangRepository
|
||||
}
|
||||
}
|
||||
|
||||
func (s projectFlockKandangService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlockKandang, int64, map[uint]*flockDTO.FlockBaseDTO, error) {
|
||||
func (s projectFlockKandangService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlockKandang, int64, map[uint]*flockDTO.FlockRelationDTO, error) {
|
||||
if err := s.Validate.Struct(params); err != nil {
|
||||
return nil, 0, nil, err
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func (s projectFlockKandangService) GetAll(c *fiber.Ctx, params *validation.Quer
|
||||
}
|
||||
}
|
||||
|
||||
flockMap := make(map[uint]*flockDTO.FlockBaseDTO)
|
||||
flockMap := make(map[uint]*flockDTO.FlockRelationDTO)
|
||||
for i := range projectFlockKandangs {
|
||||
if projectFlockKandangs[i].ProjectFlock.Id != 0 {
|
||||
baseName := pfutils.DeriveBaseName(projectFlockKandangs[i].ProjectFlock.FlockName)
|
||||
@@ -95,7 +95,7 @@ func (s projectFlockKandangService) GetAll(c *fiber.Ctx, params *validation.Quer
|
||||
s.Log.Warnf("Failed to fetch flock %q: %+v", baseName, err)
|
||||
} else if flock != nil {
|
||||
|
||||
flockMap[projectFlockKandangs[i].ProjectFlock.Id] = &flockDTO.FlockBaseDTO{
|
||||
flockMap[projectFlockKandangs[i].ProjectFlock.Id] = &flockDTO.FlockRelationDTO{
|
||||
Id: flock.Id,
|
||||
Name: flock.Name,
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func (s projectFlockKandangService) GetAll(c *fiber.Ctx, params *validation.Quer
|
||||
return projectFlockKandangs, total, flockMap, nil
|
||||
}
|
||||
|
||||
func (s projectFlockKandangService) GetOne(c *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, *flockDTO.FlockBaseDTO, error) {
|
||||
func (s projectFlockKandangService) GetOne(c *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, *flockDTO.FlockRelationDTO, error) {
|
||||
projectFlockKandang, err := s.Repository.GetByID(c.Context(), id)
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil, nil, nil, fiber.NewError(fiber.StatusNotFound, "ProjectFlockKandang not found")
|
||||
@@ -147,7 +147,7 @@ func (s projectFlockKandangService) GetOne(c *fiber.Ctx, id uint) (*entity.Proje
|
||||
productWarehouses = []entity.ProductWarehouse{}
|
||||
}
|
||||
}
|
||||
var flockResult *flockDTO.FlockBaseDTO
|
||||
var flockResult *flockDTO.FlockRelationDTO
|
||||
if projectFlockKandang.ProjectFlock.Id != 0 {
|
||||
baseName := pfutils.DeriveBaseName(projectFlockKandang.ProjectFlock.FlockName)
|
||||
if baseName != "" {
|
||||
@@ -155,7 +155,7 @@ func (s projectFlockKandangService) GetOne(c *fiber.Ctx, id uint) (*entity.Proje
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
s.Log.Warnf("Failed to fetch flock %q: %+v", baseName, err)
|
||||
} else if flock != nil {
|
||||
flockResult = &flockDTO.FlockBaseDTO{
|
||||
flockResult = &flockDTO.FlockRelationDTO{
|
||||
Id: flock.Id,
|
||||
Name: flock.Name,
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
flockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/dto"
|
||||
service "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/services"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/validations"
|
||||
@@ -85,7 +84,7 @@ func (u *ProjectflockController) GetAll(c *fiber.Ctx) error {
|
||||
query.KandangIds = ids
|
||||
}
|
||||
|
||||
result, totalResults, flockMap, err := u.ProjectflockService.GetAll(c, query)
|
||||
result, totalResults, _, err := u.ProjectflockService.GetAll(c, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -124,7 +123,7 @@ func (u *ProjectflockController) GetOne(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid Id")
|
||||
}
|
||||
|
||||
result, flock, err := u.ProjectflockService.GetOne(c, uint(id))
|
||||
result, _, err := u.ProjectflockService.GetOne(c, uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -162,7 +161,7 @@ func (u *ProjectflockController) CreateOne(c *fiber.Ctx) error {
|
||||
Code: fiber.StatusCreated,
|
||||
Status: "success",
|
||||
Message: "Create projectflock successfully",
|
||||
Data: dto.ToProjectFlockListDTO(*result, nil),
|
||||
Data: dto.ToProjectFlockListDTO(*result),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -189,7 +188,7 @@ func (u *ProjectflockController) UpdateOne(c *fiber.Ctx) error {
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Update projectflock successfully",
|
||||
Data: dto.ToProjectFlockListDTO(*result, nil),
|
||||
Data: dto.ToProjectFlockListDTO(*result),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -17,28 +17,28 @@ import (
|
||||
approvalutils "gitlab.com/mbugroup/lti-api.git/internal/utils/approvals"
|
||||
)
|
||||
|
||||
type ProjectFlockBaseDTO struct {
|
||||
type ProjectFlockRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Period int `json:"period"`
|
||||
FlockName string `json:"flock_name"`
|
||||
}
|
||||
|
||||
type ProjectFlockListDTO struct {
|
||||
ProjectFlockBaseDTO
|
||||
Flock *flockDTO.FlockBaseDTO `json:"flock,omitempty"`
|
||||
Area *areaDTO.AreaBaseDTO `json:"area,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Fcr *fcrDTO.FcrBaseDTO `json:"fcr,omitempty"`
|
||||
Location *locationDTO.LocationBaseDTO `json:"location,omitempty"`
|
||||
Kandangs []KandangWithProjectFlockIdDTO `json:"kandangs,omitempty"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Approval approvalDTO.ApprovalBaseDTO `json:"approval"`
|
||||
ProjectFlockRelationDTO
|
||||
Flock *flockDTO.FlockRelationDTO `json:"flock,omitempty"`
|
||||
Area *areaDTO.AreaRelationDTO `json:"area,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Fcr *fcrDTO.FcrRelationDTO `json:"fcr,omitempty"`
|
||||
Location *locationDTO.LocationRelationDTO `json:"location,omitempty"`
|
||||
Kandangs []KandangWithProjectFlockIdDTO `json:"kandangs,omitempty"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Approval approvalDTO.ApprovalRelationDTO `json:"approval"`
|
||||
}
|
||||
|
||||
type KandangWithProjectFlockIdDTO struct {
|
||||
kandangDTO.KandangBaseDTO
|
||||
kandangDTO.KandangRelationDTO
|
||||
ProjectFlockKandangId uint `json:"project_flock_kandang_id"`
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ type ProjectFlockDetailDTO struct {
|
||||
}
|
||||
|
||||
type FlockPeriodDTO struct {
|
||||
Flock flockDTO.FlockBaseDTO `json:"flock"`
|
||||
NextPeriod int `json:"next_period"`
|
||||
Flock flockDTO.FlockRelationDTO `json:"flock"`
|
||||
NextPeriod int `json:"next_period"`
|
||||
}
|
||||
|
||||
type KandangPeriodSummaryDTO struct {
|
||||
@@ -58,9 +58,9 @@ type KandangPeriodSummaryDTO struct {
|
||||
}
|
||||
|
||||
func ToProjectFlockListDTOWithPeriod(e entity.ProjectFlock, period int) ProjectFlockListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
@@ -77,34 +77,34 @@ func ToProjectFlockListDTOWithPeriod(e entity.ProjectFlock, period int) ProjectF
|
||||
}
|
||||
}
|
||||
kandangSummaries[i] = KandangWithProjectFlockIdDTO{
|
||||
KandangBaseDTO: kandangDTO.ToKandangBaseDTO(kandang),
|
||||
KandangRelationDTO: kandangDTO.ToKandangRelationDTO(kandang),
|
||||
ProjectFlockKandangId: pfkId,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var areaSummary *areaDTO.AreaBaseDTO
|
||||
var areaSummary *areaDTO.AreaRelationDTO
|
||||
if e.Area.Id != 0 {
|
||||
mapped := areaDTO.ToAreaBaseDTO(e.Area)
|
||||
mapped := areaDTO.ToAreaRelationDTO(e.Area)
|
||||
areaSummary = &mapped
|
||||
}
|
||||
|
||||
var fcrSummary *fcrDTO.FcrBaseDTO
|
||||
var fcrSummary *fcrDTO.FcrRelationDTO
|
||||
if e.Fcr.Id != 0 {
|
||||
mapped := fcrDTO.ToFcrBaseDTO(e.Fcr)
|
||||
mapped := fcrDTO.ToFcrRelationDTO(e.Fcr)
|
||||
fcrSummary = &mapped
|
||||
}
|
||||
|
||||
var locationSummary *locationDTO.LocationBaseDTO
|
||||
var locationSummary *locationDTO.LocationRelationDTO
|
||||
if e.Location.Id != 0 {
|
||||
mapped := locationDTO.ToLocationBaseDTO(e.Location)
|
||||
mapped := locationDTO.ToLocationRelationDTO(e.Location)
|
||||
locationSummary = &mapped
|
||||
}
|
||||
|
||||
var flockSummary *flockDTO.FlockBaseDTO
|
||||
if flock != nil && flock.Id != 0 {
|
||||
flockSummary = flock
|
||||
}
|
||||
// var flockSummary *flockDTO.FlockRelationDTO
|
||||
// if flock != nil && flock.Id != 0 {
|
||||
// flockSummary = flock
|
||||
// }
|
||||
|
||||
latestApproval := defaultProjectFlockLatestApproval(e)
|
||||
if e.LatestApproval != nil {
|
||||
@@ -113,7 +113,7 @@ func ToProjectFlockListDTOWithPeriod(e entity.ProjectFlock, period int) ProjectF
|
||||
}
|
||||
|
||||
return ProjectFlockListDTO{
|
||||
ProjectFlockBaseDTO: createProjectFlockBaseDTO(e, period),
|
||||
ProjectFlockRelationDTO: createProjectFlockRelationDTO(e, period),
|
||||
// Flock: flockSummary,
|
||||
Area: areaSummary,
|
||||
Kandangs: kandangSummaries,
|
||||
@@ -127,8 +127,8 @@ func ToProjectFlockListDTOWithPeriod(e entity.ProjectFlock, period int) ProjectF
|
||||
}
|
||||
}
|
||||
|
||||
func ToProjectFlockListDTOWithFlock(e entity.ProjectFlock, flock *flockDTO.FlockBaseDTO) ProjectFlockListDTO {
|
||||
return ToProjectFlockListDTO(e, flock)
|
||||
func ToProjectFlockListDTOWithFlock(e entity.ProjectFlock, flock *flockDTO.FlockRelationDTO) ProjectFlockListDTO {
|
||||
return ToProjectFlockListDTO(e)
|
||||
}
|
||||
|
||||
func ToProjectFlockListDTOs(items []entity.ProjectFlock) []ProjectFlockListDTO {
|
||||
@@ -160,10 +160,10 @@ func ToProjectFlockListDTOsWithPeriods(items []entity.ProjectFlock, periods map[
|
||||
func ToProjectFlockListDTOsWithFlocks(items []entity.ProjectFlock, flocks map[uint]*entity.Flock) []ProjectFlockListDTO {
|
||||
result := make([]ProjectFlockListDTO, len(items))
|
||||
for i, item := range items {
|
||||
var flock *flockDTO.FlockBaseDTO
|
||||
var flock *flockDTO.FlockRelationDTO
|
||||
if flocks != nil {
|
||||
if f := flocks[item.Id]; f != nil {
|
||||
flock = &flockDTO.FlockBaseDTO{
|
||||
flock = &flockDTO.FlockRelationDTO{
|
||||
Id: f.Id,
|
||||
Name: f.Name,
|
||||
}
|
||||
@@ -174,14 +174,14 @@ func ToProjectFlockListDTOsWithFlocks(items []entity.ProjectFlock, flocks map[ui
|
||||
return result
|
||||
}
|
||||
|
||||
func ToProjectFlockDetailDTO(e entity.ProjectFlock, flock *flockDTO.FlockBaseDTO) ProjectFlockDetailDTO {
|
||||
func ToProjectFlockDetailDTO(e entity.ProjectFlock, flock *flockDTO.FlockRelationDTO) ProjectFlockDetailDTO {
|
||||
return ProjectFlockDetailDTO{
|
||||
ProjectFlockListDTO: ToProjectFlockListDTOWithPeriod(e, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func defaultProjectFlockLatestApproval(e entity.ProjectFlock) approvalDTO.ApprovalBaseDTO {
|
||||
result := approvalDTO.ApprovalBaseDTO{}
|
||||
func defaultProjectFlockLatestApproval(e entity.ProjectFlock) approvalDTO.ApprovalRelationDTO {
|
||||
result := approvalDTO.ApprovalRelationDTO{}
|
||||
|
||||
step := utils.ProjectFlockStepPengajuan
|
||||
if step > 0 {
|
||||
@@ -194,9 +194,9 @@ func defaultProjectFlockLatestApproval(e entity.ProjectFlock) approvalDTO.Approv
|
||||
}
|
||||
|
||||
if e.CreatedUser.Id != 0 {
|
||||
result.ActionBy = userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
result.ActionBy = userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
} else if e.CreatedBy != 0 {
|
||||
result.ActionBy = userDTO.UserBaseDTO{
|
||||
result.ActionBy = userDTO.UserRelationDTO{
|
||||
Id: e.CreatedBy,
|
||||
IdUser: int64(e.CreatedBy),
|
||||
}
|
||||
@@ -205,16 +205,16 @@ func defaultProjectFlockLatestApproval(e entity.ProjectFlock) approvalDTO.Approv
|
||||
return result
|
||||
}
|
||||
|
||||
func createProjectFlockBaseDTO(e entity.ProjectFlock, period int) ProjectFlockBaseDTO {
|
||||
return ProjectFlockBaseDTO{
|
||||
func createProjectFlockRelationDTO(e entity.ProjectFlock, period int) ProjectFlockRelationDTO {
|
||||
return ProjectFlockRelationDTO{
|
||||
Id: e.Id,
|
||||
Period: period,
|
||||
FlockName: e.FlockName,
|
||||
}
|
||||
}
|
||||
|
||||
func ToFlockSummaryDTO(e entity.Flock) flockDTO.FlockBaseDTO {
|
||||
return flockDTO.FlockBaseDTO{
|
||||
func ToFlockSummaryDTO(e entity.Flock) flockDTO.FlockRelationDTO {
|
||||
return flockDTO.FlockRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
|
||||
@@ -12,35 +12,35 @@ import (
|
||||
)
|
||||
|
||||
type KandangWithPivotDTO struct {
|
||||
kandangDTO.KandangBaseDTO
|
||||
kandangDTO.KandangRelationDTO
|
||||
AvailableQuantity float64 `json:"available_quantity"`
|
||||
}
|
||||
|
||||
type ProjectFlockWithPivotDTO struct {
|
||||
ProjectFlockBaseDTO
|
||||
Flock *flockDTO.FlockBaseDTO `json:"flock,omitempty"`
|
||||
Area *areaDTO.AreaBaseDTO `json:"area,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Fcr *fcrDTO.FcrBaseDTO `json:"fcr,omitempty"`
|
||||
Location *locationDTO.LocationBaseDTO `json:"location,omitempty"`
|
||||
Kandangs []KandangWithPivotDTO `json:"kandangs,omitempty"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user,omitempty"`
|
||||
ProjectFlockRelationDTO
|
||||
Flock *flockDTO.FlockRelationDTO `json:"flock,omitempty"`
|
||||
Area *areaDTO.AreaRelationDTO `json:"area,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Fcr *fcrDTO.FcrRelationDTO `json:"fcr,omitempty"`
|
||||
Location *locationDTO.LocationRelationDTO `json:"location,omitempty"`
|
||||
Kandangs []KandangWithPivotDTO `json:"kandangs,omitempty"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
||||
}
|
||||
|
||||
type ProjectFlockKandangDTO struct {
|
||||
Id uint `json:"id"`
|
||||
ProjectFlockKandangId uint `json:"project_flock_kandang_id"`
|
||||
ProjectFlockId uint `json:"project_flock_id"`
|
||||
KandangId uint `json:"kandang_id"`
|
||||
Kandang *kandangDTO.KandangBaseDTO `json:"kandang,omitempty"`
|
||||
ProjectFlock *ProjectFlockWithPivotDTO `json:"project_flock,omitempty"`
|
||||
AvailableQuantity float64 `json:"available_quantity"`
|
||||
Id uint `json:"id"`
|
||||
ProjectFlockKandangId uint `json:"project_flock_kandang_id"`
|
||||
ProjectFlockId uint `json:"project_flock_id"`
|
||||
KandangId uint `json:"kandang_id"`
|
||||
Kandang *kandangDTO.KandangRelationDTO `json:"kandang,omitempty"`
|
||||
ProjectFlock *ProjectFlockWithPivotDTO `json:"project_flock,omitempty"`
|
||||
AvailableQuantity float64 `json:"available_quantity"`
|
||||
}
|
||||
|
||||
func ToProjectFlockKandangDTO(e entity.ProjectFlockKandang) ProjectFlockKandangDTO {
|
||||
var kandang *kandangDTO.KandangBaseDTO
|
||||
var kandang *kandangDTO.KandangRelationDTO
|
||||
if e.Kandang.Id != 0 {
|
||||
mapped := kandangDTO.ToKandangBaseDTO(e.Kandang)
|
||||
mapped := kandangDTO.ToKandangRelationDTO(e.Kandang)
|
||||
kandang = &mapped
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func ToProjectFlockKandangDTO(e entity.ProjectFlockKandang) ProjectFlockKandangD
|
||||
if e.ProjectFlock.Id != 0 {
|
||||
|
||||
pfLocal := ProjectFlockWithPivotDTO{
|
||||
ProjectFlockBaseDTO: ProjectFlockBaseDTO{
|
||||
ProjectFlockRelationDTO: ProjectFlockRelationDTO{
|
||||
Id: e.ProjectFlock.Id,
|
||||
Period: e.Period,
|
||||
FlockName: e.ProjectFlock.FlockName,
|
||||
@@ -57,31 +57,31 @@ func ToProjectFlockKandangDTO(e entity.ProjectFlockKandang) ProjectFlockKandangD
|
||||
}
|
||||
|
||||
if base := pfutils.DeriveBaseName(e.ProjectFlock.FlockName); base != "" {
|
||||
summary := flockDTO.FlockBaseDTO{Id: 0, Name: base}
|
||||
summary := flockDTO.FlockRelationDTO{Id: 0, Name: base}
|
||||
pfLocal.Flock = &summary
|
||||
}
|
||||
if e.ProjectFlock.Area.Id != 0 {
|
||||
mapped := areaDTO.ToAreaBaseDTO(e.ProjectFlock.Area)
|
||||
mapped := areaDTO.ToAreaRelationDTO(e.ProjectFlock.Area)
|
||||
pfLocal.Area = &mapped
|
||||
}
|
||||
if e.ProjectFlock.Fcr.Id != 0 {
|
||||
mapped := fcrDTO.ToFcrBaseDTO(e.ProjectFlock.Fcr)
|
||||
mapped := fcrDTO.ToFcrRelationDTO(e.ProjectFlock.Fcr)
|
||||
pfLocal.Fcr = &mapped
|
||||
}
|
||||
if e.ProjectFlock.Location.Id != 0 {
|
||||
mapped := locationDTO.ToLocationBaseDTO(e.ProjectFlock.Location)
|
||||
mapped := locationDTO.ToLocationRelationDTO(e.ProjectFlock.Location)
|
||||
pfLocal.Location = &mapped
|
||||
}
|
||||
if e.ProjectFlock.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(e.ProjectFlock.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(e.ProjectFlock.CreatedUser)
|
||||
pfLocal.CreatedUser = &mapped
|
||||
}
|
||||
|
||||
for _, k := range e.ProjectFlock.Kandangs {
|
||||
kb := kandangDTO.ToKandangBaseDTO(k)
|
||||
kb := kandangDTO.ToKandangRelationDTO(k)
|
||||
pfLocal.Kandangs = append(pfLocal.Kandangs, KandangWithPivotDTO{
|
||||
KandangBaseDTO: kb,
|
||||
AvailableQuantity: 0,
|
||||
KandangRelationDTO: kb,
|
||||
AvailableQuantity: 0,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ import (
|
||||
)
|
||||
|
||||
type ProjectflockService interface {
|
||||
GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlock, int64, map[uint]*flockDTO.FlockBaseDTO, error)
|
||||
GetOne(ctx *fiber.Ctx, id uint) (*entity.ProjectFlock, *flockDTO.FlockBaseDTO, error)
|
||||
GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlock, int64, map[uint]*flockDTO.FlockRelationDTO, error)
|
||||
GetOne(ctx *fiber.Ctx, id uint) (*entity.ProjectFlock, *flockDTO.FlockRelationDTO, error)
|
||||
CreateOne(ctx *fiber.Ctx, req *validation.Create) (*entity.ProjectFlock, error)
|
||||
UpdateOne(ctx *fiber.Ctx, req *validation.Update, id uint) (*entity.ProjectFlock, error)
|
||||
GetAvailableDocQuantity(ctx *fiber.Ctx, kandangID uint) (float64, error)
|
||||
@@ -96,7 +96,7 @@ func (s projectflockService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
Preload("KandangHistory.Kandang")
|
||||
}
|
||||
|
||||
func (s projectflockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlock, int64, map[uint]*flockDTO.FlockBaseDTO, error) {
|
||||
func (s projectflockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlock, int64, map[uint]*flockDTO.FlockRelationDTO, error) {
|
||||
if err := s.Validate.Struct(params); err != nil {
|
||||
return nil, 0, nil, err
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (s projectflockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]e
|
||||
}
|
||||
}
|
||||
|
||||
flockMap := make(map[uint]*flockDTO.FlockBaseDTO)
|
||||
flockMap := make(map[uint]*flockDTO.FlockRelationDTO)
|
||||
for i := range projectflocks {
|
||||
if projectflocks[i].FlockName != "" {
|
||||
baseName := pfutils.DeriveBaseName(projectflocks[i].FlockName)
|
||||
@@ -146,7 +146,7 @@ func (s projectflockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]e
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
s.Log.Warnf("Failed to fetch flock %q: %+v", baseName, err)
|
||||
} else if flock != nil {
|
||||
flockMap[projectflocks[i].Id] = &flockDTO.FlockBaseDTO{
|
||||
flockMap[projectflocks[i].Id] = &flockDTO.FlockRelationDTO{
|
||||
Id: flock.Id,
|
||||
Name: flock.Name,
|
||||
}
|
||||
@@ -187,7 +187,7 @@ func (s projectflockService) getOneEntityOnly(c *fiber.Ctx, id uint) (*entity.Pr
|
||||
return projectflock, nil
|
||||
}
|
||||
|
||||
func (s projectflockService) GetOne(c *fiber.Ctx, id uint) (*entity.ProjectFlock, *flockDTO.FlockBaseDTO, error) {
|
||||
func (s projectflockService) GetOne(c *fiber.Ctx, id uint) (*entity.ProjectFlock, *flockDTO.FlockRelationDTO, error) {
|
||||
projectflock, err := s.Repository.GetByID(c.Context(), id, s.Repository.WithDefaultRelations())
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil, fiber.NewError(fiber.StatusNotFound, "Projectflock not found")
|
||||
@@ -214,7 +214,7 @@ func (s projectflockService) GetOne(c *fiber.Ctx, id uint) (*entity.ProjectFlock
|
||||
}
|
||||
|
||||
// Fetch Flock master data for this ProjectFlock
|
||||
var flockResult *flockDTO.FlockBaseDTO
|
||||
var flockResult *flockDTO.FlockRelationDTO
|
||||
if projectflock.FlockName != "" {
|
||||
baseName := pfutils.DeriveBaseName(projectflock.FlockName)
|
||||
if baseName != "" {
|
||||
@@ -222,7 +222,7 @@ func (s projectflockService) GetOne(c *fiber.Ctx, id uint) (*entity.ProjectFlock
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
s.Log.Warnf("Failed to fetch flock %q: %+v", baseName, err)
|
||||
} else if flock != nil {
|
||||
flockResult = &flockDTO.FlockBaseDTO{
|
||||
flockResult = &flockDTO.FlockRelationDTO{
|
||||
Id: flock.Id,
|
||||
Name: flock.Name,
|
||||
}
|
||||
|
||||
@@ -15,30 +15,30 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type RecordingBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
ProjectFlockKandangId uint `json:"project_flock_kandang_id"`
|
||||
RecordDatetime time.Time `json:"record_datetime"`
|
||||
Day int `json:"day"`
|
||||
ProjectFlockCategory string `json:"project_flock_category"`
|
||||
TotalDepletionQty float64 `json:"total_depletion_qty"`
|
||||
CumDepletionRate float64 `json:"cum_depletion_rate"`
|
||||
DailyGain float64 `json:"daily_gain"`
|
||||
AvgDailyGain float64 `json:"avg_daily_gain"`
|
||||
CumIntake int `json:"cum_intake"`
|
||||
FcrValue float64 `json:"fcr_value"`
|
||||
TotalChickQty float64 `json:"total_chick_qty"`
|
||||
Approval approvalDTO.ApprovalBaseDTO `json:"approval"`
|
||||
EggGradingStatus *string `json:"egg_grading_status"`
|
||||
EggGradingPendingQty *int `json:"egg_grading_pending_qty"`
|
||||
EggGradingCompletedQty *int `json:"egg_grading_completed_qty"`
|
||||
type RecordingRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
ProjectFlockKandangId uint `json:"project_flock_kandang_id"`
|
||||
RecordDatetime time.Time `json:"record_datetime"`
|
||||
Day int `json:"day"`
|
||||
ProjectFlockCategory string `json:"project_flock_category"`
|
||||
TotalDepletionQty float64 `json:"total_depletion_qty"`
|
||||
CumDepletionRate float64 `json:"cum_depletion_rate"`
|
||||
DailyGain float64 `json:"daily_gain"`
|
||||
AvgDailyGain float64 `json:"avg_daily_gain"`
|
||||
CumIntake int `json:"cum_intake"`
|
||||
FcrValue float64 `json:"fcr_value"`
|
||||
TotalChickQty float64 `json:"total_chick_qty"`
|
||||
Approval approvalDTO.ApprovalRelationDTO `json:"approval"`
|
||||
EggGradingStatus *string `json:"egg_grading_status"`
|
||||
EggGradingPendingQty *int `json:"egg_grading_pending_qty"`
|
||||
EggGradingCompletedQty *int `json:"egg_grading_completed_qty"`
|
||||
}
|
||||
|
||||
type RecordingListDTO struct {
|
||||
RecordingBaseDTO
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
RecordingRelationDTO
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type RecordingDetailDTO struct {
|
||||
@@ -91,7 +91,7 @@ type RecordingEggGradingDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToRecordingBaseDTO(e entity.Recording) RecordingBaseDTO {
|
||||
func ToRecordingRelationDTO(e entity.Recording) RecordingRelationDTO {
|
||||
var (
|
||||
projectFlockCategory string
|
||||
day int
|
||||
@@ -142,7 +142,7 @@ func ToRecordingBaseDTO(e entity.Recording) RecordingBaseDTO {
|
||||
|
||||
gradingStatus, gradingPending, gradingCompleted := computeEggGradingStatus(e)
|
||||
|
||||
return RecordingBaseDTO{
|
||||
return RecordingRelationDTO{
|
||||
Id: e.Id,
|
||||
ProjectFlockKandangId: e.ProjectFlockKandangId,
|
||||
RecordDatetime: e.RecordDatetime,
|
||||
@@ -163,17 +163,17 @@ func ToRecordingBaseDTO(e entity.Recording) RecordingBaseDTO {
|
||||
}
|
||||
|
||||
func ToRecordingListDTO(e entity.Recording) RecordingListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser != nil && e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(*e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(*e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return RecordingListDTO{
|
||||
RecordingBaseDTO: ToRecordingBaseDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
RecordingRelationDTO: ToRecordingRelationDTO(e),
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,8 +344,8 @@ func filterGoodEggs(eggs []entity.RecordingEgg) []entity.RecordingEgg {
|
||||
return result
|
||||
}
|
||||
|
||||
func defaultRecordingLatestApproval(e entity.Recording) approvalDTO.ApprovalBaseDTO {
|
||||
result := approvalDTO.ApprovalBaseDTO{}
|
||||
func defaultRecordingLatestApproval(e entity.Recording) approvalDTO.ApprovalRelationDTO {
|
||||
result := approvalDTO.ApprovalRelationDTO{}
|
||||
|
||||
step := utils.RecordingStepPengajuan
|
||||
result.StepNumber = uint16(step)
|
||||
@@ -356,9 +356,9 @@ func defaultRecordingLatestApproval(e entity.Recording) approvalDTO.ApprovalBase
|
||||
}
|
||||
|
||||
if e.CreatedUser != nil && e.CreatedUser.Id != 0 {
|
||||
result.ActionBy = userDTO.ToUserBaseDTO(*e.CreatedUser)
|
||||
result.ActionBy = userDTO.ToUserRelationDTO(*e.CreatedUser)
|
||||
} else if e.CreatedBy != 0 {
|
||||
result.ActionBy = userDTO.UserBaseDTO{
|
||||
result.ActionBy = userDTO.UserRelationDTO{
|
||||
Id: e.CreatedBy,
|
||||
IdUser: int64(e.CreatedBy),
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type TransferLayingBaseDTO struct {
|
||||
type TransferLayingRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
TransferNumber string `json:"transfer_number"`
|
||||
TransferDate time.Time `json:"transfer_date"`
|
||||
@@ -64,22 +64,22 @@ type LayingTransferTargetDTO struct {
|
||||
}
|
||||
|
||||
type TransferLayingListDTO struct {
|
||||
TransferLayingBaseDTO
|
||||
FromProjectFlock *ProjectFlockSummaryDTO `json:"from_project_flock,omitempty"`
|
||||
ToProjectFlock *ProjectFlockSummaryDTO `json:"to_project_flock,omitempty"`
|
||||
PendingUsageQty *float64 `json:"pending_usage_qty"`
|
||||
UsageQty *float64 `json:"usage_qty"`
|
||||
CreatedBy uint `json:"created_by"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Approval *approvalDTO.ApprovalBaseDTO `json:"approval,omitempty"`
|
||||
TransferLayingRelationDTO
|
||||
FromProjectFlock *ProjectFlockSummaryDTO `json:"from_project_flock,omitempty"`
|
||||
ToProjectFlock *ProjectFlockSummaryDTO `json:"to_project_flock,omitempty"`
|
||||
PendingUsageQty *float64 `json:"pending_usage_qty"`
|
||||
UsageQty *float64 `json:"usage_qty"`
|
||||
CreatedBy uint `json:"created_by"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Approval *approvalDTO.ApprovalRelationDTO `json:"approval,omitempty"`
|
||||
}
|
||||
|
||||
type TransferLayingDetailDTO struct {
|
||||
TransferLayingListDTO
|
||||
Sources []LayingTransferSourceDTO `json:"sources,omitempty"`
|
||||
Targets []LayingTransferTargetDTO `json:"targets,omitempty"`
|
||||
Approval *approvalDTO.ApprovalBaseDTO `json:"approval,omitempty"`
|
||||
Sources []LayingTransferSourceDTO `json:"sources,omitempty"`
|
||||
Targets []LayingTransferTargetDTO `json:"targets,omitempty"`
|
||||
Approval *approvalDTO.ApprovalRelationDTO `json:"approval,omitempty"`
|
||||
}
|
||||
|
||||
// === Available Quantity DTOs ===
|
||||
@@ -203,8 +203,8 @@ func ToLayingTransferTargetDTOs(targets []entity.LayingTransferTarget) []LayingT
|
||||
return result
|
||||
}
|
||||
|
||||
func ToTransferLayingBaseDTO(e entity.LayingTransfer) TransferLayingBaseDTO {
|
||||
return TransferLayingBaseDTO{
|
||||
func ToTransferLayingRelationDTO(e entity.LayingTransfer) TransferLayingRelationDTO {
|
||||
return TransferLayingRelationDTO{
|
||||
Id: e.Id,
|
||||
TransferNumber: e.TransferNumber,
|
||||
TransferDate: e.TransferDate,
|
||||
@@ -213,26 +213,26 @@ func ToTransferLayingBaseDTO(e entity.LayingTransfer) TransferLayingBaseDTO {
|
||||
}
|
||||
|
||||
func ToTransferLayingListDTO(e entity.LayingTransfer) TransferLayingListDTO {
|
||||
var createdUser *userDTO.UserBaseDTO
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser != nil && e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserBaseDTO(*e.CreatedUser)
|
||||
mapped := userDTO.ToUserRelationDTO(*e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return TransferLayingListDTO{
|
||||
TransferLayingBaseDTO: ToTransferLayingBaseDTO(e),
|
||||
FromProjectFlock: ToProjectFlockSummaryDTO(e.FromProjectFlock),
|
||||
ToProjectFlock: ToProjectFlockSummaryDTO(e.ToProjectFlock),
|
||||
PendingUsageQty: e.PendingUsageQty,
|
||||
UsageQty: e.UsageQty,
|
||||
CreatedBy: e.CreatedBy,
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: e.CreatedAt,
|
||||
TransferLayingRelationDTO: ToTransferLayingRelationDTO(e),
|
||||
FromProjectFlock: ToProjectFlockSummaryDTO(e.FromProjectFlock),
|
||||
ToProjectFlock: ToProjectFlockSummaryDTO(e.ToProjectFlock),
|
||||
PendingUsageQty: e.PendingUsageQty,
|
||||
UsageQty: e.UsageQty,
|
||||
CreatedBy: e.CreatedBy,
|
||||
CreatedUser: createdUser,
|
||||
CreatedAt: e.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func ToTransferLayingDetailDTO(e entity.LayingTransfer, approvals []entity.Approval) TransferLayingDetailDTO {
|
||||
var latestApproval *approvalDTO.ApprovalBaseDTO
|
||||
var latestApproval *approvalDTO.ApprovalRelationDTO
|
||||
|
||||
if e.LatestApproval != nil {
|
||||
mapped := approvalDTO.ToApprovalDTO(*e.LatestApproval)
|
||||
@@ -252,7 +252,7 @@ func ToTransferLayingDetailDTO(e entity.LayingTransfer, approvals []entity.Appro
|
||||
}
|
||||
|
||||
func ToTransferLayingDetailDTOWithSingleApproval(e entity.LayingTransfer, approval *entity.Approval) TransferLayingDetailDTO {
|
||||
var mappedApproval *approvalDTO.ApprovalBaseDTO
|
||||
var mappedApproval *approvalDTO.ApprovalRelationDTO
|
||||
|
||||
// Prefer LatestApproval from entity
|
||||
if e.LatestApproval != nil && e.LatestApproval.Id != 0 {
|
||||
|
||||
@@ -13,52 +13,52 @@ import (
|
||||
)
|
||||
|
||||
type PurchaseListItemDTO struct {
|
||||
Id uint64 `json:"id"`
|
||||
PrNumber string `json:"pr_number"`
|
||||
PoNumber *string `json:"po_number"`
|
||||
Supplier *supplierDTO.SupplierBaseDTO `json:"supplier"`
|
||||
CreditTerm *int `json:"credit_term"`
|
||||
DueDate *time.Time `json:"due_date"`
|
||||
PoDate *time.Time `json:"po_date"`
|
||||
GrandTotal float64 `json:"grand_total"`
|
||||
Notes *string `json:"notes"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Approval *approvalDTO.ApprovalBaseDTO `json:"approval"`
|
||||
Id uint64 `json:"id"`
|
||||
PrNumber string `json:"pr_number"`
|
||||
PoNumber *string `json:"po_number"`
|
||||
Supplier *supplierDTO.SupplierRelationDTO `json:"supplier"`
|
||||
CreditTerm *int `json:"credit_term"`
|
||||
DueDate *time.Time `json:"due_date"`
|
||||
PoDate *time.Time `json:"po_date"`
|
||||
GrandTotal float64 `json:"grand_total"`
|
||||
Notes *string `json:"notes"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Approval *approvalDTO.ApprovalRelationDTO `json:"approval"`
|
||||
}
|
||||
|
||||
type PurchaseDetailDTO struct {
|
||||
Id uint64 `json:"id"`
|
||||
PrNumber string `json:"pr_number"`
|
||||
PoNumber *string `json:"po_number"`
|
||||
Supplier *supplierDTO.SupplierBaseDTO `json:"supplier"`
|
||||
CreditTerm *int `json:"credit_term"`
|
||||
DueDate *time.Time `json:"due_date"`
|
||||
PoDate *time.Time `json:"po_date"`
|
||||
GrandTotal float64 `json:"grand_total"`
|
||||
Notes *string `json:"notes"`
|
||||
Items []PurchaseItemDTO `json:"items"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Approval *approvalDTO.ApprovalBaseDTO `json:"approval"`
|
||||
Id uint64 `json:"id"`
|
||||
PrNumber string `json:"pr_number"`
|
||||
PoNumber *string `json:"po_number"`
|
||||
Supplier *supplierDTO.SupplierRelationDTO `json:"supplier"`
|
||||
CreditTerm *int `json:"credit_term"`
|
||||
DueDate *time.Time `json:"due_date"`
|
||||
PoDate *time.Time `json:"po_date"`
|
||||
GrandTotal float64 `json:"grand_total"`
|
||||
Notes *string `json:"notes"`
|
||||
Items []PurchaseItemDTO `json:"items"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Approval *approvalDTO.ApprovalRelationDTO `json:"approval"`
|
||||
}
|
||||
|
||||
type PurchaseItemDTO struct {
|
||||
Id uint64 `json:"id"`
|
||||
ProductID uint64 `json:"product_id"`
|
||||
Product *productDTO.ProductBaseDTO `json:"product"`
|
||||
WarehouseID uint64 `json:"warehouse_id"`
|
||||
Warehouse *warehouseDTO.WarehouseBaseDTO `json:"warehouse"`
|
||||
ProductWarehouseID *uint64 `json:"product_warehouse_id"`
|
||||
SubQty float64 `json:"sub_qty"`
|
||||
TotalQty float64 `json:"total_qty"`
|
||||
TotalUsed float64 `json:"total_used"`
|
||||
Price float64 `json:"price"`
|
||||
TotalPrice float64 `json:"total_price"`
|
||||
ReceivedDate *time.Time `json:"received_date"`
|
||||
TravelNumber *string `json:"travel_number"`
|
||||
TravelDocumentPath *string `json:"travel_document_path"`
|
||||
VehicleNumber *string `json:"vehicle_number"`
|
||||
Id uint64 `json:"id"`
|
||||
ProductID uint64 `json:"product_id"`
|
||||
Product *productDTO.ProductRelationDTO `json:"product"`
|
||||
WarehouseID uint64 `json:"warehouse_id"`
|
||||
Warehouse *warehouseDTO.WarehouseRelationDTO `json:"warehouse"`
|
||||
ProductWarehouseID *uint64 `json:"product_warehouse_id"`
|
||||
SubQty float64 `json:"sub_qty"`
|
||||
TotalQty float64 `json:"total_qty"`
|
||||
TotalUsed float64 `json:"total_used"`
|
||||
Price float64 `json:"price"`
|
||||
TotalPrice float64 `json:"total_price"`
|
||||
ReceivedDate *time.Time `json:"received_date"`
|
||||
TravelNumber *string `json:"travel_number"`
|
||||
TravelDocumentPath *string `json:"travel_document_path"`
|
||||
VehicleNumber *string `json:"vehicle_number"`
|
||||
}
|
||||
|
||||
func ToPurchaseItemDTO(item entity.PurchaseItem) PurchaseItemDTO {
|
||||
@@ -78,17 +78,17 @@ func ToPurchaseItemDTO(item entity.PurchaseItem) PurchaseItemDTO {
|
||||
VehicleNumber: item.VehicleNumber,
|
||||
}
|
||||
if item.Product != nil && item.Product.Id != 0 {
|
||||
summary := productDTO.ToProductBaseDTO(*item.Product)
|
||||
summary := productDTO.ToProductRelationDTO(*item.Product)
|
||||
dto.Product = &summary
|
||||
}
|
||||
if item.Warehouse != nil && item.Warehouse.Id != 0 {
|
||||
summary := warehouseDTO.ToWarehouseBaseDTO(*item.Warehouse)
|
||||
summary := warehouseDTO.ToWarehouseRelationDTO(*item.Warehouse)
|
||||
if item.Warehouse.Area.Id != 0 {
|
||||
areaSummary := areaDTO.ToAreaBaseDTO(item.Warehouse.Area)
|
||||
areaSummary := areaDTO.ToAreaRelationDTO(item.Warehouse.Area)
|
||||
summary.Area = &areaSummary
|
||||
}
|
||||
if item.Warehouse.Location != nil && item.Warehouse.Location.Id != 0 {
|
||||
locationSummary := locationDTO.ToLocationBaseDTO(*item.Warehouse.Location)
|
||||
locationSummary := locationDTO.ToLocationRelationDTO(*item.Warehouse.Location)
|
||||
summary.Location = &locationSummary
|
||||
}
|
||||
dto.Warehouse = &summary
|
||||
@@ -145,11 +145,11 @@ func ToPurchaseListDTO(p entity.Purchase) PurchaseListItemDTO {
|
||||
return dto
|
||||
}
|
||||
|
||||
func mapSupplier(s entity.Supplier) *supplierDTO.SupplierBaseDTO {
|
||||
func mapSupplier(s entity.Supplier) *supplierDTO.SupplierRelationDTO {
|
||||
if s.Id == 0 {
|
||||
return nil
|
||||
}
|
||||
summary := supplierDTO.ToSupplierBaseDTO(s)
|
||||
summary := supplierDTO.ToSupplierRelationDTO(s)
|
||||
return &summary
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func ToPurchaseListDTOs(items []entity.Purchase) []PurchaseListItemDTO {
|
||||
return result
|
||||
}
|
||||
|
||||
func toPurchaseApprovalDTO(p entity.Purchase) *approvalDTO.ApprovalBaseDTO {
|
||||
func toPurchaseApprovalDTO(p entity.Purchase) *approvalDTO.ApprovalRelationDTO {
|
||||
if p.LatestApproval == nil || p.LatestApproval.Id == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type UserBaseDTO struct {
|
||||
type UserRelationDTO struct {
|
||||
Id uint `json:"id"`
|
||||
IdUser int64 `json:"id_user"`
|
||||
Email string `json:"email"`
|
||||
@@ -16,7 +16,7 @@ type UserBaseDTO struct {
|
||||
}
|
||||
|
||||
type UserListDTO struct {
|
||||
UserBaseDTO
|
||||
UserRelationDTO
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
@@ -27,8 +27,8 @@ type UserDetailDTO struct {
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToUserBaseDTO(m entity.User) UserBaseDTO {
|
||||
return UserBaseDTO{
|
||||
func ToUserRelationDTO(m entity.User) UserRelationDTO {
|
||||
return UserRelationDTO{
|
||||
Id: m.Id,
|
||||
IdUser: m.IdUser,
|
||||
Email: m.Email,
|
||||
@@ -38,9 +38,9 @@ func ToUserBaseDTO(m entity.User) UserBaseDTO {
|
||||
|
||||
func ToUserListDTO(m entity.User) UserListDTO {
|
||||
return UserListDTO{
|
||||
UserBaseDTO: ToUserBaseDTO(m),
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
UserRelationDTO: ToUserRelationDTO(m),
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user