diff --git a/notification-app/entity/channel.go b/notification-app/entity/channel.go index fa114320..4dfcc563 100644 --- a/notification-app/entity/channel.go +++ b/notification-app/entity/channel.go @@ -2,7 +2,7 @@ package entity type Channel struct { ID int8 - Type notificationType + Type NotificationType Provider string Config string } diff --git a/notification-app/service/additem.go b/notification-app/service/additem.go index c4702e35..b213b828 100644 --- a/notification-app/service/additem.go +++ b/notification-app/service/additem.go @@ -7,29 +7,9 @@ import ( ) type notifservice struct { - //MessageBroker MessageBroker -} - -func NewNotifservice() *notifservice { - return ¬ifservice{} -} - -func (n *notifservice) NewNotification(notificationType entity.NotificationType, Recipinet, Body string) *entity.Notification { - - return &entity.Notification{ - Type: notificationType, - Recipinet: Recipinet, - Body: Body, - Status: entity.Pending, - } -} - -func (n *notifservice) Send(notification entity.Notification) error { - return nil -} - -func (n *notifservice) Add(notification *entity.Notification) error { - return nil + MessageBroker MessageBroker + Repository Repository + Channel Channel } type MessageBroker interface { @@ -38,11 +18,50 @@ type MessageBroker interface { HealthCheck() error } -func main() { - f := NewNotifservice() - - notif := f.NewNotification(entity.SMS, "09201008697", "Hello World") - - f.Add(notif) - +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 }