mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 23:35:43 +00:00
feat[BE#US386]: add production standards module with CRUD operations
- Created database migration for production standards and related tables. - Implemented entities for ProductionStandard, ProductionStandardDetail, and StandardGrowthDetail. - Developed controller for handling production standard requests. - Added DTOs for data transfer between layers. - Implemented service layer for business logic related to production standards. - Created repository interfaces and implementations for data access. - Added validation for production standard requests. - Registered routes for production standards in the main application.
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type ProductionStandardListDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ProjectCategory string `json:"project_category"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
|
||||
}
|
||||
|
||||
type ProductionStandardDetailDTO struct {
|
||||
ProductionStandardListDTO
|
||||
Details []WeeklyProductionStandardDTO `json:"details"`
|
||||
}
|
||||
|
||||
type GrowthStandardDetailDTO struct {
|
||||
Id uint `json:"id"`
|
||||
TargetMeanBW *float64 `json:"target_mean_bw"`
|
||||
MaxDepletion *float64 `json:"max_depletion"`
|
||||
MinUniformity float64 `json:"min_uniformity"`
|
||||
FeedIntake *float64 `json:"feed_intake"`
|
||||
}
|
||||
|
||||
type EggProductionStandardDetailDTO struct {
|
||||
Id uint `json:"id"`
|
||||
TargetHenDayProduction *float64 `json:"target_hen_day_production"`
|
||||
TargetHenHouseProduction *float64 `json:"target_hen_house_production"`
|
||||
TargetEggWeight *float64 `json:"target_egg_weight"`
|
||||
TargetEggMass *float64 `json:"target_egg_mass"`
|
||||
}
|
||||
|
||||
type WeeklyProductionStandardDTO struct {
|
||||
Week int `json:"week"`
|
||||
GrowthStandardDetail GrowthStandardDetailDTO `json:"growth_standard_detail"`
|
||||
EggProductionStandardDetailDTO *EggProductionStandardDetailDTO `json:"egg_production_standard_detail,omitempty"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToProductionStandardListDTO(e entity.ProductionStandard) ProductionStandardListDTO {
|
||||
var createdUser *userDTO.UserRelationDTO
|
||||
if e.CreatedUser.Id != 0 {
|
||||
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
|
||||
return ProductionStandardListDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
ProjectCategory: e.ProjectCategory,
|
||||
CreatedUser: createdUser,
|
||||
}
|
||||
}
|
||||
|
||||
func ToProductionStandardListDTOs(e []entity.ProductionStandard) []ProductionStandardListDTO {
|
||||
result := make([]ProductionStandardListDTO, len(e))
|
||||
for i, r := range e {
|
||||
result[i] = ToProductionStandardListDTO(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ToWeeklyProductionStandardDTO(e entity.StandardGrowthDetail) WeeklyProductionStandardDTO {
|
||||
return WeeklyProductionStandardDTO{
|
||||
Week: e.Week,
|
||||
GrowthStandardDetail: GrowthStandardDetailDTO{
|
||||
Id: e.Id,
|
||||
TargetMeanBW: e.TargetMeanBw,
|
||||
MaxDepletion: e.MaxDepletion,
|
||||
MinUniformity: e.MinUniformity,
|
||||
FeedIntake: e.FeedIntake,
|
||||
},
|
||||
EggProductionStandardDetailDTO: nil, // GROWING category - no egg production details
|
||||
}
|
||||
}
|
||||
|
||||
func ToWeeklyProductionStandardDTOWithDetails(growth entity.StandardGrowthDetail, detail entity.ProductionStandardDetail) WeeklyProductionStandardDTO {
|
||||
eggDetail := &EggProductionStandardDetailDTO{
|
||||
Id: detail.Id,
|
||||
TargetHenDayProduction: detail.TargetHenDayProduction,
|
||||
TargetHenHouseProduction: detail.TargetHenHouseProduction,
|
||||
TargetEggWeight: detail.TargetEggWeight,
|
||||
TargetEggMass: detail.TargetEggMass,
|
||||
}
|
||||
|
||||
return WeeklyProductionStandardDTO{
|
||||
Week: growth.Week,
|
||||
GrowthStandardDetail: GrowthStandardDetailDTO{
|
||||
Id: growth.Id,
|
||||
TargetMeanBW: growth.TargetMeanBw,
|
||||
MaxDepletion: growth.MaxDepletion,
|
||||
MinUniformity: growth.MinUniformity,
|
||||
FeedIntake: growth.FeedIntake,
|
||||
},
|
||||
EggProductionStandardDetailDTO: eggDetail, // LAYING category - with egg production details
|
||||
}
|
||||
}
|
||||
|
||||
func ToWeeklyProductionStandardDTOs(e []entity.StandardGrowthDetail) []WeeklyProductionStandardDTO {
|
||||
result := make([]WeeklyProductionStandardDTO, len(e))
|
||||
for i, r := range e {
|
||||
result[i] = ToWeeklyProductionStandardDTO(r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ToWeeklyProductionStandardDTOsWithDetails(
|
||||
growthDetails []entity.StandardGrowthDetail,
|
||||
productionStandardDetails []entity.ProductionStandardDetail,
|
||||
) []WeeklyProductionStandardDTO {
|
||||
result := make([]WeeklyProductionStandardDTO, len(growthDetails))
|
||||
|
||||
// Create map for production standard details by week
|
||||
prodDetailMap := make(map[int]entity.ProductionStandardDetail)
|
||||
for _, detail := range productionStandardDetails {
|
||||
prodDetailMap[detail.Week] = detail
|
||||
}
|
||||
|
||||
// Map growth details and combine with production standard details
|
||||
for i, growth := range growthDetails {
|
||||
if prodDetail, exists := prodDetailMap[growth.Week]; exists {
|
||||
result[i] = ToWeeklyProductionStandardDTOWithDetails(growth, prodDetail)
|
||||
} else {
|
||||
result[i] = ToWeeklyProductionStandardDTO(growth)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func ToEggProductionStandardDetailDTO(e entity.ProductionStandardDetail) EggProductionStandardDetailDTO {
|
||||
return EggProductionStandardDetailDTO{
|
||||
TargetHenDayProduction: e.TargetHenDayProduction,
|
||||
TargetHenHouseProduction: e.TargetHenHouseProduction,
|
||||
TargetEggWeight: e.TargetEggWeight,
|
||||
TargetEggMass: e.TargetEggMass,
|
||||
}
|
||||
}
|
||||
|
||||
func ToProductionStandardDetailDTO(
|
||||
standard entity.ProductionStandard,
|
||||
growthDetails []entity.StandardGrowthDetail,
|
||||
productionStandardDetails []entity.ProductionStandardDetail,
|
||||
) ProductionStandardDetailDTO {
|
||||
return ProductionStandardDetailDTO{
|
||||
ProductionStandardListDTO: ToProductionStandardListDTO(standard),
|
||||
Details: ToWeeklyProductionStandardDTOsWithDetails(growthDetails, productionStandardDetails),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user