get_expired_thing_notifications.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package notification
  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/things/notifications/expired [get]
  9. // @Success 200 {object} dto.ThingNotificationsExtResponse
  10. // @Failure 400 {object} dto.ErrorResponse
  11. // @Failure 500 {object} dto.ErrorResponse
  12. // @Summary Get expired thing notifications
  13. // @Tags Notifications
  14. // @security APIKey
  15. // @Accept json
  16. // @Produce json
  17. func GetExpiredThingNotificationsHandler(
  18. thingNotificationRepository ThingNotificationRepository,
  19. ) fiber.Handler {
  20. return func(fctx *fiber.Ctx) error {
  21. ctx := fctx.Context()
  22. res, err := thingNotificationRepository.GetExpired(ctx)
  23. if err != nil {
  24. logger.Info(ctx, err.Error())
  25. return fiber.NewError(fiber.StatusInternalServerError, err.Error())
  26. }
  27. res = location.ApplyLocation(fctx, res)
  28. return fctx.JSON(mappers.ToThingNotificationsExtResponse(res))
  29. }
  30. }