get_places.go 773 B

1234567891011121314151617181920212223242526272829
  1. package place
  2. import (
  3. "github.com/gofiber/fiber/v2"
  4. "git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
  5. "git.dmitriygnatenko.ru/dima/homethings/internal/mappers"
  6. )
  7. // @Router /api/v1/places [get]
  8. // @Success 200 {object} dto.PlacesResponse
  9. // @Failure 500 {object} dto.ErrorResponse
  10. // @Summary Get places list
  11. // @Tags Places
  12. // @security APIKey
  13. // @Accept json
  14. // @Produce json
  15. func GetPlacesHandler(placeRepository PlaceRepository) fiber.Handler {
  16. return func(fctx *fiber.Ctx) error {
  17. res, err := placeRepository.GetAll(fctx.Context())
  18. if err != nil {
  19. return fiber.NewError(fiber.StatusInternalServerError, err.Error())
  20. }
  21. res = helpers.ApplyLocation(fctx, res)
  22. return fctx.JSON(mappers.ToPlacesResponse(res))
  23. }
  24. }