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 {
|
type Channel struct {
|
||||||
ID int8
|
ID int8
|
||||||
Type notificationType
|
Type NotificationType
|
||||||
Provider string
|
Provider string
|
||||||
Config string
|
Config string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,29 +7,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type notifservice struct {
|
type notifservice struct {
|
||||||
//MessageBroker MessageBroker
|
MessageBroker MessageBroker
|
||||||
}
|
Repository Repository
|
||||||
|
Channel Channel
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageBroker interface {
|
type MessageBroker interface {
|
||||||
|
|
@ -38,11 +18,50 @@ type MessageBroker interface {
|
||||||
HealthCheck() error
|
HealthCheck() error
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
type Repository interface {
|
||||||
f := NewNotifservice()
|
AddItem(notification entity.Notification) error
|
||||||
|
}
|
||||||
notif := f.NewNotification(entity.SMS, "09201008697", "Hello World")
|
|
||||||
|
type Channel interface {
|
||||||
f.Add(notif)
|
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