mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +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 {
|
type MarketingListDTO struct {
|
||||||
MarketingRelationDTO
|
MarketingRelationDTO
|
||||||
Customer *customerDTO.CustomerRelationDTO `json:"customer,omitempty"`
|
Customer customerDTO.CustomerRelationDTO `json:"customer"`
|
||||||
SalesPerson *userDTO.UserRelationDTO `json:"sales_person,omitempty"`
|
SalesPerson userDTO.UserRelationDTO `json:"sales_person"`
|
||||||
SoDocs string `json:"so_docs,omitempty"`
|
SoDocs string `json:"so_docs"`
|
||||||
SalesOrder []MarketingProductDTO `json:"sales_order,omitempty"`
|
SalesOrder []MarketingProductDTO `json:"sales_order"`
|
||||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
CreatedUser userDTO.UserRelationDTO `json:"created_user"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
LatestApproval *approvalDTO.ApprovalRelationDTO `json:"latest_approval,omitempty"`
|
LatestApproval approvalDTO.ApprovalRelationDTO `json:"latest_approval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MarketingDetailDTO struct {
|
type MarketingDetailDTO struct {
|
||||||
MarketingRelationDTO
|
MarketingRelationDTO
|
||||||
Customer *customerDTO.CustomerRelationDTO `json:"customer,omitempty"`
|
Customer customerDTO.CustomerRelationDTO `json:"customer"`
|
||||||
SalesPerson *userDTO.UserRelationDTO `json:"sales_person,omitempty"`
|
SalesPerson userDTO.UserRelationDTO `json:"sales_person"`
|
||||||
SoDocs string `json:"so_docs,omitempty"`
|
SoDocs string `json:"so_docs"`
|
||||||
SalesOrder []MarketingProductDTO `json:"sales_order,omitempty"`
|
SalesOrder []MarketingProductDTO `json:"sales_order"`
|
||||||
DeliveryOrder []DeliveryGroupDTO `json:"delivery_order,omitempty"`
|
DeliveryOrder []DeliveryGroupDTO `json:"delivery_order"`
|
||||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
CreatedUser userDTO.UserRelationDTO `json:"created_user"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
LatestApproval *approvalDTO.ApprovalRelationDTO `json:"latest_approval,omitempty"`
|
LatestApproval approvalDTO.ApprovalRelationDTO `json:"latest_approval"`
|
||||||
}
|
}
|
||||||
type MarketingDeliveryProductDTO struct {
|
type MarketingDeliveryProductDTO struct {
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
@@ -131,28 +131,28 @@ func ToMarketingDeliveryProductDTO(e entity.MarketingDeliveryProduct) MarketingD
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ToMarketingListDTO(marketing *entity.Marketing, deliveryProducts []entity.MarketingDeliveryProduct) MarketingListDTO {
|
func ToMarketingListDTO(marketing *entity.Marketing, deliveryProducts []entity.MarketingDeliveryProduct) MarketingListDTO {
|
||||||
var createdUser *userDTO.UserRelationDTO
|
var createdUser userDTO.UserRelationDTO
|
||||||
if marketing.CreatedUser.Id != 0 {
|
if marketing.CreatedUser.Id != 0 {
|
||||||
mapped := userDTO.ToUserRelationDTO(marketing.CreatedUser)
|
mapped := userDTO.ToUserRelationDTO(marketing.CreatedUser)
|
||||||
createdUser = &mapped
|
createdUser = mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
var customer *customerDTO.CustomerRelationDTO
|
var customer customerDTO.CustomerRelationDTO
|
||||||
if marketing.Customer.Id != 0 {
|
if marketing.Customer.Id != 0 {
|
||||||
mapped := customerDTO.ToCustomerRelationDTO(marketing.Customer)
|
mapped := customerDTO.ToCustomerRelationDTO(marketing.Customer)
|
||||||
customer = &mapped
|
customer = mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
var salesPerson *userDTO.UserRelationDTO
|
var salesPerson userDTO.UserRelationDTO
|
||||||
if marketing.SalesPerson.Id != 0 {
|
if marketing.SalesPerson.Id != 0 {
|
||||||
mapped := userDTO.ToUserRelationDTO(marketing.SalesPerson)
|
mapped := userDTO.ToUserRelationDTO(marketing.SalesPerson)
|
||||||
salesPerson = &mapped
|
salesPerson = mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
var latestApproval *approvalDTO.ApprovalRelationDTO
|
var latestApproval approvalDTO.ApprovalRelationDTO
|
||||||
if marketing.LatestApproval != nil {
|
if marketing.LatestApproval != nil {
|
||||||
mapped := approvalDTO.ToApprovalDTO(*marketing.LatestApproval)
|
mapped := approvalDTO.ToApprovalDTO(*marketing.LatestApproval)
|
||||||
latestApproval = &mapped
|
latestApproval = mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
var salesOrderProducts []MarketingProductDTO
|
var salesOrderProducts []MarketingProductDTO
|
||||||
@@ -177,22 +177,22 @@ func ToMarketingListDTO(marketing *entity.Marketing, deliveryProducts []entity.M
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ToMarketingDetailDTO(marketing *entity.Marketing, deliveryProducts []entity.MarketingDeliveryProduct) MarketingDetailDTO {
|
func ToMarketingDetailDTO(marketing *entity.Marketing, deliveryProducts []entity.MarketingDeliveryProduct) MarketingDetailDTO {
|
||||||
var createdUser *userDTO.UserRelationDTO
|
var createdUser userDTO.UserRelationDTO
|
||||||
if marketing.CreatedUser.Id != 0 {
|
if marketing.CreatedUser.Id != 0 {
|
||||||
mapped := userDTO.ToUserRelationDTO(marketing.CreatedUser)
|
mapped := userDTO.ToUserRelationDTO(marketing.CreatedUser)
|
||||||
createdUser = &mapped
|
createdUser = mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
var customer *customerDTO.CustomerRelationDTO
|
var customer customerDTO.CustomerRelationDTO
|
||||||
if marketing.Customer.Id != 0 {
|
if marketing.Customer.Id != 0 {
|
||||||
mapped := customerDTO.ToCustomerRelationDTO(marketing.Customer)
|
mapped := customerDTO.ToCustomerRelationDTO(marketing.Customer)
|
||||||
customer = &mapped
|
customer = mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
var salesPerson *userDTO.UserRelationDTO
|
var salesPerson userDTO.UserRelationDTO
|
||||||
if marketing.SalesPerson.Id != 0 {
|
if marketing.SalesPerson.Id != 0 {
|
||||||
mapped := userDTO.ToUserRelationDTO(marketing.SalesPerson)
|
mapped := userDTO.ToUserRelationDTO(marketing.SalesPerson)
|
||||||
salesPerson = &mapped
|
salesPerson = mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
var salesOrderProducts []MarketingProductDTO
|
var salesOrderProducts []MarketingProductDTO
|
||||||
@@ -214,10 +214,10 @@ func ToMarketingDetailDTO(marketing *entity.Marketing, deliveryProducts []entity
|
|||||||
|
|
||||||
deliveryGroups := groupDeliveryProducts(deliveryProductsDTOs, marketing.SoNumber)
|
deliveryGroups := groupDeliveryProducts(deliveryProductsDTOs, marketing.SoNumber)
|
||||||
|
|
||||||
var latestApproval *approvalDTO.ApprovalRelationDTO
|
var latestApproval approvalDTO.ApprovalRelationDTO
|
||||||
if marketing.LatestApproval != nil {
|
if marketing.LatestApproval != nil {
|
||||||
mapped := approvalDTO.ToApprovalDTO(*marketing.LatestApproval)
|
mapped := approvalDTO.ToApprovalDTO(*marketing.LatestApproval)
|
||||||
latestApproval = &mapped
|
latestApproval = mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
return MarketingDetailDTO{
|
return MarketingDetailDTO{
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ func (s salesOrdersService) withRelations(db *gorm.DB) *gorm.DB {
|
|||||||
Preload("CreatedUser").
|
Preload("CreatedUser").
|
||||||
Preload("Customer").
|
Preload("Customer").
|
||||||
Preload("SalesPerson").
|
Preload("SalesPerson").
|
||||||
Preload("Products.ProductWarehouse.Product").
|
Preload("Products.ProductWarehouse.Product.Flags").
|
||||||
Preload("Products.ProductWarehouse.Warehouse")
|
Preload("Products.ProductWarehouse.Warehouse")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,24 +10,28 @@ import (
|
|||||||
// === DTO Structs ===
|
// === DTO Structs ===
|
||||||
|
|
||||||
type CustomerRelationDTO struct {
|
type CustomerRelationDTO struct {
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
PicId uint `json:"pic_id"`
|
Type string `json:"type"`
|
||||||
Type string `json:"type"`
|
AccountNumber string `json:"account_number"`
|
||||||
Address string `json:"address"`
|
Balance float64 `json:"balance"`
|
||||||
Phone string `json:"phone"`
|
Pic *userDTO.UserRelationDTO `json:"pic,omitempty"`
|
||||||
Email string `json:"email"`
|
|
||||||
AccountNumber string `json:"account_number"`
|
|
||||||
Balance float64 `json:"balance"`
|
|
||||||
|
|
||||||
Pic *userDTO.UserRelationDTO `json:"pic,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomerListDTO struct {
|
type CustomerListDTO struct {
|
||||||
CustomerRelationDTO
|
Id uint `json:"id"`
|
||||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
Name string `json:"name"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
PicId uint `json:"pic_id"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
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 {
|
type CustomerDetailDTO struct {
|
||||||
@@ -44,6 +48,28 @@ func ToCustomerRelationDTO(e entity.Customer) CustomerRelationDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 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,
|
Id: e.Id,
|
||||||
Name: e.Name,
|
Name: e.Name,
|
||||||
PicId: e.PicId,
|
PicId: e.PicId,
|
||||||
@@ -53,21 +79,9 @@ func ToCustomerRelationDTO(e entity.Customer) CustomerRelationDTO {
|
|||||||
Email: e.Email,
|
Email: e.Email,
|
||||||
AccountNumber: e.AccountNumber,
|
AccountNumber: e.AccountNumber,
|
||||||
Pic: pic,
|
Pic: pic,
|
||||||
}
|
CreatedAt: e.CreatedAt,
|
||||||
}
|
UpdatedAt: e.UpdatedAt,
|
||||||
|
CreatedUser: createdUser,
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ import (
|
|||||||
// === DTO Structs ===
|
// === DTO Structs ===
|
||||||
|
|
||||||
type KandangRelationDTO struct {
|
type KandangRelationDTO struct {
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Capacity float64 `json:"capacity"`
|
Capacity float64 `json:"capacity"`
|
||||||
Location locationDTO.LocationRelationDTO `json:"location,omitempty"`
|
Location *locationDTO.LocationRelationDTO `json:"location,omitempty"`
|
||||||
Pic userDTO.UserRelationDTO `json:"pic,omitempty"`
|
Pic *userDTO.UserRelationDTO `json:"pic,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KandangListDTO struct {
|
type KandangListDTO struct {
|
||||||
@@ -38,16 +38,16 @@ type KandangDetailDTO struct {
|
|||||||
// === Mapper Functions ===
|
// === Mapper Functions ===
|
||||||
|
|
||||||
func ToKandangRelationDTO(e entity.Kandang) KandangRelationDTO {
|
func ToKandangRelationDTO(e entity.Kandang) KandangRelationDTO {
|
||||||
var location locationDTO.LocationRelationDTO
|
var location *locationDTO.LocationRelationDTO
|
||||||
if e.Location.Id != 0 {
|
if e.Location.Id != 0 {
|
||||||
mapped := locationDTO.ToLocationRelationDTO(e.Location)
|
mapped := locationDTO.ToLocationRelationDTO(e.Location)
|
||||||
location = mapped
|
location = &mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
var pic userDTO.UserRelationDTO
|
var pic *userDTO.UserRelationDTO
|
||||||
if e.Pic.Id != 0 {
|
if e.Pic.Id != 0 {
|
||||||
mapped := userDTO.ToUserRelationDTO(e.Pic)
|
mapped := userDTO.ToUserRelationDTO(e.Pic)
|
||||||
pic = mapped
|
pic = &mapped
|
||||||
}
|
}
|
||||||
|
|
||||||
return KandangRelationDTO{
|
return KandangRelationDTO{
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ type ProductRelationDTO struct {
|
|||||||
ProductPrice float64 `gorm:"type:numeric(15,3);not null"`
|
ProductPrice float64 `gorm:"type:numeric(15,3);not null"`
|
||||||
SellingPrice *float64 `gorm:"type:numeric(15,3)"`
|
SellingPrice *float64 `gorm:"type:numeric(15,3)"`
|
||||||
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
|
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
|
||||||
Flags []string `json:"flags"`
|
Flags *[]string `json:"flags,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductListDTO struct {
|
type ProductListDTO struct {
|
||||||
@@ -56,10 +56,12 @@ func ToProductRelationDTO(e entity.Product) ProductRelationDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ProductRelationDTO{
|
return ProductRelationDTO{
|
||||||
Id: e.Id,
|
Id: e.Id,
|
||||||
Name: e.Name,
|
Name: e.Name,
|
||||||
Flags: flags,
|
ProductPrice: e.ProductPrice,
|
||||||
Uom: uomRef,
|
SellingPrice: e.SellingPrice,
|
||||||
|
Flags: &flags,
|
||||||
|
Uom: uomRef,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
||||||
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||||
|
|
||||||
// authmiddleware "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
// authmiddleware "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||||
productWarehouseRepository "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
|
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"
|
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 {
|
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 {
|
if err != nil {
|
||||||
s.Log.Warnf("Unable to load latest approvals for projectflocks: %+v", err)
|
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 {
|
if s.ApprovalSvc != nil {
|
||||||
approvals, err := s.ApprovalSvc.ListByTarget(c.Context(), s.approvalWorkflow, id, func(db *gorm.DB) *gorm.DB {
|
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 {
|
if err != nil {
|
||||||
s.Log.Warnf("Unable to load approvals for projectflock %d: %+v", id, err)
|
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 {
|
if s.ApprovalSvc != nil {
|
||||||
approvals, err := s.ApprovalSvc.ListByTarget(c.Context(), s.approvalWorkflow, id, func(db *gorm.DB) *gorm.DB {
|
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 {
|
if err != nil {
|
||||||
s.Log.Warnf("Unable to load approvals for projectflock %d: %+v", id, err)
|
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())
|
return kandangRepository.NewKandangRepository(s.Repository.DB())
|
||||||
}
|
}
|
||||||
|
|
||||||
func actorIDFromContext(c *fiber.Ctx) (uint, error) {
|
func actorIDFromContext(_ *fiber.Ctx) (uint, error) {
|
||||||
// user, ok := authmiddleware.AuthenticatedUser(c)
|
// user, ok := authmiddleware.AuthenticatedUser(c)
|
||||||
// if !ok || user == nil || user.Id == 0 {
|
// if !ok || user == nil || user.Id == 0 {
|
||||||
// return 0, fiber.NewError(fiber.StatusUnauthorized, "Please authenticate")
|
// return 0, fiber.NewError(fiber.StatusUnauthorized, "Please authenticate")
|
||||||
// }
|
// }
|
||||||
// return user.Id, nil
|
// return user.Id, nil
|
||||||
return 1,nil
|
return 1, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user