mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix(BE): adjust dto and project flock, master data, and marketing
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user