refactor(api): Bind query params

master
Abdussamet Kocak 4 weeks ago
parent 8ab2de40e0
commit 612c6ebde5

@ -226,18 +226,14 @@ func New(services Services) *fiber.App {
var params struct {
LocationID int `query:"location_id"`
}
locationIDText := strings.TrimSpace(ctx.Query("location_id"))
if locationIDText == "" {
return fmt.Errorf("missing query parameter location_id: %w", fiber.ErrBadRequest)
if err := ctx.Bind().Query(&params); err != nil {
return fmt.Errorf("failed to bind legacy prayer times query parameters: %w", errors.Join(fiber.ErrBadRequest, err))
}
locationID, err := strconv.Atoi(locationIDText)
if err != nil {
return fmt.Errorf("failed to parse location_id query parameter: %w", errors.Join(fiber.ErrBadRequest, err))
if params.LocationID <= 0 {
return fmt.Errorf("missing query parameter location_id: %w", fiber.ErrBadRequest)
}
legacyLocation, err := services.LegacyLocationProvider.GetLocationByID(ctx.Context(), locationID)
legacyLocation, err := services.LegacyLocationProvider.GetLocationByID(ctx.Context(), params.LocationID)
if err != nil {
return fmt.Errorf("failed to resolve location by location_id: %w", errors.Join(fiber.ErrNotFound, err))
}

Loading…
Cancel
Save