package handlers import ( "strconv" "github.com/gofiber/fiber/v2" "github.com/buhapp/backend/internal/places" ) type PlacesHandler struct { Places *places.Client } func NewPlacesHandler() *PlacesHandler { return &PlacesHandler{Places: places.New()} } // GET /api/v1/places/nearby?lat=..&lng=..&radius=..&limit=.. func (h *PlacesHandler) Nearby(c *fiber.Ctx) error { lat, err := strconv.ParseFloat(c.Query("lat"), 64) if err != nil { return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "lat required"}) } lng, err := strconv.ParseFloat(c.Query("lng"), 64) if err != nil { return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "lng required"}) } radius, _ := strconv.ParseFloat(c.Query("radius", "3"), 64) if radius < 0.5 { radius = 0.5 } if radius > 25 { radius = 25 } limit, _ := strconv.Atoi(c.Query("limit", "30")) results, err := h.Places.NearbyPlaces(c.UserContext(), lat, lng, radius, limit) if err != nil { // не критично — отдаём пустой массив с сообщением return c.JSON(fiber.Map{ "places": []places.Place{}, "error": err.Error(), "count": 0, }) } return c.JSON(fiber.Map{ "places": results, "count": len(results), }) }