2fas-server/internal/api/mobile/app/command/publish_whatsnew_notification.go

31 lines
656 B
Go
Raw Normal View History

2022-12-31 10:22:38 +01:00
package command
import (
"database/sql"
"github.com/google/uuid"
2023-01-30 19:59:42 +01:00
"github.com/twofas/2fas-server/internal/api/mobile/domain"
2022-12-31 10:22:38 +01:00
"time"
)
type PublishNotification struct {
Id string `uri:"notification_id" validate:"required,uuid4"`
}
type PublishNotificationHandler struct {
Repository domain.MobileNotificationsRepository
}
func (h *PublishNotificationHandler) Handle(cmd *PublishNotification) error {
id, _ := uuid.Parse(cmd.Id)
mobileNotification, err := h.Repository.FindById(id)
if err != nil {
return err
}
mobileNotification.PublishedAt = sql.NullTime{Time: time.Now(), Valid: true}
return h.Repository.Update(mobileNotification)
}