diff --git a/internal/modules/marketing/delivery-orderss/dto/delivery-orders.dto.go b/internal/modules/marketing/delivery-orderss/dto/delivery-orders.dto.go index b3ac5a05..d2f29fe9 100644 --- a/internal/modules/marketing/delivery-orderss/dto/delivery-orders.dto.go +++ b/internal/modules/marketing/delivery-orderss/dto/delivery-orders.dto.go @@ -21,27 +21,27 @@ type MarketingRelationDTO struct { type MarketingListDTO struct { 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"` + Customer customerDTO.CustomerRelationDTO `json:"customer"` + SalesPerson userDTO.UserRelationDTO `json:"sales_person"` + SoDocs string `json:"so_docs"` + SalesOrder []MarketingProductDTO `json:"sales_order"` + CreatedUser userDTO.UserRelationDTO `json:"created_user"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + LatestApproval approvalDTO.ApprovalRelationDTO `json:"latest_approval"` } type MarketingDetailDTO struct { 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"` + Customer customerDTO.CustomerRelationDTO `json:"customer"` + SalesPerson userDTO.UserRelationDTO `json:"sales_person"` + SoDocs string `json:"so_docs"` + SalesOrder []MarketingProductDTO `json:"sales_order"` + DeliveryOrder []DeliveryGroupDTO `json:"delivery_order"` + CreatedUser userDTO.UserRelationDTO `json:"created_user"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + LatestApproval approvalDTO.ApprovalRelationDTO `json:"latest_approval"` } type MarketingDeliveryProductDTO struct { Id uint `json:"id"` @@ -131,28 +131,28 @@ func ToMarketingDeliveryProductDTO(e entity.MarketingDeliveryProduct) MarketingD } func ToMarketingListDTO(marketing *entity.Marketing, deliveryProducts []entity.MarketingDeliveryProduct) MarketingListDTO { - var createdUser *userDTO.UserRelationDTO + var createdUser userDTO.UserRelationDTO if marketing.CreatedUser.Id != 0 { mapped := userDTO.ToUserRelationDTO(marketing.CreatedUser) - createdUser = &mapped + createdUser = mapped } - var customer *customerDTO.CustomerRelationDTO + var customer customerDTO.CustomerRelationDTO if marketing.Customer.Id != 0 { mapped := customerDTO.ToCustomerRelationDTO(marketing.Customer) - customer = &mapped + customer = mapped } - var salesPerson *userDTO.UserRelationDTO + var salesPerson userDTO.UserRelationDTO if marketing.SalesPerson.Id != 0 { mapped := userDTO.ToUserRelationDTO(marketing.SalesPerson) - salesPerson = &mapped + salesPerson = mapped } - var latestApproval *approvalDTO.ApprovalRelationDTO + var latestApproval approvalDTO.ApprovalRelationDTO if marketing.LatestApproval != nil { mapped := approvalDTO.ToApprovalDTO(*marketing.LatestApproval) - latestApproval = &mapped + latestApproval = mapped } var salesOrderProducts []MarketingProductDTO @@ -177,22 +177,22 @@ func ToMarketingListDTO(marketing *entity.Marketing, deliveryProducts []entity.M } func ToMarketingDetailDTO(marketing *entity.Marketing, deliveryProducts []entity.MarketingDeliveryProduct) MarketingDetailDTO { - var createdUser *userDTO.UserRelationDTO + var createdUser userDTO.UserRelationDTO if marketing.CreatedUser.Id != 0 { mapped := userDTO.ToUserRelationDTO(marketing.CreatedUser) - createdUser = &mapped + createdUser = mapped } - var customer *customerDTO.CustomerRelationDTO + var customer customerDTO.CustomerRelationDTO if marketing.Customer.Id != 0 { mapped := customerDTO.ToCustomerRelationDTO(marketing.Customer) - customer = &mapped + customer = mapped } - var salesPerson *userDTO.UserRelationDTO + var salesPerson userDTO.UserRelationDTO if marketing.SalesPerson.Id != 0 { mapped := userDTO.ToUserRelationDTO(marketing.SalesPerson) - salesPerson = &mapped + salesPerson = mapped } var salesOrderProducts []MarketingProductDTO @@ -214,10 +214,10 @@ func ToMarketingDetailDTO(marketing *entity.Marketing, deliveryProducts []entity deliveryGroups := groupDeliveryProducts(deliveryProductsDTOs, marketing.SoNumber) - var latestApproval *approvalDTO.ApprovalRelationDTO + var latestApproval approvalDTO.ApprovalRelationDTO if marketing.LatestApproval != nil { mapped := approvalDTO.ToApprovalDTO(*marketing.LatestApproval) - latestApproval = &mapped + latestApproval = mapped } return MarketingDetailDTO{ diff --git a/internal/modules/marketing/sales-orders/services/sales-orders.service.go b/internal/modules/marketing/sales-orders/services/sales-orders.service.go index c1cd8f5f..d750c4a4 100644 --- a/internal/modules/marketing/sales-orders/services/sales-orders.service.go +++ b/internal/modules/marketing/sales-orders/services/sales-orders.service.go @@ -58,7 +58,7 @@ func (s salesOrdersService) withRelations(db *gorm.DB) *gorm.DB { Preload("CreatedUser"). Preload("Customer"). Preload("SalesPerson"). - Preload("Products.ProductWarehouse.Product"). + Preload("Products.ProductWarehouse.Product.Flags"). Preload("Products.ProductWarehouse.Warehouse") } diff --git a/internal/modules/master/customers/dto/customer.dto.go b/internal/modules/master/customers/dto/customer.dto.go index 333c1297..444c6768 100644 --- a/internal/modules/master/customers/dto/customer.dto.go +++ b/internal/modules/master/customers/dto/customer.dto.go @@ -10,24 +10,28 @@ import ( // === DTO Structs === type CustomerRelationDTO struct { - Id uint `json:"id"` - Name string `json:"name"` - PicId uint `json:"pic_id"` - Type string `json:"type"` - Address string `json:"address"` - Phone string `json:"phone"` - Email string `json:"email"` - AccountNumber string `json:"account_number"` - Balance float64 `json:"balance"` - - Pic *userDTO.UserRelationDTO `json:"pic,omitempty"` + Id uint `json:"id"` + Name string `json:"name"` + Type string `json:"type"` + AccountNumber string `json:"account_number"` + Balance float64 `json:"balance"` + Pic *userDTO.UserRelationDTO `json:"pic,omitempty"` } type CustomerListDTO struct { - CustomerRelationDTO - CreatedUser *userDTO.UserRelationDTO `json:"created_user"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` + Id uint `json:"id"` + Name string `json:"name"` + PicId uint `json:"pic_id"` + Type string `json:"type"` + Address string `json:"address"` + Phone string `json:"phone"` + Email string `json:"email"` + AccountNumber string `json:"account_number"` + Balance float64 `json:"balance"` + Pic userDTO.UserRelationDTO `json:"pic"` + CreatedUser userDTO.UserRelationDTO `json:"created_user"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } type CustomerDetailDTO struct { @@ -44,6 +48,28 @@ func ToCustomerRelationDTO(e entity.Customer) CustomerRelationDTO { } return CustomerRelationDTO{ + Id: e.Id, + Name: e.Name, + Type: e.Type, + AccountNumber: e.AccountNumber, + Pic: pic, + } +} + +func ToCustomerListDTO(e entity.Customer) CustomerListDTO { + var createdUser userDTO.UserRelationDTO + if e.CreatedUser.Id != 0 { + mapped := userDTO.ToUserRelationDTO(e.CreatedUser) + createdUser = mapped + } + + var pic userDTO.UserRelationDTO + if e.Pic.Id != 0 { + mapped := userDTO.ToUserRelationDTO(e.Pic) + pic = mapped + } + + return CustomerListDTO{ Id: e.Id, Name: e.Name, PicId: e.PicId, @@ -53,21 +79,9 @@ func ToCustomerRelationDTO(e entity.Customer) CustomerRelationDTO { Email: e.Email, AccountNumber: e.AccountNumber, Pic: pic, - } -} - -func ToCustomerListDTO(e entity.Customer) CustomerListDTO { - var createdUser *userDTO.UserRelationDTO - if e.CreatedUser.Id != 0 { - mapped := userDTO.ToUserRelationDTO(e.CreatedUser) - createdUser = &mapped - } - - return CustomerListDTO{ - CustomerRelationDTO: ToCustomerRelationDTO(e), - CreatedAt: e.CreatedAt, - UpdatedAt: e.UpdatedAt, - CreatedUser: createdUser, + CreatedAt: e.CreatedAt, + UpdatedAt: e.UpdatedAt, + CreatedUser: createdUser, } } diff --git a/internal/modules/master/kandangs/dto/kandang.dto.go b/internal/modules/master/kandangs/dto/kandang.dto.go index 9f99d5fa..1584b07f 100644 --- a/internal/modules/master/kandangs/dto/kandang.dto.go +++ b/internal/modules/master/kandangs/dto/kandang.dto.go @@ -11,12 +11,12 @@ import ( // === DTO Structs === 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"` + 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 { @@ -38,16 +38,16 @@ type KandangDetailDTO struct { // === Mapper Functions === func ToKandangRelationDTO(e entity.Kandang) KandangRelationDTO { - var location locationDTO.LocationRelationDTO + var location *locationDTO.LocationRelationDTO if e.Location.Id != 0 { mapped := locationDTO.ToLocationRelationDTO(e.Location) - location = mapped + location = &mapped } - var pic userDTO.UserRelationDTO + var pic *userDTO.UserRelationDTO if e.Pic.Id != 0 { mapped := userDTO.ToUserRelationDTO(e.Pic) - pic = mapped + pic = &mapped } return KandangRelationDTO{ diff --git a/internal/modules/master/products/dto/product.dto.go b/internal/modules/master/products/dto/product.dto.go index f676f994..3b2370b2 100644 --- a/internal/modules/master/products/dto/product.dto.go +++ b/internal/modules/master/products/dto/product.dto.go @@ -17,7 +17,7 @@ type ProductRelationDTO struct { 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"` + Flags *[]string `json:"flags,omitempty"` } type ProductListDTO struct { @@ -56,10 +56,12 @@ func ToProductRelationDTO(e entity.Product) ProductRelationDTO { } return ProductRelationDTO{ - Id: e.Id, - Name: e.Name, - Flags: flags, - Uom: uomRef, + Id: e.Id, + Name: e.Name, + ProductPrice: e.ProductPrice, + SellingPrice: e.SellingPrice, + Flags: &flags, + Uom: uomRef, } } diff --git a/internal/modules/production/project_flocks/services/projectflock.service.go b/internal/modules/production/project_flocks/services/projectflock.service.go index 7e3b94cb..f40ea97b 100644 --- a/internal/modules/production/project_flocks/services/projectflock.service.go +++ b/internal/modules/production/project_flocks/services/projectflock.service.go @@ -10,6 +10,7 @@ import ( commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository" commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service" entity "gitlab.com/mbugroup/lti-api.git/internal/entities" + // authmiddleware "gitlab.com/mbugroup/lti-api.git/internal/middleware" productWarehouseRepository "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories" flockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto" @@ -124,7 +125,7 @@ func (s projectflockService) GetAll(c *fiber.Ctx, params *validation.Query) ([]e } latestMap, err := s.ApprovalSvc.LatestByTargets(c.Context(), s.approvalWorkflow, ids, func(db *gorm.DB) *gorm.DB { - return db.Preload("ActionUser") + return s.withRelations(db) }) if err != nil { s.Log.Warnf("Unable to load latest approvals for projectflocks: %+v", err) @@ -170,7 +171,7 @@ func (s projectflockService) getOneEntityOnly(c *fiber.Ctx, id uint) (*entity.Pr if s.ApprovalSvc != nil { approvals, err := s.ApprovalSvc.ListByTarget(c.Context(), s.approvalWorkflow, id, func(db *gorm.DB) *gorm.DB { - return db.Preload("ActionUser") + return s.withRelations(db) }) if err != nil { s.Log.Warnf("Unable to load approvals for projectflock %d: %+v", id, err) @@ -199,7 +200,7 @@ func (s projectflockService) GetOne(c *fiber.Ctx, id uint) (*entity.ProjectFlock if s.ApprovalSvc != nil { approvals, err := s.ApprovalSvc.ListByTarget(c.Context(), s.approvalWorkflow, id, func(db *gorm.DB) *gorm.DB { - return db.Preload("ActionUser") + return s.withRelations(db) }) if err != nil { s.Log.Warnf("Unable to load approvals for projectflock %d: %+v", id, err) @@ -1098,11 +1099,11 @@ func (s projectflockService) kandangRepoWithTx(tx *gorm.DB) kandangRepository.Ka return kandangRepository.NewKandangRepository(s.Repository.DB()) } -func actorIDFromContext(c *fiber.Ctx) (uint, error) { +func actorIDFromContext(_ *fiber.Ctx) (uint, error) { // user, ok := authmiddleware.AuthenticatedUser(c) // if !ok || user == nil || user.Id == 0 { // return 0, fiber.NewError(fiber.StatusUnauthorized, "Please authenticate") // } // return user.Id, nil - return 1,nil + return 1, nil }