refactor(api): Bind query params
This commit is contained in:
+5
-9
@@ -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(¶ms); 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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user