2022-12-31 10:22:38 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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
|
|
|
)
|
|
|
|
|
|
|
|
type CreateNotification struct {
|
|
|
|
Id uuid.UUID
|
|
|
|
Icon string `json:"icon" validate:"required,oneof=updates news features youtube"`
|
|
|
|
Link string `json:"link" validate:"required,max=128"`
|
|
|
|
Message string `json:"message" validate:"required,max=256"`
|
|
|
|
Platform string `json:"platform" validate:"required,oneof=ios android huawei"`
|
|
|
|
Version string `json:"version" validate:"omitempty,max=12"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type CreateNotificationHandler struct {
|
|
|
|
Repository domain.MobileNotificationsRepository
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *CreateNotificationHandler) Handle(cmd *CreateNotification) error {
|
|
|
|
mobileNotification := &domain.MobileNotification{
|
|
|
|
Id: cmd.Id,
|
|
|
|
Icon: cmd.Icon,
|
|
|
|
Link: cmd.Link,
|
|
|
|
Message: cmd.Message,
|
|
|
|
Platform: cmd.Platform,
|
|
|
|
Version: cmd.Version,
|
|
|
|
}
|
|
|
|
|
|
|
|
return h.Repository.Save(mobileNotification)
|
|
|
|
}
|