forked from ebhomengo/niki
feat/notification - notification service
This commit is contained in:
parent
539a316277
commit
6b150111c7
|
|
@ -2,7 +2,7 @@ package entity
|
|||
|
||||
type Channel struct {
|
||||
ID int8
|
||||
Type notificationType
|
||||
Type NotificationType
|
||||
Provider string
|
||||
Config string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue