buhapp-backend/internal/handlers/places.go
ga 748b4a31fb Sprint 8: 2GIS tiles + places (бары/рестораны) nearby
- internal/places/overpass.go: запрос к Overpass API (OSM), bar/pub/restaurant/cafe/biergarten/nightclub
- internal/handlers/places.go: GET /api/v1/places/nearby (radius, limit)
- POST через application/x-www-form-urlencoded (раньше был broken — query params)
- 2GIS tile layer в map.js (вместо OSM)
- Кнопка 'Показать/Скрыть бары' + список под картой
- Invite to place: шлёт предложение встретиться в чат с собеседником
- Карточки с эмодзи по типу заведения, расстояние, время работы
2026-08-20 21:11:54 +00:00

52 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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),
})
}