mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
184 lines
4.6 KiB
Go
184 lines
4.6 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 ProjectFlockBaseDTO struct {
|
|
Id uint `json:"id"`
|
|
// FlockId uint `json:"flock_id"`
|
|
// AreaId uint `json:"area_id"`
|
|
// ProductCategoryId uint `json:"product_category_id"`
|
|
// FcrId uint `json:"fcr_id"`
|
|
// LocationId uint `json:"location_id"`
|
|
Period int `json:"period"`
|
|
}
|
|
|
|
func ToProjectFlockBaseDTO(e entity.ProjectFlock) ProjectFlockBaseDTO {
|
|
return ProjectFlockBaseDTO{
|
|
Id: e.Id,
|
|
// FlockId: e.FlockId,
|
|
// AreaId: e.AreaId,
|
|
// ProductCategoryId: e.ProductCategoryId,
|
|
// FcrId: e.FcrId,
|
|
// LocationId: e.LocationId,
|
|
Period: e.Period,
|
|
}
|
|
}
|
|
|
|
type FlockSummaryDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type AreaSummaryDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type ProductCategorySummaryDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
Code string `json:"code"`
|
|
}
|
|
|
|
type FcrSummaryDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type LocationSummaryDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
Address string `json:"address"`
|
|
}
|
|
|
|
type KandangSummaryDTO struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
type ProjectFlockListDTO struct {
|
|
ProjectFlockBaseDTO
|
|
Flock *FlockSummaryDTO `json:"flock,omitempty"`
|
|
Area *AreaSummaryDTO `json:"area,omitempty"`
|
|
ProductCategory *ProductCategorySummaryDTO `json:"product_category,omitempty"`
|
|
Fcr *FcrSummaryDTO `json:"fcr,omitempty"`
|
|
Location *LocationSummaryDTO `json:"location,omitempty"`
|
|
Kandangs []KandangSummaryDTO `json:"kandangs,omitempty"`
|
|
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type ProjectFlockDetailDTO struct {
|
|
ProjectFlockListDTO
|
|
}
|
|
|
|
type FlockPeriodSummaryDTO struct {
|
|
Flock FlockSummaryDTO `json:"flock"`
|
|
NextPeriod int `json:"next_period"`
|
|
}
|
|
|
|
func ToProjectFlockListDTO(e entity.ProjectFlock) ProjectFlockListDTO {
|
|
var createdUser *userDTO.UserBaseDTO
|
|
if e.CreatedUser.Id != 0 {
|
|
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
|
|
createdUser = &mapped
|
|
}
|
|
|
|
var flockSummary *FlockSummaryDTO
|
|
if e.Flock.Id != 0 {
|
|
summary := ToFlockSummaryDTO(e.Flock)
|
|
flockSummary = &summary
|
|
}
|
|
|
|
var areaSummary *AreaSummaryDTO
|
|
if e.Area.Id != 0 {
|
|
areaSummary = &AreaSummaryDTO{
|
|
Id: e.Area.Id,
|
|
Name: e.Area.Name,
|
|
}
|
|
}
|
|
|
|
var categorySummary *ProductCategorySummaryDTO
|
|
if e.ProductCategory.Id != 0 {
|
|
categorySummary = &ProductCategorySummaryDTO{
|
|
Id: e.ProductCategory.Id,
|
|
Name: e.ProductCategory.Name,
|
|
Code: e.ProductCategory.Code,
|
|
}
|
|
}
|
|
|
|
var fcrSummary *FcrSummaryDTO
|
|
if e.Fcr.Id != 0 {
|
|
fcrSummary = &FcrSummaryDTO{
|
|
Id: e.Fcr.Id,
|
|
Name: e.Fcr.Name,
|
|
}
|
|
}
|
|
|
|
var locationSummary *LocationSummaryDTO
|
|
if e.Location.Id != 0 {
|
|
locationSummary = &LocationSummaryDTO{
|
|
Id: e.Location.Id,
|
|
Name: e.Location.Name,
|
|
Address: e.Location.Address,
|
|
}
|
|
}
|
|
|
|
kandangSummaries := make([]KandangSummaryDTO, len(e.Kandangs))
|
|
for i, kandang := range e.Kandangs {
|
|
kandangSummaries[i] = KandangSummaryDTO{
|
|
Id: kandang.Id,
|
|
Name: kandang.Name,
|
|
Status: kandang.Status,
|
|
}
|
|
}
|
|
|
|
return ProjectFlockListDTO{
|
|
ProjectFlockBaseDTO: ToProjectFlockBaseDTO(e),
|
|
Flock: flockSummary,
|
|
Area: areaSummary,
|
|
ProductCategory: categorySummary,
|
|
Fcr: fcrSummary,
|
|
Location: locationSummary,
|
|
Kandangs: kandangSummaries,
|
|
CreatedAt: e.CreatedAt,
|
|
UpdatedAt: e.UpdatedAt,
|
|
CreatedUser: createdUser,
|
|
}
|
|
}
|
|
|
|
func ToProjectFlockListDTOs(items []entity.ProjectFlock) []ProjectFlockListDTO {
|
|
result := make([]ProjectFlockListDTO, len(items))
|
|
for i, item := range items {
|
|
result[i] = ToProjectFlockListDTO(item)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ToProjectFlockDetailDTO(e entity.ProjectFlock) ProjectFlockDetailDTO {
|
|
return ProjectFlockDetailDTO{
|
|
ProjectFlockListDTO: ToProjectFlockListDTO(e),
|
|
}
|
|
}
|
|
|
|
func ToFlockSummaryDTO(e entity.Flock) FlockSummaryDTO {
|
|
return FlockSummaryDTO{
|
|
Id: e.Id,
|
|
Name: e.Name,
|
|
}
|
|
}
|
|
|
|
func ToFlockPeriodSummaryDTO(flock entity.Flock, next int) FlockPeriodSummaryDTO {
|
|
return FlockPeriodSummaryDTO{
|
|
Flock: ToFlockSummaryDTO(flock),
|
|
NextPeriod: next,
|
|
}
|
|
}
|