get_place_nested.go 1.1 KB

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