wms-be/modules/uom/dto/uom_dto.go

75 lines
2.3 KiB
Go

package dto
import (
"errors"
"github.com/Caknoooo/go-gin-clean-starter/database/entities"
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
)
const (
MESSAGE_FAILED_CREATE_UOM = "failed create uom"
MESSAGE_SUCCESS_CREATE_UOM = "success create uom"
MESSAGE_FAILED_GET_UOM = "failed get uom"
MESSAGE_SUCCESS_GET_UOM = "success get uom"
MESSAGE_FAILED_UPDATE_UOM = "failed update uom"
MESSAGE_SUCCESS_UPDATE_UOM = "success update uom"
MESSAGE_FAILED_DELETE_UOM = "failed delete uom"
MESSAGE_SUCCESS_DELETE_UOM = "success delete uom"
MESSAGE_FAILED_GET_DATA_FROM_BODY = "failed get data from body"
)
var (
ErrCreateUom = errors.New("failed to create uom")
ErrGetUomById = errors.New("failed to get uom by id")
ErrUpdateUom = errors.New("failed to update uom")
ErrDeleteUom = errors.New("failed to delete uom")
)
type UomCreateRequest struct {
Name string `json:"name" binding:"required"`
Description string `json:"description"`
Symbol string `json:"symbol"`
// Code string `json:"code"`
StdPrecision int `json:"std_precision"`
IsActive bool `json:"is_active"`
ClientID string `json:"client_id" binding:"required"`
}
type UomUpdateRequest struct {
Name string `json:"name"`
Description string `json:"description"`
Symbol string `json:"symbol"`
Code string `json:"code"`
StdPrecision int `json:"std_precision"`
IsActive bool `json:"is_active"`
ClientID string `json:"client_id"`
}
type UomResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Symbol string `json:"symbol"`
Code string `json:"code"`
StdPrecision int `json:"std_precision"`
IsActive bool `json:"is_active"`
Client pkgdto.ClientResponse `json:"client"`
}
func ToUomResponse(e entities.MUomEntity) UomResponse {
return UomResponse{
ID: e.ID.String(),
Name: e.Name,
Description: e.Description,
Symbol: e.Symbol,
Code: e.Code,
StdPrecision: e.StdPrecision,
IsActive: e.IsActive,
Client: pkgdto.ClientResponse{
ID: e.Client.ID.String(),
Name: e.Client.Name,
},
}
}