get_place_nested.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package place
  2. import (
  3. "github.com/gofiber/fiber/v2"
  4. "git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
  5. "git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
  6. )
  7. // @Router /api/v1/places/{parentPlaceId}/nested [get]
  8. // @Param parentPlaceId path int true "Place ID"
  9. // @Success 200 {object} dto.PlacesResponse
  10. // @Failure 500 {object} dto.ErrorResponse
  11. // @Failure 400 {object} dto.ErrorResponse
  12. // @Summary Get nested places by parent ID
  13. // @Tags Places
  14. // @security APIKey
  15. // @Accept json
  16. // @Produce json
  17. func GetNestedPlacesHandler(placeRepository PlaceRepository) fiber.Handler {
  18. return func(fctx *fiber.Ctx) error {
  19. ctx := fctx.Context()
  20. id, err := fctx.ParamsInt("parentPlaceId")
  21. if err != nil {
  22. return fiber.NewError(fiber.StatusBadRequest, err.Error())
  23. }
  24. res, err := placeRepository.GetNestedPlaces(ctx, id)
  25. if err != nil {
  26. return fiber.NewError(fiber.StatusInternalServerError, err.Error())
  27. }
  28. res = helpers.ApplyLocation(fctx, res)
  29. return fctx.JSON(mappers.ToPlacesResponse(res))
  30. }
  31. }