get_place_tree.go 892 B

1234567891011121314151617181920212223242526272829303132
  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/mappers"
  7. )
  8. // @Router /api/v1/places/tree [get]
  9. // @Success 200 {object} dto.PlaceTreeResponse
  10. // @Failure 500 {object} dto.ErrorResponse
  11. // @Summary Get places tree
  12. // @Tags Places
  13. // @security APIKey
  14. // @Accept json
  15. // @Produce json
  16. func GetPlaceTreeHandler(placeRepository PlaceRepository) fiber.Handler {
  17. return func(fctx *fiber.Ctx) error {
  18. ctx := fctx.Context()
  19. res, err := placeRepository.GetAll(ctx)
  20. if err != nil {
  21. logger.Error(ctx, err.Error())
  22. return fiber.NewError(fiber.StatusInternalServerError, err.Error())
  23. }
  24. res = location.ApplyLocation(fctx, res)
  25. return fctx.JSON(mappers.ToPlaceTreeResponse(res))
  26. }
  27. }