forked from ebhomengo/niki
Impelement Notification Structure
This commit is contained in:
parent
6cea941f48
commit
539a316277
|
|
@ -0,0 +1,8 @@
|
||||||
|
package entity
|
||||||
|
|
||||||
|
type Channel struct {
|
||||||
|
ID int8
|
||||||
|
Type notificationType
|
||||||
|
Provider string
|
||||||
|
Config string
|
||||||
|
}
|
||||||
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package messagebroker
|
||||||
|
|
||||||
|
import "git.gocasts.ir/ebhomengo/niki/notification-app/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
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "time"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/notification-app/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
type MessageBroker interface {
|
||||||
|
AddItem(notification entity.Notification) error
|
||||||
|
RemoveItem(notification entity.Notification) error
|
||||||
|
HealthCheck() error
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
f := NewNotifservice()
|
||||||
|
|
||||||
|
notif := f.NewNotification(entity.SMS, "09201008697", "Hello World")
|
||||||
|
|
||||||
|
f.Add(notif)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package service
|
||||||
|
|
||||||
|
import "git.gocasts.ir/ebhomengo/niki/notification-app/entity"
|
||||||
|
|
||||||
|
type sender interface {
|
||||||
|
Send(notification entity.Notification) error
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue