mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
142 lines
4.0 KiB
Go
142 lines
4.0 KiB
Go
package dto
|
|
|
|
import (
|
|
"time"
|
|
|
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
|
productCategoryDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/product-categories/dto"
|
|
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
|
)
|
|
|
|
// === DTO Structs ===
|
|
|
|
type ProductRelationDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
SKU string `json:"sku"`
|
|
ProductCategory *productCategoryDTO.ProductCategoryRelationDTO `json:"product_category,omitempty"`
|
|
}
|
|
|
|
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 *ProductRelationDTO `json:"product,omitempty"`
|
|
Warehouse *WarehouseRelationDTO `json:"warehouse,omitempty"`
|
|
}
|
|
|
|
type AdjustmentRelationDTO struct {
|
|
Id uint `json:"id"`
|
|
TransactionType string `json:"transaction_type"`
|
|
Quantity float64 `json:"quantity"`
|
|
BeforeQuantity float64 `json:"before_quantity"`
|
|
AfterQuantity float64 `json:"after_quantity"`
|
|
Note string `json:"note,omitempty"`
|
|
ProductWarehouseId uint `json:"product_warehouse_id"`
|
|
ProductWarehouse *ProductWarehouseDTO `json:"product_warehouse,omitempty"`
|
|
}
|
|
|
|
type AdjustmentListDTO struct {
|
|
AdjustmentRelationDTO
|
|
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type AdjustmentDetailDTO struct {
|
|
AdjustmentListDTO
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// === Mapper Functions ===
|
|
|
|
func ToProductRelationDTO(e *entity.Product) *ProductRelationDTO {
|
|
if e == nil {
|
|
return nil
|
|
}
|
|
sku := ""
|
|
if e.Sku != nil {
|
|
sku = *e.Sku
|
|
}
|
|
|
|
var category *productCategoryDTO.ProductCategoryRelationDTO
|
|
if e.ProductCategory.Id != 0 {
|
|
mapped := productCategoryDTO.ToProductCategoryRelationDTO(e.ProductCategory)
|
|
category = &mapped
|
|
}
|
|
|
|
return &ProductRelationDTO{
|
|
Id: e.Id,
|
|
Name: e.Name,
|
|
SKU: sku,
|
|
ProductCategory: category,
|
|
}
|
|
}
|
|
|
|
func ToWarehouseRelationDTO(e *entity.Warehouse) *WarehouseRelationDTO {
|
|
if e == nil {
|
|
return nil
|
|
}
|
|
return &WarehouseRelationDTO{
|
|
Id: e.Id,
|
|
Name: e.Name,
|
|
}
|
|
}
|
|
|
|
func ToProductWarehouseDTO(e *entity.ProductWarehouse) *ProductWarehouseDTO {
|
|
if e == nil {
|
|
return nil
|
|
}
|
|
return &ProductWarehouseDTO{
|
|
Id: e.Id,
|
|
ProductId: e.ProductId,
|
|
WarehouseId: e.WarehouseId,
|
|
Quantity: e.Quantity,
|
|
Product: ToProductRelationDTO(&e.Product),
|
|
Warehouse: ToWarehouseRelationDTO(&e.Warehouse),
|
|
}
|
|
}
|
|
|
|
func ToAdjustmentRelationDTO(e *entity.StockLog) AdjustmentRelationDTO {
|
|
return AdjustmentRelationDTO{
|
|
Id: e.Id,
|
|
TransactionType: e.TransactionType,
|
|
Quantity: e.Quantity,
|
|
BeforeQuantity: e.BeforeQuantity,
|
|
AfterQuantity: e.AfterQuantity,
|
|
Note: e.Note,
|
|
ProductWarehouseId: e.ProductWarehouseId,
|
|
ProductWarehouse: ToProductWarehouseDTO(e.ProductWarehouse),
|
|
}
|
|
}
|
|
|
|
func ToAdjustmentListDTO(e *entity.StockLog) AdjustmentListDTO {
|
|
var createdUser *userDTO.UserRelationDTO
|
|
if e.CreatedUser != nil {
|
|
createdUser = &userDTO.UserRelationDTO{
|
|
Id: e.CreatedUser.Id,
|
|
IdUser: e.CreatedUser.IdUser,
|
|
Email: e.CreatedUser.Email,
|
|
Name: e.CreatedUser.Name,
|
|
}
|
|
}
|
|
|
|
return AdjustmentListDTO{
|
|
AdjustmentRelationDTO: ToAdjustmentRelationDTO(e),
|
|
CreatedUser: createdUser,
|
|
CreatedAt: e.CreatedAt,
|
|
}
|
|
}
|
|
|
|
func ToAdjustmentDetailDTO(e *entity.StockLog) AdjustmentDetailDTO {
|
|
return AdjustmentDetailDTO{
|
|
AdjustmentListDTO: ToAdjustmentListDTO(e),
|
|
UpdatedAt: e.UpdatedAt,
|
|
}
|
|
}
|