get_thing_images.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package image
  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/images/thing/{thingId} [get]
  9. // @Param thingId path int true "Thing ID"
  10. // @Success 200 {object} dto.ImagesResponse
  11. // @Failure 400 {object} dto.ErrorResponse
  12. // @Failure 500 {object} dto.ErrorResponse
  13. // @Summary Get images by thing ID
  14. // @Tags Images
  15. // @security APIKey
  16. // @Accept json
  17. // @Produce json
  18. func GetThingImagesHandler(sp interfaces.ServiceProvider) fiber.Handler {
  19. return func(fctx *fiber.Ctx) error {
  20. ctx := fctx.Context()
  21. id, err := fctx.ParamsInt("thingId")
  22. if err != nil {
  23. return fiber.NewError(fiber.StatusBadRequest, err.Error())
  24. }
  25. res, err := sp.GetThingImageRepository().GetByThingID(ctx, id)
  26. if err != nil {
  27. return fiber.NewError(fiber.StatusInternalServerError, err.Error())
  28. }
  29. res = helpers.ApplyLocation(fctx, res)
  30. return fctx.JSON(mappers.ConvertToImagesResponseDTO(res))
  31. }
  32. }