get_place_things.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package thing
  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/things/place/{placeId} [get]
  9. // @Param placeId path int true "Place ID"
  10. // @Success 200 {object} dto.ThingsExtResponse
  11. // @Failure 400 {object} dto.ErrorResponse
  12. // @Failure 500 {object} dto.ErrorResponse
  13. // @Summary Get things by place ID
  14. // @Tags Things
  15. // @security APIKey
  16. // @Accept json
  17. // @Produce json
  18. func GetPlaceThingsHandler(sp interfaces.ServiceProvider) fiber.Handler {
  19. return func(fctx *fiber.Ctx) error {
  20. ctx := fctx.Context()
  21. id, err := fctx.ParamsInt("placeId")
  22. if err != nil {
  23. return fiber.NewError(fiber.StatusBadRequest, err.Error())
  24. }
  25. things, err := sp.GetThingRepository().GetAllByPlaceID(ctx, id)
  26. if err != nil {
  27. return fiber.NewError(fiber.StatusInternalServerError, err.Error())
  28. }
  29. tags, err := sp.GetThingTagRepository().GetByPlaceID(ctx, id)
  30. if err != nil {
  31. return fiber.NewError(fiber.StatusInternalServerError, err.Error())
  32. }
  33. things = helpers.ApplyLocation(fctx, things)
  34. tags = helpers.ApplyLocation(fctx, tags)
  35. return fctx.JSON(mappers.ConvertToThingsExtResponseDTO(things, tags))
  36. }
  37. }