83 lines
2.9 KiB
Go
83 lines
2.9 KiB
Go
package helper
|
|
|
|
import (
|
|
"users_management/m/model/dto/res"
|
|
"users_management/m/model/entity"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ConvertToFishboneResponses converts fishbone entities to response DTOs
|
|
func ConvertToFishboneResponses(fishbones []entity.Fishbone, totalFishbone map[uuid.UUID]int) ([]res.FishboneResponse, error) {
|
|
var responses []res.FishboneResponse
|
|
|
|
for _, fishbone := range fishbones {
|
|
fishboneResp := res.FishboneResponse{
|
|
ID: fishbone.ID,
|
|
FishboneCode: fishbone.FishboneCode,
|
|
BackboneCode: fishbone.Backbone.BackboneCode,
|
|
DeviceStart: fishbone.DeviceStart.DeviceCode,
|
|
DeviceEnd: fishbone.DeviceEnd.DeviceCode,
|
|
CoreAmount: fishbone.CoreAmount,
|
|
CreatedAt: fishbone.CreatedAt,
|
|
UpdatedAt: fishbone.UpdatedAt,
|
|
}
|
|
responses = append(responses, fishboneResp)
|
|
}
|
|
|
|
return responses, nil
|
|
}
|
|
|
|
// ConvertToFishboneDetailResponse converts a single fishbone entity to detailed response
|
|
func ConvertToFishboneDetailResponse(fishbone entity.Fishbone) res.FishboneDetailResponse {
|
|
return res.FishboneDetailResponse{
|
|
ID: fishbone.ID,
|
|
FishboneCode: fishbone.FishboneCode,
|
|
Backbone: res.BackboneInfo{
|
|
BackboneCode: fishbone.Backbone.BackboneCode,// Fixed missing field
|
|
},
|
|
CoreAmount: fishbone.CoreAmount,
|
|
CreatedAt: fishbone.CreatedAt,
|
|
UpdatedAt: fishbone.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
// ConvertToSimpleFishboneResponses converts fishbone entities to simple response format
|
|
func ConvertToSimpleFishboneResponses(fishbones []entity.Fishbone) []res.FishboneResponse {
|
|
var responses []res.FishboneResponse
|
|
|
|
for _, fishbone := range fishbones {
|
|
fishboneResp := res.FishboneResponse{
|
|
ID: fishbone.ID,
|
|
FishboneCode: fishbone.FishboneCode,
|
|
BackboneCode: fishbone.Backbone.BackboneCode,
|
|
DeviceStart: fishbone.DeviceStart.DeviceCode,
|
|
DeviceEnd: fishbone.DeviceEnd.DeviceCode,
|
|
CoreAmount: fishbone.CoreAmount,
|
|
CreatedAt: fishbone.CreatedAt,
|
|
UpdatedAt: fishbone.UpdatedAt,
|
|
}
|
|
responses = append(responses, fishboneResp)
|
|
}
|
|
|
|
return responses
|
|
}
|
|
|
|
// GetFishboneStats calculates statistics for fishbones
|
|
func GetFishboneStats(fishbones []entity.Fishbone) map[string]interface{} {
|
|
totalFishbones := len(fishbones)
|
|
totalCores := 0
|
|
backboneCount := make(map[uuid.UUID]int)
|
|
|
|
for _, fishbone := range fishbones {
|
|
totalCores += fishbone.CoreAmount
|
|
backboneCount[fishbone.BackboneID]++
|
|
}
|
|
|
|
return map[string]interface{}{
|
|
"total_cores": totalCores,
|
|
"average_cores": float64(totalCores) / float64(totalFishbones),
|
|
"unique_backbones": len(backboneCount),
|
|
"backbone_usage": backboneCount,
|
|
}
|
|
} |