get_places.go 878 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 [get]
  9. // @Success 200 {object} dto.PlacesResponse
  10. // @Failure 500 {object} dto.ErrorResponse
  11. // @Summary Get places list
  12. // @Tags Places
  13. // @security APIKey
  14. // @Accept json
  15. // @Produce json
  16. func GetPlacesHandler(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.ToPlacesResponse(res))
  26. }
  27. }