mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 15:55:44 +00:00
feat[BE]: Update TransferRelationDTO and service search logic to include warehouse names
This commit is contained in:
@@ -4,20 +4,17 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||||
|
warehouseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/dto"
|
||||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransferRelationDTO struct {
|
type TransferRelationDTO struct {
|
||||||
Id uint64 `json:"id"`
|
Id uint64 `json:"id"`
|
||||||
TransferReason string `json:"transfer_reason"`
|
MovementNumber string `json:"movement_number"`
|
||||||
TransferDate string `json:"transfer_date"`
|
TransferReason string `json:"transfer_reason"`
|
||||||
SourceWarehouse *WarehouseDetailDTO `json:"source_warehouse,omitempty"`
|
TransferDate string `json:"transfer_date"`
|
||||||
DestinationWarehouse *WarehouseDetailDTO `json:"destination_warehouse,omitempty"`
|
SourceWarehouse *warehouseDTO.WarehouseRelationDTO `json:"source_warehouse,omitempty"`
|
||||||
}
|
DestinationWarehouse *warehouseDTO.WarehouseRelationDTO `json:"destination_warehouse,omitempty"`
|
||||||
|
|
||||||
type WarehouseSimpleDTO struct {
|
|
||||||
Id uint `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductSimpleDTO struct {
|
type ProductSimpleDTO struct {
|
||||||
@@ -25,16 +22,6 @@ type ProductSimpleDTO struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AreaDTO struct {
|
|
||||||
Id uint `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type LocationDTO struct {
|
|
||||||
Id uint `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SupplierSimpleDTO struct {
|
type SupplierSimpleDTO struct {
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -48,13 +35,6 @@ type DocumentDTO struct {
|
|||||||
Size float64 `json:"size"`
|
Size float64 `json:"size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WarehouseDetailDTO struct {
|
|
||||||
Id uint `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Location *LocationDTO `json:"location"`
|
|
||||||
Area *AreaDTO `json:"area"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TransferListDTO struct {
|
type TransferListDTO struct {
|
||||||
TransferRelationDTO
|
TransferRelationDTO
|
||||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
||||||
@@ -97,16 +77,19 @@ type TransferDeliveryItemDTO struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ToTransferRelationDTO(e entity.StockTransfer) TransferRelationDTO {
|
func ToTransferRelationDTO(e entity.StockTransfer) TransferRelationDTO {
|
||||||
var sourceWarehouse *WarehouseDetailDTO
|
var sourceWarehouse *warehouseDTO.WarehouseRelationDTO
|
||||||
if e.FromWarehouse != nil && e.FromWarehouse.Id != 0 {
|
if e.FromWarehouse != nil && e.FromWarehouse.Id != 0 {
|
||||||
sourceWarehouse = toWarehouseDetailDTO(e.FromWarehouse)
|
mapped := warehouseDTO.ToWarehouseRelationDTO(*e.FromWarehouse)
|
||||||
|
sourceWarehouse = &mapped
|
||||||
}
|
}
|
||||||
var destinationWarehouse *WarehouseDetailDTO
|
var destinationWarehouse *warehouseDTO.WarehouseRelationDTO
|
||||||
if e.ToWarehouse != nil && e.ToWarehouse.Id != 0 {
|
if e.ToWarehouse != nil && e.ToWarehouse.Id != 0 {
|
||||||
destinationWarehouse = toWarehouseDetailDTO(e.ToWarehouse)
|
mapped := warehouseDTO.ToWarehouseRelationDTO(*e.ToWarehouse)
|
||||||
|
destinationWarehouse = &mapped
|
||||||
}
|
}
|
||||||
return TransferRelationDTO{
|
return TransferRelationDTO{
|
||||||
Id: e.Id,
|
Id: e.Id,
|
||||||
|
MovementNumber: e.MovementNumber,
|
||||||
TransferReason: e.Reason,
|
TransferReason: e.Reason,
|
||||||
TransferDate: e.CreatedAt.Format("2006-01-02"),
|
TransferDate: e.CreatedAt.Format("2006-01-02"),
|
||||||
SourceWarehouse: sourceWarehouse,
|
SourceWarehouse: sourceWarehouse,
|
||||||
@@ -114,38 +97,6 @@ func ToTransferRelationDTO(e entity.StockTransfer) TransferRelationDTO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toAreaDTO(a *entity.Area) *AreaDTO {
|
|
||||||
if a == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &AreaDTO{
|
|
||||||
Id: a.Id,
|
|
||||||
Name: a.Name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func toLocationDTO(l *entity.Location) *LocationDTO {
|
|
||||||
if l == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &LocationDTO{
|
|
||||||
Id: l.Id,
|
|
||||||
Name: l.Name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func toWarehouseDetailDTO(w *entity.Warehouse) *WarehouseDetailDTO {
|
|
||||||
if w == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &WarehouseDetailDTO{
|
|
||||||
Id: w.Id,
|
|
||||||
Name: w.Name,
|
|
||||||
Location: toLocationDTO(w.Location),
|
|
||||||
Area: toAreaDTO(&w.Area),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ToTransferListDTO(e entity.StockTransfer) TransferListDTO {
|
func ToTransferListDTO(e entity.StockTransfer) TransferListDTO {
|
||||||
var createdUser *userDTO.UserRelationDTO
|
var createdUser *userDTO.UserRelationDTO
|
||||||
if e.CreatedUser != nil {
|
if e.CreatedUser != nil {
|
||||||
|
|||||||
@@ -99,7 +99,11 @@ func (s transferService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
|
|||||||
transfers, total, err := s.StockTransferRepo.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
|
transfers, total, err := s.StockTransferRepo.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
|
||||||
db = s.withRelations(db)
|
db = s.withRelations(db)
|
||||||
if params.Search != "" {
|
if params.Search != "" {
|
||||||
db = db.Where("movement_number ILIKE ?", "%"+strings.TrimSpace(params.Search)+"%")
|
searchTerm := "%" + strings.TrimSpace(params.Search) + "%"
|
||||||
|
db = db.Joins("LEFT JOIN warehouses AS from_warehouses ON from_warehouses.id = stock_transfers.from_warehouse_id").
|
||||||
|
Joins("LEFT JOIN warehouses AS to_warehouses ON to_warehouses.id = stock_transfers.to_warehouse_id").
|
||||||
|
Where("movement_number ILIKE ? OR from_warehouses.name ILIKE ? OR to_warehouses.name ILIKE ?",
|
||||||
|
searchTerm, searchTerm, searchTerm)
|
||||||
}
|
}
|
||||||
return db.Order("created_at DESC").Order("updated_at DESC")
|
return db.Order("created_at DESC").Order("updated_at DESC")
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user