1
0
Fork 0

feat(server): implement training by slug endpoint

This commit is contained in:
Vojtěch Mareš 2024-06-27 09:14:15 +02:00
parent e0594892d5
commit aee7cbc526
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D

View file

@ -176,6 +176,41 @@ func (h *APIHandlers) GetTraining(ctx context.Context, req GetTrainingRequestObj
}, nil
}
func (h *APIHandlers) GetTrainingBySlug(ctx context.Context, req GetTrainingBySlugRequestObject) (GetTrainingBySlugResponseObject, error) {
t, err := h.trainingRepository.FindBySlug(req.TrainingSlug)
if errors.Is(err, training.ErrTrainingNotFound) {
return GetTrainingBySlug404ApplicationProblemPlusJSONResponse{
NotFoundErrorApplicationProblemPlusJSONResponse: NotFoundErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusNotFound,
Title: "Not Found: Training not found",
}}, nil
} else if err != nil {
return GetTrainingBySlug500ApplicationProblemPlusJSONResponse{
InternalErrorApplicationProblemPlusJSONResponse: InternalErrorApplicationProblemPlusJSONResponse{
Status: fiber.StatusInternalServerError,
Title: "Internal Server Error: Failed to get training",
Detail: err.Error(),
}}, nil
}
pricing := make([]TrainingPrice, len(t.Pricing))
for idx, p := range t.Pricing {
pricing[idx] = TrainingPrice{
Amount: p.Amount.String(),
Currency: p.Currency,
Type: TrainingPriceType(p.Type),
}
}
return GetTrainingBySlug200JSONResponse{
Id: t.ID,
Name: t.Name,
Slug: t.Slug,
Days: t.Days,
Description: t.Description,
Pricing: pricing,
}, nil
}
func (h *APIHandlers) UpdateTraining(ctx context.Context, req UpdateTrainingRequestObject) (UpdateTrainingResponseObject, error) {
pricing := make([]training.Price, len(req.Body.Pricing))
for idx, p := range req.Body.Pricing {