- 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: шлёт предложение встретиться в чат с собеседником - Карточки с эмодзи по типу заведения, расстояние, время работы
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
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),
|
||
})
|
||
}
|