mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
62 lines
1.8 KiB
Go
62 lines
1.8 KiB
Go
package dto
|
|
|
|
import (
|
|
"time"
|
|
|
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
|
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
|
)
|
|
|
|
type StockLogListDTO struct {
|
|
Id uint `json:"id"`
|
|
ProductWarehouseId uint `json:"product_warehouse_id"`
|
|
Increase float64 `json:"increase"`
|
|
Decrease float64 `json:"decrease"`
|
|
Stock float64 `json:"stock"`
|
|
LoggableType string `json:"loggable_type"`
|
|
LoggableId uint `json:"loggable_id"`
|
|
Notes *string `json:"notes"`
|
|
CreatedBy uint `json:"created_by"`
|
|
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func ToStockLogListDTO(e entity.StockLog) StockLogListDTO {
|
|
var notes *string
|
|
if e.Notes != "" {
|
|
n := e.Notes
|
|
notes = &n
|
|
}
|
|
|
|
var createdUser *userDTO.UserRelationDTO
|
|
if e.CreatedUser != nil && e.CreatedUser.Id != 0 {
|
|
mapped := userDTO.ToUserRelationDTO(*e.CreatedUser)
|
|
createdUser = &mapped
|
|
}
|
|
|
|
return StockLogListDTO{
|
|
Id: e.Id,
|
|
ProductWarehouseId: e.ProductWarehouseId,
|
|
Increase: e.Increase,
|
|
Decrease: e.Decrease,
|
|
Stock: e.Stock,
|
|
LoggableType: e.LoggableType,
|
|
LoggableId: e.LoggableId,
|
|
Notes: notes,
|
|
CreatedBy: e.CreatedBy,
|
|
CreatedUser: createdUser,
|
|
CreatedAt: e.CreatedAt,
|
|
}
|
|
}
|
|
|
|
func ToStockLogListDTOs(e []entity.StockLog) []StockLogListDTO {
|
|
if len(e) == 0 {
|
|
return []StockLogListDTO{}
|
|
}
|
|
result := make([]StockLogListDTO, len(e))
|
|
for i, log := range e {
|
|
result[i] = ToStockLogListDTO(log)
|
|
}
|
|
return result
|
|
}
|