diff --git a/domain/notification/entity/channel.go b/domain/notification/entity/channel.go new file mode 100644 index 00000000..4dfcc563 --- /dev/null +++ b/domain/notification/entity/channel.go @@ -0,0 +1,8 @@ +package entity + +type Channel struct { + ID int8 + Type NotificationType + Provider string + Config string +} diff --git a/domain/notification/entity/notification.go b/domain/notification/entity/notification.go new file mode 100644 index 00000000..96887c62 --- /dev/null +++ b/domain/notification/entity/notification.go @@ -0,0 +1,51 @@ +package entity + +type Notification struct { + ID int8 + Type NotificationType + Recipinet string + Body string + Status NotificationStatus +} + +type NotificationType uint8 + +const ( + Email NotificationType = iota + 1 + SMS + Push +) + +func (t NotificationType) String() string { + switch t { + case Email: + return "Email" + case SMS: + return "SMS" + case Push: + return "Push" + default: + return "Unknown" + } +} + +type NotificationStatus uint8 + +const ( + Pending NotificationStatus = iota + 1 + Success + Failed +) + +func (t NotificationStatus) String() string { + switch t { + case Pending: + return "Pending" + case Success: + return "Success" + case Failed: + return "Failed" + default: + return "Unknown" + } +} diff --git a/domain/notification/messagebroker/redis.go b/domain/notification/messagebroker/redis.go new file mode 100644 index 00000000..c6974a9e --- /dev/null +++ b/domain/notification/messagebroker/redis.go @@ -0,0 +1,17 @@ +package messagebroker + +import "git.gocasts.ir/ebhomengo/niki/domain/notification/entity" + +type redis struct { +} + +func (r *redis) AddItem(notification entity.Notification) error { + return nil +} + +func (r *redis) RemoveItem(notification entity.Notification) error { + return nil +} +func (r *redis) HealthCheck() error { + return nil +} diff --git a/domain/notification/service/additem.go b/domain/notification/service/additem.go new file mode 100644 index 00000000..d79a9677 --- /dev/null +++ b/domain/notification/service/additem.go @@ -0,0 +1,67 @@ +package service + +import ( + _ "time" + + "git.gocasts.ir/ebhomengo/niki/domain/notification/entity" +) + +type Notifservice struct { + MessageBroker MessageBroker + Repository Repository + Channel Channel +} + +type MessageBroker interface { + AddItem(notification entity.Notification) error + RemoveItem(notification entity.Notification) error + HealthCheck() error +} + +type Repository interface { + AddItem(notification entity.Notification) error +} + +type Channel interface { + SendMessage(notification entity.Notification) error +} +type NotificationServiceRequest struct { + Body string + Type entity.NotificationType + Recipinet string +} + +func (n *Notifservice) NewNotification(r NotificationServiceRequest) *entity.Notification { + // TODO add validation of notification properties + return &entity.Notification{ + Type: r.Type, + Recipinet: r.Recipinet, + Body: r.Body, + Status: entity.Pending, + } +} + +func (n *Notifservice) Send(notification entity.Notification) error { + if err := n.Channel.SendMessage(notification); err != nil { + return err + } + return nil +} + +func (n *Notifservice) Add(notification *entity.Notification) error { + err := n.MessageBroker.AddItem(*notification) + if err != nil { + return err + } + return nil +} + +func (n *Notifservice) Archive(notification *entity.Notification) error { + if err := n.MessageBroker.RemoveItem(*notification); err != nil { + return err + } + if err := n.Repository.AddItem(*notification); err != nil { + return err + } + return nil +} diff --git a/domain/notification/service/send.go b/domain/notification/service/send.go new file mode 100644 index 00000000..1d2c9211 --- /dev/null +++ b/domain/notification/service/send.go @@ -0,0 +1,7 @@ +package service + +import "git.gocasts.ir/ebhomengo/niki/domain/notification/entity" + +type sender interface { + Send(notification entity.Notification) error +}