get_place_tree.go 864 B

1234567891011121314151617181920212223242526272829
  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/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(sp interfaces.ServiceProvider) fiber.Handler {
  17. return func(fctx *fiber.Ctx) error {
  18. res, err := sp.GetPlaceRepository().GetAll(fctx.Context())
  19. if err != nil {
  20. return fiber.NewError(fiber.StatusInternalServerError, err.Error())
  21. }
  22. res = helpers.ApplyLocation(fctx, res)
  23. return fctx.JSON(mappers.ConvertToPlaceTreeResponseDTO(res))
  24. }
  25. }