refactor(api): Bind query params

This commit is contained in:
2026-02-22 23:44:52 +03:00
parent 8ab2de40e0
commit 612c6ebde5
+5 -9
View File
@@ -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 == "" {
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))
}
if params.LocationID <= 0 {
return fmt.Errorf("missing query parameter location_id: %w", fiber.ErrBadRequest)
}
locationID, err := strconv.Atoi(locationIDText)
if err != nil {
return fmt.Errorf("failed to parse location_id query parameter: %w", errors.Join(fiber.ErrBadRequest, err))
}
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))
}