feat: Add location search
This commit is contained in:
+10
-6
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/gofiber/fiber/v3/middleware/cors"
|
||||
"github.com/gofiber/fiber/v3/middleware/favicon"
|
||||
"github.com/gofiber/fiber/v3/middleware/logger"
|
||||
recover "github.com/gofiber/fiber/v3/middleware/recover"
|
||||
"github.com/gofiber/fiber/v3/middleware/recover"
|
||||
"github.com/gofiber/fiber/v3/middleware/static"
|
||||
|
||||
"prayertimes/pkg/prayer"
|
||||
@@ -25,12 +25,16 @@ type httpError struct {
|
||||
}
|
||||
|
||||
type Services struct {
|
||||
Provider DiyanetProvider
|
||||
PrayerProvider PrayerProvider
|
||||
LocationProvider LocationProvider
|
||||
}
|
||||
|
||||
type DiyanetProvider interface {
|
||||
type PrayerProvider interface {
|
||||
Get(ctx context.Context, locationID string) ([]prayer.Times, error)
|
||||
GetByCoords(ctx context.Context, coords prayer.Coordinates) ([]prayer.Times, error)
|
||||
}
|
||||
|
||||
type LocationProvider interface {
|
||||
SearchLocations(ctx context.Context, query string) ([]prayer.Location, error)
|
||||
}
|
||||
|
||||
@@ -82,7 +86,7 @@ func New(services Services) *fiber.App {
|
||||
|
||||
switch {
|
||||
case locationID != "":
|
||||
times, err = services.Provider.Get(ctx.Context(), locationID)
|
||||
times, err = services.PrayerProvider.Get(ctx.Context(), locationID)
|
||||
case latitude != "" && longitude != "":
|
||||
lat, latErr := strconv.ParseFloat(latitude, 64)
|
||||
if latErr != nil {
|
||||
@@ -93,7 +97,7 @@ func New(services Services) *fiber.App {
|
||||
return fmt.Errorf("failed to parse longitude query parameter: %w", errors.Join(fiber.ErrBadRequest, lngErr))
|
||||
}
|
||||
|
||||
times, err = services.Provider.GetByCoords(ctx.Context(), prayer.Coordinates{
|
||||
times, err = services.PrayerProvider.GetByCoords(ctx.Context(), prayer.Coordinates{
|
||||
Latitude: lat,
|
||||
Longitude: lng,
|
||||
})
|
||||
@@ -124,7 +128,7 @@ func New(services Services) *fiber.App {
|
||||
return fmt.Errorf("failed to validate location query parameters: %w", fiber.ErrBadRequest)
|
||||
}
|
||||
|
||||
locations, err := services.Provider.SearchLocations(ctx.Context(), query.Text)
|
||||
locations, err := services.LocationProvider.SearchLocations(ctx.Context(), query.Text)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to search locations: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user