From 539a3162775ba0b345b94b8c362d3d7810945f69 Mon Sep 17 00:00:00 2001 From: mahdi simin Date: Wed, 1 Apr 2026 00:20:52 +0330 Subject: [PATCH 1/3] Impelement Notification Structure --- notification-app/entity/channel.go | 8 ++++ notification-app/entity/notification.go | 51 +++++++++++++++++++++++++ notification-app/messagebroker/redis.go | 17 +++++++++ notification-app/service/additem.go | 48 +++++++++++++++++++++++ notification-app/service/send.go | 7 ++++ 5 files changed, 131 insertions(+) create mode 100644 notification-app/entity/channel.go create mode 100644 notification-app/entity/notification.go create mode 100644 notification-app/messagebroker/redis.go create mode 100644 notification-app/service/additem.go create mode 100644 notification-app/service/send.go diff --git a/notification-app/entity/channel.go b/notification-app/entity/channel.go new file mode 100644 index 00000000..fa114320 --- /dev/null +++ b/notification-app/entity/channel.go @@ -0,0 +1,8 @@ +package entity + +type Channel struct { + ID int8 + Type notificationType + Provider string + Config string +} diff --git a/notification-app/entity/notification.go b/notification-app/entity/notification.go new file mode 100644 index 00000000..96887c62 --- /dev/null +++ b/notification-app/entity/notification.go @@ -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" + } +} diff --git a/notification-app/messagebroker/redis.go b/notification-app/messagebroker/redis.go new file mode 100644 index 00000000..31dc8033 --- /dev/null +++ b/notification-app/messagebroker/redis.go @@ -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 +} diff --git a/notification-app/service/additem.go b/notification-app/service/additem.go new file mode 100644 index 00000000..c4702e35 --- /dev/null +++ b/notification-app/service/additem.go @@ -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) + +} diff --git a/notification-app/service/send.go b/notification-app/service/send.go new file mode 100644 index 00000000..ef8b6d87 --- /dev/null +++ b/notification-app/service/send.go @@ -0,0 +1,7 @@ +package service + +import "git.gocasts.ir/ebhomengo/niki/notification-app/entity" + +type sender interface { + Send(notification entity.Notification) error +} From 6b150111c7e564107ffdcea4498dcbd48b43c697 Mon Sep 17 00:00:00 2001 From: Mahdi Simin Date: Sat, 4 Apr 2026 04:20:12 +0330 Subject: [PATCH 2/3] feat/notification - notification service --- notification-app/entity/channel.go | 2 +- notification-app/service/additem.go | 79 ++++++++++++++++++----------- 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/notification-app/entity/channel.go b/notification-app/entity/channel.go index fa114320..4dfcc563 100644 --- a/notification-app/entity/channel.go +++ b/notification-app/entity/channel.go @@ -2,7 +2,7 @@ package entity type Channel struct { ID int8 - Type notificationType + Type NotificationType Provider string Config string } diff --git a/notification-app/service/additem.go b/notification-app/service/additem.go index c4702e35..b213b828 100644 --- a/notification-app/service/additem.go +++ b/notification-app/service/additem.go @@ -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 } From bc37b8472687328c7ba2e8f101f934e00021c449 Mon Sep 17 00:00:00 2001 From: Mahdi Simin Date: Sat, 4 Apr 2026 04:51:28 +0330 Subject: [PATCH 3/3] feat/notification - restructure Notification app with new structure --- .../notification}/entity/channel.go | 0 .../notification}/entity/notification.go | 0 .../notification}/messagebroker/redis.go | 2 +- .../notification}/service/additem.go | 12 ++++++------ .../notification}/service/send.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) rename {notification-app => domain/notification}/entity/channel.go (100%) rename {notification-app => domain/notification}/entity/notification.go (100%) rename {notification-app => domain/notification}/messagebroker/redis.go (79%) rename {notification-app => domain/notification}/service/additem.go (76%) rename {notification-app => domain/notification}/service/send.go (57%) diff --git a/notification-app/entity/channel.go b/domain/notification/entity/channel.go similarity index 100% rename from notification-app/entity/channel.go rename to domain/notification/entity/channel.go diff --git a/notification-app/entity/notification.go b/domain/notification/entity/notification.go similarity index 100% rename from notification-app/entity/notification.go rename to domain/notification/entity/notification.go diff --git a/notification-app/messagebroker/redis.go b/domain/notification/messagebroker/redis.go similarity index 79% rename from notification-app/messagebroker/redis.go rename to domain/notification/messagebroker/redis.go index 31dc8033..c6974a9e 100644 --- a/notification-app/messagebroker/redis.go +++ b/domain/notification/messagebroker/redis.go @@ -1,6 +1,6 @@ package messagebroker -import "git.gocasts.ir/ebhomengo/niki/notification-app/entity" +import "git.gocasts.ir/ebhomengo/niki/domain/notification/entity" type redis struct { } diff --git a/notification-app/service/additem.go b/domain/notification/service/additem.go similarity index 76% rename from notification-app/service/additem.go rename to domain/notification/service/additem.go index b213b828..d79a9677 100644 --- a/notification-app/service/additem.go +++ b/domain/notification/service/additem.go @@ -3,10 +3,10 @@ package service import ( _ "time" - "git.gocasts.ir/ebhomengo/niki/notification-app/entity" + "git.gocasts.ir/ebhomengo/niki/domain/notification/entity" ) -type notifservice struct { +type Notifservice struct { MessageBroker MessageBroker Repository Repository Channel Channel @@ -31,7 +31,7 @@ type NotificationServiceRequest struct { Recipinet string } -func (n *notifservice) NewNotification(r NotificationServiceRequest) *entity.Notification { +func (n *Notifservice) NewNotification(r NotificationServiceRequest) *entity.Notification { // TODO add validation of notification properties return &entity.Notification{ Type: r.Type, @@ -41,14 +41,14 @@ func (n *notifservice) NewNotification(r NotificationServiceRequest) *entity.Not } } -func (n *notifservice) Send(notification entity.Notification) error { +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 { +func (n *Notifservice) Add(notification *entity.Notification) error { err := n.MessageBroker.AddItem(*notification) if err != nil { return err @@ -56,7 +56,7 @@ func (n *notifservice) Add(notification *entity.Notification) error { return nil } -func (n *notifservice) Archive(notification *entity.Notification) error { +func (n *Notifservice) Archive(notification *entity.Notification) error { if err := n.MessageBroker.RemoveItem(*notification); err != nil { return err } diff --git a/notification-app/service/send.go b/domain/notification/service/send.go similarity index 57% rename from notification-app/service/send.go rename to domain/notification/service/send.go index ef8b6d87..1d2c9211 100644 --- a/notification-app/service/send.go +++ b/domain/notification/service/send.go @@ -1,6 +1,6 @@ package service -import "git.gocasts.ir/ebhomengo/niki/notification-app/entity" +import "git.gocasts.ir/ebhomengo/niki/domain/notification/entity" type sender interface { Send(notification entity.Notification) error