refactor: /v1/trainings/upcoming-dates sends response with trainingID and list of dates together
This commit is contained in:
parent
401cc5330e
commit
715ce009b1
3 changed files with 82 additions and 54 deletions
|
|
@ -382,35 +382,49 @@ func (h *APIHandlers) UpdateTrainingDate(ctx context.Context, req UpdateTraining
|
|||
}
|
||||
|
||||
func (h *APIHandlers) ListAllUpcomingTrainingDates(ctx context.Context, req ListAllUpcomingTrainingDatesRequestObject) (ListAllUpcomingTrainingDatesResponseObject, error) {
|
||||
trainingDates, err := h.trainingDateRepository.FindAllUpcoming()
|
||||
trainings, err := h.trainingRepository.FindAll()
|
||||
if err != nil {
|
||||
return ListAllUpcomingTrainingDates500ApplicationProblemPlusJSONResponse{
|
||||
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
|
||||
Status: fiber.StatusInternalServerError,
|
||||
Title: "Internal Server Error: Failed to list upcoming training dates",
|
||||
Title: "Internal Server Error: Failed to list all upcoming training dates",
|
||||
Detail: err.Error(),
|
||||
}}, nil
|
||||
}
|
||||
|
||||
data := make([]TrainingDate, len(trainingDates))
|
||||
for idx, td := range trainingDates {
|
||||
data[idx] = TrainingDate{
|
||||
Id: td.ID,
|
||||
Date: td.Date,
|
||||
StartTime: td.StartTime.Format(trainingDateStartTimeFormat),
|
||||
Days: td.Days,
|
||||
IsOnline: td.IsOnline,
|
||||
Location: td.Location,
|
||||
Address: td.Address,
|
||||
Capacity: td.Capacity,
|
||||
Price: TrainingDatePrice{
|
||||
Amount: td.Price.Amount,
|
||||
Currency: td.Price.Currency,
|
||||
},
|
||||
response := make(ListAllUpcomingTrainingDatesResponse, len(trainings))
|
||||
for i, t := range trainings {
|
||||
trainingDates, err := h.trainingDateRepository.FindUpcomingByTrainingID(t.ID)
|
||||
if err != nil {
|
||||
return ListAllUpcomingTrainingDates500ApplicationProblemPlusJSONResponse{
|
||||
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
|
||||
Status: fiber.StatusInternalServerError,
|
||||
Title: "Internal Server Error: Failed to list all upcoming training dates",
|
||||
Detail: err.Error(),
|
||||
}}, nil
|
||||
}
|
||||
|
||||
response[i].Dates = make([]TrainingDate, len(trainingDates))
|
||||
response[i].TrainingID = t.ID
|
||||
for j, td := range trainingDates {
|
||||
response[i].Dates[j] = TrainingDate{
|
||||
Id: td.ID,
|
||||
Date: td.Date,
|
||||
StartTime: td.StartTime.Format(trainingDateStartTimeFormat),
|
||||
Days: td.Days,
|
||||
IsOnline: td.IsOnline,
|
||||
Location: td.Location,
|
||||
Address: td.Address,
|
||||
Capacity: td.Capacity,
|
||||
Price: TrainingDatePrice{
|
||||
Amount: td.Price.Amount,
|
||||
Currency: td.Price.Currency,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ListAllUpcomingTrainingDates200JSONResponse(data), nil
|
||||
return ListAllUpcomingTrainingDates200JSONResponse(response), nil
|
||||
}
|
||||
|
||||
func (h *APIHandlers) ListTrainingUpcomingDates(ctx context.Context, req ListTrainingUpcomingDatesRequestObject) (ListTrainingUpcomingDatesResponseObject, error) {
|
||||
|
|
|
|||
Reference in a new issue