forked from ebhomengo/niki
1
0
Fork 0

feat(niki): sms notification for agent

This commit is contained in:
Iman Mirazimi 2024-09-16 18:26:05 +03:30
parent d26d4fc179
commit 4ef5c0ed66
9 changed files with 84 additions and 2 deletions

View File

@ -4,21 +4,25 @@ import (
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
agentkindboxservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
"git.gocasts.ir/ebhomengo/niki/service/notification"
)
type Handler struct {
authSvc authservice.Service
agentKindBoxSvc agentkindboxservice.Service
adminAuthorizeSvc adminauthorizationservice.Service
notificationSvc notification.Service
}
func New(authSvc authservice.Service,
agentKindBoxSvc agentkindboxservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service,
notificationSvc notification.Service,
) Handler {
return Handler{
authSvc: authSvc,
agentKindBoxSvc: agentKindBoxSvc,
adminAuthorizeSvc: adminAuthorizeSvc,
notificationSvc: notificationSvc,
}
}

View File

@ -3,6 +3,7 @@ package agentkindboxhandler
import (
"net/http"
params "git.gocasts.ir/ebhomengo/niki/param"
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
@ -46,5 +47,9 @@ func (h Handler) Return(c echo.Context) error {
return echo.NewHTTPError(code, msg)
}
go h.notificationSvc.KindBoxReturned(params.NotificationKindBoxReturned{
KindBoxID: req.KindBoxID,
})
return c.NoContent(http.StatusNoContent)
}

View File

@ -2,6 +2,7 @@ package agentkindboxreqhandler
import (
"context"
params "git.gocasts.ir/ebhomengo/niki/param"
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
"net/http"
@ -52,5 +53,9 @@ func (h Handler) Deliver(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, errmsg.ErrorMsgSomethingWentWrong)
}
go h.notificationSvc.KindBoxReqDelivered(params.NotificationKindBoxReqDelivered{
KindBoxReqID: req.KindBoxReqID,
})
return c.JSON(http.StatusOK, resp)
}

View File

@ -4,21 +4,25 @@ import (
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
agentkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box_req"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
"git.gocasts.ir/ebhomengo/niki/service/notification"
)
type Handler struct {
authSvc authservice.Service
agentKindBoxReqSvc agentkindboxreqservice.Service
adminAuthorizeSvc adminauthorizationservice.Service
notificationSvc notification.Service
}
func New(authSvc authservice.Service,
agentKindBoxReqSvc agentkindboxreqservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service,
notificationSvc notification.Service,
) Handler {
return Handler{
authSvc: authSvc,
agentKindBoxReqSvc: agentKindBoxReqSvc,
adminAuthorizeSvc: adminAuthorizeSvc,
notificationSvc: notificationSvc,
}
}

View File

@ -47,8 +47,8 @@ func New(
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc),
agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc),
agentKindBoxReqHandler: agentkindboxreqhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxReqSvc, svc.AdminAuthorizeSvc),
agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
agentKindBoxReqHandler: agentkindboxreqhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
benefactorHandler: benefactorhandler.New(svc.BenefactorAuthSvc, svc.BenefactorSvc),
benefactorKindBoxReqHandler: benefactorkindboxreqhandler.New(svc.BenefactorAuthSvc, svc.BenefactorKindBoxReqSvc, svc.NotificationSvc),
benefactorAddressHandler: benefactoraddresshandler.New(svc.BenefactorAuthSvc, svc.BenefactorAddressSvc),

View File

@ -17,6 +17,10 @@ type NotificationKindBoxReqAssigned struct {
KindBoxReqID uint
}
type NotificationKindBoxReqDelivered struct {
KindBoxReqID uint
}
type NotificationKindBoxRegisteredEmptyingRequest struct {
KindBoxID uint
}
@ -28,3 +32,7 @@ type NotificationKindBoxAssigned struct {
type NotificationKindBoxEnumerated struct {
KindBoxID uint
}
type NotificationKindBoxReturned struct {
KindBoxID uint
}

View File

@ -5,7 +5,9 @@ const (
SmsMsgKindBoxReqAccepted = "%s عزیز، درخواست قلک شما پذیرفته شد"
SmsMsgKindBoxReqRejected = "%s عزیز، درخواست قلک شما به دلیل %s پذیرفته نشد"
SmsMsgKindBoxReqAssigned = "%s عزیز، درخواست قلک شماره %d جهت تحویل به نیکوکار به شما اختصاص داده شد"
SmsMsgKindBoxReqDelivered = "%s عزیز, درخواست قلک شما تحویل داده شد"
SmsMsgKindBoxRegistedEmptyingRequest = "%s عزیز، درخواست خالی کردن قلک شما ثبت شد"
SmsMsgKindBoxAssigned = "%s عزیز، قلکی جهت تخلیه به شما اختصاص داده شد"
SmsMsgKindBoxEnumerated = "%s عزیز، قلک شما با شماره سریال %s و مبلغ %d تومان شمارش شد. از مشارکت شما سپاسگزاریم."
SmsMsgKindBoxReturned = "%s عزیز, قلک با شماره سریال %s از شما تحویل گرفته شد"
)

View File

@ -0,0 +1,27 @@
package notification
import (
"context"
"fmt"
"git.gocasts.ir/ebhomengo/niki/param"
bnfparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
kbp "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
smsmsg "git.gocasts.ir/ebhomengo/niki/pkg/sms_msg"
)
func (s Service) KindBoxReturned(req param.NotificationKindBoxReturned) {
const op = "notification.KindBoxReturned"
ctx := context.Background()
kb, err := s.KindBoxSvc.Get(ctx, kbp.KindBoxGetRequest{
KindBoxID: req.KindBoxID,
})
if err != nil {
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
}
bnf, gErr := s.BenefactorSvc.GetByID(ctx, bnfparam.GetBenefactorByIDRequest{BenefactorID: kb.Data.BenefactorID})
if gErr != nil {
fmt.Println(fmt.Errorf("error(%s):%w", op, gErr))
}
s.smsAdapter.Send(bnf.PhoneNumber, fmt.Sprintf(smsmsg.SmsMsgKindBoxReturned, bnf.FirstName, kb.Data.SerialNumber))
}

View File

@ -0,0 +1,27 @@
package notification
import (
"context"
"fmt"
"git.gocasts.ir/ebhomengo/niki/param"
bnfparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
kbparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
smsmsg "git.gocasts.ir/ebhomengo/niki/pkg/sms_msg"
)
func (s Service) KindBoxReqDelivered(req param.NotificationKindBoxReqDelivered) {
const op = "notification.KindBoxReqDelivered"
ctx := context.Background()
kb, err := s.KindBoxReqSvc.Get(ctx, kbparam.GetKindBoxReqRequest{
KindBoxID: req.KindBoxReqID,
})
if err != nil {
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
}
bnf, gErr := s.BenefactorSvc.GetByID(ctx, bnfparam.GetBenefactorByIDRequest{BenefactorID: kb.Data.BenefactorID})
if gErr != nil {
fmt.Println(fmt.Errorf("error(%s):%w", op, gErr))
}
s.smsAdapter.Send(bnf.PhoneNumber, fmt.Sprintf(smsmsg.SmsMsgKindBoxReqDelivered, bnf.FirstName))
}