Impelement Notification Structure

This commit is contained in:
mahdi simin 2026-04-01 00:20:52 +03:30
parent 6cea941f48
commit 539a316277
5 changed files with 131 additions and 0 deletions

View File

@ -0,0 +1,8 @@
package entity
type Channel struct {
ID int8
Type notificationType
Provider string
Config string
}

View File

@ -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"
}
}

View File

@ -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
}

View File

@ -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 &notifservice{}
}
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)
}

View File

@ -0,0 +1,7 @@
package service
import "git.gocasts.ir/ebhomengo/niki/notification-app/entity"
type sender interface {
Send(notification entity.Notification) error
}