get_place_nested.go 1.3 KB

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