Merge pull request 'feature/notification' (#263) from feature/notification into develop

Reviewed-on: ebhomengo/niki#263
Reviewed-by: hossein <h.nazari1990@gmail.com>
This commit is contained in:
hossein 2026-04-08 05:10:41 +00:00
commit 2dfbeaf58e
5 changed files with 150 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/domain/notification/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,67 @@
package service
import (
_ "time"
"git.gocasts.ir/ebhomengo/niki/domain/notification/entity"
)
type Notifservice struct {
MessageBroker MessageBroker
Repository Repository
Channel Channel
}
type MessageBroker interface {
AddItem(notification entity.Notification) error
RemoveItem(notification entity.Notification) error
HealthCheck() error
}
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
}

View File

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