forked from ebhomengo/niki
Merge pull request 'feat(niki): implement admin sms notifications' (#123) from stage/erfan/admin-sms-notifications into develop
Reviewed-on: ebhomengo/niki#123
This commit is contained in:
commit
19649c17d8
|
@ -3,6 +3,7 @@ package adminkindboxhandler
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
@ -40,5 +41,9 @@ func (h Handler) AssignReceiverAgent(c echo.Context) error {
|
|||
return echo.NewHTTPError(code, msg)
|
||||
}
|
||||
|
||||
go h.notificationSvc.KindBoxAssigned(params.NotificationKindBoxAssigned{
|
||||
ReceiverAgentID: req.ReceiverAgentID,
|
||||
})
|
||||
|
||||
return c.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package adminkindboxhandler
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
@ -44,5 +45,9 @@ func (h Handler) Enumerate(c echo.Context) error {
|
|||
return echo.NewHTTPError(code, msg)
|
||||
}
|
||||
|
||||
go h.notificationSvc.KindBoxEnumerated(params.NotificationKindBoxEnumerated{
|
||||
KindBoxID: req.KindBoxID,
|
||||
})
|
||||
|
||||
return c.JSON(http.StatusNoContent, resp)
|
||||
}
|
||||
|
|
|
@ -4,21 +4,25 @@ import (
|
|||
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
|
||||
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
|
||||
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||
"git.gocasts.ir/ebhomengo/niki/service/notification"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
authSvc authservice.Service
|
||||
adminKindBoxSvc adminkindboxservice.Service
|
||||
adminAuthorizeSvc adminauthorizationservice.Service
|
||||
notificationSvc notification.Service
|
||||
}
|
||||
|
||||
func New(authSvc authservice.Service,
|
||||
adminKindBoxSvc adminkindboxservice.Service,
|
||||
adminAuthorizeSvc adminauthorizationservice.Service,
|
||||
notificationSvc notification.Service,
|
||||
) Handler {
|
||||
return Handler{
|
||||
authSvc: authSvc,
|
||||
adminKindBoxSvc: adminKindBoxSvc,
|
||||
adminAuthorizeSvc: adminAuthorizeSvc,
|
||||
notificationSvc: notificationSvc,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
|
@ -50,5 +51,9 @@ func (h Handler) AssignSenderAgent(c echo.Context) error {
|
|||
return echo.NewHTTPError(code, msg)
|
||||
}
|
||||
|
||||
go h.notificationSvc.KindBoxReqAssigned(params.NotificationKindBoxReqAssigned{
|
||||
KindBoxReqID: req.KindBoxReqID,
|
||||
})
|
||||
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
|
@ -45,5 +46,10 @@ func (h Handler) Reject(c echo.Context) error {
|
|||
return echo.NewHTTPError(code, msg)
|
||||
}
|
||||
|
||||
go h.notificationSvc.KindBoxReqRejected(params.NotificationKindBoxReqRejected{
|
||||
KindBoxReqID: req.ID,
|
||||
Description: req.Description,
|
||||
})
|
||||
|
||||
return c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func New(
|
|||
config: cfg,
|
||||
adminHandler: adminhandler.New(svc.AdminAuthSvc, svc.AdminSvc, svc.AdminAuthorizeSvc),
|
||||
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc),
|
||||
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),
|
||||
benefactorHandler: benefactorhandler.New(svc.BenefactorAuthSvc, svc.BenefactorSvc),
|
||||
|
|
|
@ -3,3 +3,20 @@ package param
|
|||
type NotificationKindBoxReqAccepted struct {
|
||||
KindBoxReqID uint
|
||||
}
|
||||
|
||||
type NotificationKindBoxReqRejected struct {
|
||||
KindBoxReqID uint
|
||||
Description string
|
||||
}
|
||||
|
||||
type NotificationKindBoxReqAssigned struct {
|
||||
KindBoxReqID uint
|
||||
}
|
||||
|
||||
type NotificationKindBoxAssigned struct {
|
||||
ReceiverAgentID uint
|
||||
}
|
||||
|
||||
type NotificationKindBoxEnumerated struct {
|
||||
KindBoxID uint
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package smsmsg
|
||||
|
||||
const (
|
||||
SmsMsgKindBoxReqAccepted = "%s عزیز درخواست قلک شما پذیرفته شد"
|
||||
SmsMsgKindBoxReqAccepted = "%s عزیز، درخواست قلک شما پذیرفته شد"
|
||||
SmsMsgKindBoxReqRejected = "%s عزیز، درخواست قلک شما به دلیل %s پذیرفته نشد"
|
||||
SmsMsgKindBoxReqAssigned = "%s عزیز، درخواست قلک شماره %d جهت تحویل به نیکوکار به شما اختصاص داده شد"
|
||||
SmsMsgKindBoxAssigned = "%s عزیز، قلکی جهت تخلیه به شما اختصاص داده شد"
|
||||
SmsMsgKindBoxEnumerated = "%s عزیز، قلک شما با شماره سریال %s و مبلغ %d تومان شمارش شد. از مشارکت شما سپاسگزاریم."
|
||||
)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
||||
smsmsg "git.gocasts.ir/ebhomengo/niki/pkg/sms_msg"
|
||||
)
|
||||
|
||||
func (s Service) KindBoxAssigned(req params.NotificationKindBoxAssigned) {
|
||||
const op = "notification.KindBoxAssigned"
|
||||
|
||||
ctx := context.Background()
|
||||
bnf, gErr := s.AdminSvc.AdminExistByID(ctx, adminserviceparam.AdminExistByIDRequest{AdminID: req.ReceiverAgentID})
|
||||
if gErr != nil {
|
||||
fmt.Println(fmt.Errorf("error(%s):%w", op, gErr))
|
||||
}
|
||||
s.smsAdapter.Send(bnf.Admin.PhoneNumber, fmt.Sprintf(smsmsg.SmsMsgKindBoxAssigned, bnf.Admin.FirstName))
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
params "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) KindBoxEnumerated(req params.NotificationKindBoxEnumerated) {
|
||||
const op = "notification.KindBoxEnumerated"
|
||||
|
||||
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.BenefactorID})
|
||||
if gErr != nil {
|
||||
fmt.Println(fmt.Errorf("error(%s):%w", op, gErr))
|
||||
}
|
||||
s.smsAdapter.Send(bnf.PhoneNumber, fmt.Sprintf(smsmsg.SmsMsgKindBoxEnumerated, bnf.FirstName, kb.SerialNumber, kb.Amount))
|
||||
}
|
|
@ -21,7 +21,7 @@ func (s Service) KindBoxReqAccepted(req params.NotificationKindBoxReqAccepted) {
|
|||
fmt.Println(fmt.Errorf("error(%s):%w", op, err))
|
||||
}
|
||||
bnf, gErr := s.BenefactorSvc.GetByID(ctx, bnfparam.GetBenefactorByIDRequest{BenefactorID: kb.BenefactorID})
|
||||
if err != nil {
|
||||
if gErr != nil {
|
||||
fmt.Println(fmt.Errorf("error(%s):%w", op, gErr))
|
||||
}
|
||||
s.smsAdapter.Send(bnf.PhoneNumber, fmt.Sprintf(smsmsg.SmsMsgKindBoxReqAccepted, bnf.FirstName))
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
||||
kbparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
smsmsg "git.gocasts.ir/ebhomengo/niki/pkg/sms_msg"
|
||||
)
|
||||
|
||||
func (s Service) KindBoxReqAssigned(req params.NotificationKindBoxReqAssigned) {
|
||||
const op = "notification.KindBoxReqAssigned"
|
||||
|
||||
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.AdminSvc.AdminExistByID(ctx, adminserviceparam.AdminExistByIDRequest{AdminID: kb.SenderAgentID})
|
||||
if gErr != nil {
|
||||
fmt.Println(fmt.Errorf("error(%s):%w", op, gErr))
|
||||
}
|
||||
s.smsAdapter.Send(bnf.Admin.PhoneNumber, fmt.Sprintf(smsmsg.SmsMsgKindBoxReqAssigned, bnf.Admin.FirstName, kb.ID))
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
params "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) KindBoxReqRejected(req params.NotificationKindBoxReqRejected) {
|
||||
const op = "notification.KindBoxReqRejected"
|
||||
|
||||
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.BenefactorID})
|
||||
if gErr != nil {
|
||||
fmt.Println(fmt.Errorf("error(%s):%w", op, gErr))
|
||||
}
|
||||
s.smsAdapter.Send(bnf.PhoneNumber, fmt.Sprintf(smsmsg.SmsMsgKindBoxReqRejected, bnf.FirstName, req.Description))
|
||||
}
|
|
@ -4,7 +4,9 @@ import (
|
|||
"context"
|
||||
|
||||
smscontract "git.gocasts.ir/ebhomengo/niki/contract/sms"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
||||
adminbenefactorparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
kbp "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
adminkindboxreqparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
)
|
||||
|
||||
|
@ -16,16 +18,30 @@ type BenefactorSvc interface {
|
|||
GetByID(ctx context.Context, req adminbenefactorparam.GetBenefactorByIDRequest) (adminbenefactorparam.GetBenefactorByIDResponse, error)
|
||||
}
|
||||
|
||||
type AdminSvc interface {
|
||||
AdminExistByID(ctx context.Context, req param.AdminExistByIDRequest) (param.AdminExistByIDResponse, error)
|
||||
}
|
||||
|
||||
type KindBoxSvc interface {
|
||||
Get(ctx context.Context, req kbp.KindBoxGetRequest) (kbp.KindBoxGetResponse, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
smsAdapter smscontract.SmsAdapter
|
||||
KindBoxReqSvc KindBoxReqSvc
|
||||
BenefactorSvc BenefactorSvc
|
||||
AdminSvc AdminSvc
|
||||
KindBoxSvc KindBoxSvc
|
||||
}
|
||||
|
||||
func New(smsAdapter smscontract.SmsAdapter, kindBoxReqSvc KindBoxReqSvc, benefactorSvc BenefactorSvc) Service {
|
||||
func New(smsAdapter smscontract.SmsAdapter, kindBoxReqSvc KindBoxReqSvc, benefactorSvc BenefactorSvc,
|
||||
adminSvc AdminSvc, kindBoxSvc KindBoxSvc,
|
||||
) Service {
|
||||
return Service{
|
||||
smsAdapter: smsAdapter,
|
||||
KindBoxReqSvc: kindBoxReqSvc,
|
||||
BenefactorSvc: benefactorSvc,
|
||||
AdminSvc: adminSvc,
|
||||
KindBoxSvc: kindBoxSvc,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
|||
BenefactorKindBoxVld = benefactorkindboxvalidator.New(kindBoxRepo, BenefactorSvc, BenefactorAddressSvc, BenefactorReferTimeSvc)
|
||||
BenefactorKindBoxSvc = benefactorkindboxservice.New(kindBoxRepo, BenefactorKindBoxVld)
|
||||
)
|
||||
NotificationSvc := notification.New(smsAdapter, AdminKindBoxReqSvc, AdminBenefactorSvc)
|
||||
NotificationSvc := notification.New(smsAdapter, AdminKindBoxReqSvc, AdminBenefactorSvc, AdminSvc, AdminKindBoxSvc)
|
||||
|
||||
return &Service{
|
||||
AdminAuthSvc: AdminAuthSvc,
|
||||
|
|
Loading…
Reference in New Issue