feat(server): implement training by slug endpoint
This commit is contained in:
parent
e0594892d5
commit
aee7cbc526
1 changed files with 35 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Reference in a new issue