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" adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
agentkindboxservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box" agentkindboxservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth" authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
"git.gocasts.ir/ebhomengo/niki/service/notification"
) )
type Handler struct { type Handler struct {
authSvc authservice.Service authSvc authservice.Service
agentKindBoxSvc agentkindboxservice.Service agentKindBoxSvc agentkindboxservice.Service
adminAuthorizeSvc adminauthorizationservice.Service adminAuthorizeSvc adminauthorizationservice.Service
notificationSvc notification.Service
} }
func New(authSvc authservice.Service, func New(authSvc authservice.Service,
agentKindBoxSvc agentkindboxservice.Service, agentKindBoxSvc agentkindboxservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service, adminAuthorizeSvc adminauthorizationservice.Service,
notificationSvc notification.Service,
) Handler { ) Handler {
return Handler{ return Handler{
authSvc: authSvc, authSvc: authSvc,
agentKindBoxSvc: agentKindBoxSvc, agentKindBoxSvc: agentKindBoxSvc,
adminAuthorizeSvc: adminAuthorizeSvc, adminAuthorizeSvc: adminAuthorizeSvc,
notificationSvc: notificationSvc,
} }
} }

View File

@ -3,6 +3,7 @@ package agentkindboxhandler
import ( import (
"net/http" "net/http"
params "git.gocasts.ir/ebhomengo/niki/param"
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box" param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
"git.gocasts.ir/ebhomengo/niki/pkg/claim" "git.gocasts.ir/ebhomengo/niki/pkg/claim"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" 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) return echo.NewHTTPError(code, msg)
} }
go h.notificationSvc.KindBoxReturned(params.NotificationKindBoxReturned{
KindBoxID: req.KindBoxID,
})
return c.NoContent(http.StatusNoContent) return c.NoContent(http.StatusNoContent)
} }

View File

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

View File

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

View File

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

View File

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

View File

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