forked from ebhomengo/niki
				
			Merge pull request 'feat(niki): implement kind box req accepted notification' (#106) from kind-box-req-accepted-notification into develop
Reviewed-on: ebhomengo/niki#106
This commit is contained in:
		
						commit
						f82c85b455
					
				| 
						 | 
					@ -6,6 +6,6 @@ type Adapter struct {
 | 
				
			||||||
	adapter *kavenegar.Adapter
 | 
						adapter *kavenegar.Adapter
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func New(adapter *kavenegar.Adapter) Adapter {
 | 
					func New(adapter *kavenegar.Adapter) *Adapter {
 | 
				
			||||||
	return Adapter{adapter: adapter}
 | 
						return &Adapter{adapter: adapter}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,7 +7,8 @@ import (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *Adapter) Send(phoneNumber, message string) {
 | 
					func (a *Adapter) Send(phoneNumber, message string) {
 | 
				
			||||||
	const op = "kavenegarnotification.SendNotification"
 | 
						const op = "kavenegarnotification.Send"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var params *kavenegar.MessageSendParam
 | 
						var params *kavenegar.MessageSendParam
 | 
				
			||||||
	if _, err := a.adapter.Client().Message.Send(a.adapter.Config().Sender, []string{phoneNumber}, message, params); err != nil {
 | 
						if _, err := a.adapter.Client().Message.Send(a.adapter.Config().Sender, []string{phoneNumber}, message, params); err != nil {
 | 
				
			||||||
		//nolint
 | 
							//nolint
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,7 +29,7 @@ benefactor_service:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
kavenegar_sms_provider:
 | 
					kavenegar_sms_provider:
 | 
				
			||||||
  api_key: insert_your_api_key
 | 
					  api_key: insert_your_api_key
 | 
				
			||||||
  sender: ""
 | 
					  sender: insert_sender_number
 | 
				
			||||||
  otp_template_new_user: ebhomeverify
 | 
					  otp_template_new_user: ebhomeverify
 | 
				
			||||||
  otp_template_registered_user: ebhomeverify
 | 
					  otp_template_registered_user: ebhomeverify
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import (
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						params "git.gocasts.ir/ebhomengo/niki/param"
 | 
				
			||||||
	param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
 | 
						param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
 | 
				
			||||||
	errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
 | 
						errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
 | 
				
			||||||
	httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
 | 
						httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
 | 
				
			||||||
| 
						 | 
					@ -46,6 +47,7 @@ func (h Handler) Accept(c echo.Context) error {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return echo.NewHTTPError(code, msg)
 | 
							return echo.NewHTTPError(code, msg)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						go h.notificationSvc.KindBoxReqAccepted(params.NotificationKindBoxReqAccepted{KindBoxReqID: req.ID})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return c.JSON(http.StatusOK, resp)
 | 
						return c.JSON(http.StatusOK, resp)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import (
 | 
				
			||||||
	adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
 | 
						adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
 | 
				
			||||||
	adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
 | 
						adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/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"
 | 
				
			||||||
	adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
 | 
						adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,11 +14,12 @@ type Handler struct {
 | 
				
			||||||
	adminKindBoxReqSvc adminkindboxreqservice.Service
 | 
						adminKindBoxReqSvc adminkindboxreqservice.Service
 | 
				
			||||||
	adminKindBoxReqVld adminkindboxreqvalidator.Validator
 | 
						adminKindBoxReqVld adminkindboxreqvalidator.Validator
 | 
				
			||||||
	adminAuthorizeSvc  adminauthorizationservice.Service
 | 
						adminAuthorizeSvc  adminauthorizationservice.Service
 | 
				
			||||||
 | 
						notificationSvc    notification.Service
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func New(authConfig authservice.Config, authSvc authservice.Service,
 | 
					func New(authConfig authservice.Config, authSvc authservice.Service,
 | 
				
			||||||
	adminKindBoxReqSvc adminkindboxreqservice.Service, adminKindBoxReqVld adminkindboxreqvalidator.Validator,
 | 
						adminKindBoxReqSvc adminkindboxreqservice.Service, adminKindBoxReqVld adminkindboxreqvalidator.Validator,
 | 
				
			||||||
	adminAuthorizeSvc adminauthorizationservice.Service,
 | 
						adminAuthorizeSvc adminauthorizationservice.Service, notificationSvc notification.Service,
 | 
				
			||||||
) Handler {
 | 
					) Handler {
 | 
				
			||||||
	return Handler{
 | 
						return Handler{
 | 
				
			||||||
		authConfig:         authConfig,
 | 
							authConfig:         authConfig,
 | 
				
			||||||
| 
						 | 
					@ -25,5 +27,6 @@ func New(authConfig authservice.Config, authSvc authservice.Service,
 | 
				
			||||||
		adminKindBoxReqSvc: adminKindBoxReqSvc,
 | 
							adminKindBoxReqSvc: adminKindBoxReqSvc,
 | 
				
			||||||
		adminKindBoxReqVld: adminKindBoxReqVld,
 | 
							adminKindBoxReqVld: adminKindBoxReqVld,
 | 
				
			||||||
		adminAuthorizeSvc:  adminAuthorizeSvc,
 | 
							adminAuthorizeSvc:  adminAuthorizeSvc,
 | 
				
			||||||
 | 
							notificationSvc:    notificationSvc,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,6 +23,7 @@ import (
 | 
				
			||||||
	benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
 | 
						benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
 | 
				
			||||||
	benefactorkindboxservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box"
 | 
						benefactorkindboxservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box"
 | 
				
			||||||
	benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
 | 
						benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
 | 
				
			||||||
 | 
						"git.gocasts.ir/ebhomengo/niki/service/notification"
 | 
				
			||||||
	adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
 | 
						adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
 | 
				
			||||||
	adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
 | 
						adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
 | 
				
			||||||
	adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
 | 
						adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
 | 
				
			||||||
| 
						 | 
					@ -70,6 +71,7 @@ func New(
 | 
				
			||||||
	adminKindBoxVld adminkindboxvalidator.Validator,
 | 
						adminKindBoxVld adminkindboxvalidator.Validator,
 | 
				
			||||||
	agentKindBoxSvc agentkindboxservice.Service,
 | 
						agentKindBoxSvc agentkindboxservice.Service,
 | 
				
			||||||
	agentKindBoxVld agentkindboxvalidator.Validator,
 | 
						agentKindBoxVld agentkindboxvalidator.Validator,
 | 
				
			||||||
 | 
						notificationSvc notification.Service,
 | 
				
			||||||
) Server {
 | 
					) Server {
 | 
				
			||||||
	return Server{
 | 
						return Server{
 | 
				
			||||||
		Router:                      echo.New(),
 | 
							Router:                      echo.New(),
 | 
				
			||||||
| 
						 | 
					@ -79,7 +81,7 @@ func New(
 | 
				
			||||||
		benefactorAddressHandler:    benefactoraddresshandler.New(cfg.Auth, benefactorAuthSvc, benefactorAddressSvc, benefactorAddressVld),
 | 
							benefactorAddressHandler:    benefactoraddresshandler.New(cfg.Auth, benefactorAuthSvc, benefactorAddressSvc, benefactorAddressVld),
 | 
				
			||||||
		benefactorKindBoxHandler:    benefactorkindboxhandler.New(cfg.Auth, benefactorAuthSvc, benefactorKindBoxSvc, benefactorKindBoxVld),
 | 
							benefactorKindBoxHandler:    benefactorkindboxhandler.New(cfg.Auth, benefactorAuthSvc, benefactorKindBoxSvc, benefactorKindBoxVld),
 | 
				
			||||||
		adminHandler:                adminhandler.New(cfg.AdminAuth, adminAuthSvc, adminSvc, adminVld, adminAuthorizeSvc),
 | 
							adminHandler:                adminhandler.New(cfg.AdminAuth, adminAuthSvc, adminSvc, adminVld, adminAuthorizeSvc),
 | 
				
			||||||
		adminKindBoxReqHandler:      adminkindboxreqhandler.New(cfg.Auth, adminAuthSvc, adminKinBoxReqSvc, adminKinBoxReqVld, adminAuthorizeSvc),
 | 
							adminKindBoxReqHandler:      adminkindboxreqhandler.New(cfg.Auth, adminAuthSvc, adminKinBoxReqSvc, adminKinBoxReqVld, adminAuthorizeSvc, notificationSvc),
 | 
				
			||||||
		adminKindBoxHandler:         adminKindBoxHandler.New(cfg.Auth, adminAuthSvc, adminKindBoxSvc, adminKindBoxVld, adminAuthorizeSvc),
 | 
							adminKindBoxHandler:         adminKindBoxHandler.New(cfg.Auth, adminAuthSvc, adminKindBoxSvc, adminKindBoxVld, adminAuthorizeSvc),
 | 
				
			||||||
		agentKindBoxHandler:         agentkindboxhandler.New(cfg.AdminAuth, adminAuthSvc, agentKindBoxSvc, agentKindBoxVld, adminAuthorizeSvc),
 | 
							agentKindBoxHandler:         agentkindboxhandler.New(cfg.AdminAuth, adminAuthSvc, agentKindBoxSvc, agentKindBoxVld, adminAuthorizeSvc),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ package initial
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"git.gocasts.ir/ebhomengo/niki/adapter/redis"
 | 
						"git.gocasts.ir/ebhomengo/niki/adapter/redis"
 | 
				
			||||||
	smsprovider "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar"
 | 
						smsprovider "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar"
 | 
				
			||||||
 | 
						kavenegarnotification "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar/notification"
 | 
				
			||||||
	kavenegarotp "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar/otp"
 | 
						kavenegarotp "git.gocasts.ir/ebhomengo/niki/adapter/sms_provider/kavenegar/otp"
 | 
				
			||||||
	"git.gocasts.ir/ebhomengo/niki/config"
 | 
						"git.gocasts.ir/ebhomengo/niki/config"
 | 
				
			||||||
	"git.gocasts.ir/ebhomengo/niki/repository/mysql"
 | 
						"git.gocasts.ir/ebhomengo/niki/repository/mysql"
 | 
				
			||||||
| 
						 | 
					@ -21,6 +22,7 @@ import (
 | 
				
			||||||
	benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
 | 
						benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
 | 
				
			||||||
	benefactorkindboxservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box"
 | 
						benefactorkindboxservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box"
 | 
				
			||||||
	benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
 | 
						benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
 | 
				
			||||||
 | 
						"git.gocasts.ir/ebhomengo/niki/service/notification"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Services struct {
 | 
					type Services struct {
 | 
				
			||||||
| 
						 | 
					@ -33,25 +35,30 @@ type Services struct {
 | 
				
			||||||
	AdminSvc                adminservice.Service
 | 
						AdminSvc                adminservice.Service
 | 
				
			||||||
	AdminKindBoxReqSvc      adminkindboxreqservice.Service
 | 
						AdminKindBoxReqSvc      adminkindboxreqservice.Service
 | 
				
			||||||
	AdminReferTimeSvc       adminrefertimeservice.Service
 | 
						AdminReferTimeSvc       adminrefertimeservice.Service
 | 
				
			||||||
 | 
						NotificationSvc         notification.Service
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func initSms(cfg config.Config) *kavenegarotp.Adapter {
 | 
					func initSmsOtp(cfg config.Config) *kavenegarotp.Adapter {
 | 
				
			||||||
	return kavenegarotp.New(smsprovider.New(cfg.KavenegarSmsProvider))
 | 
						return kavenegarotp.New(smsprovider.New(cfg.KavenegarSmsProvider))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func initSmsNotification(cfg config.Config) *kavenegarnotification.Adapter {
 | 
				
			||||||
 | 
						return kavenegarnotification.New(smsprovider.New(cfg.KavenegarSmsProvider))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func InitAdminService(cfg config.Config, db *mysql.DB) adminservice.Service {
 | 
					func InitAdminService(cfg config.Config, db *mysql.DB) adminservice.Service {
 | 
				
			||||||
	return adminservice.New(InitAdminMysql(db), InitAdminAuthService(cfg))
 | 
						return adminservice.New(InitAdminMysql(db), InitAdminAuthService(cfg))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func InitBenefactorForAdminService(db *mysql.DB) benefactorforadminservice.Service {
 | 
					func InitBenefactorForAdminService(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) benefactorforadminservice.Service {
 | 
				
			||||||
	return benefactorforadminservice.New(InitAdminMysql(db))
 | 
						return benefactorforadminservice.New(InitAdminMysql(db), InitBenefactorService(cfg, redisAdapter, db))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func InitBenefactorService(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) benefactorservice.Service {
 | 
					func InitBenefactorService(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) benefactorservice.Service {
 | 
				
			||||||
	return benefactorservice.New(
 | 
						return benefactorservice.New(
 | 
				
			||||||
		cfg.BenefactorSvc,
 | 
							cfg.BenefactorSvc,
 | 
				
			||||||
		redisotp.New(redisAdapter),
 | 
							redisotp.New(redisAdapter),
 | 
				
			||||||
		initSms(cfg),
 | 
							initSmsOtp(cfg),
 | 
				
			||||||
		InitBenefactorAuthService(cfg),
 | 
							InitBenefactorAuthService(cfg),
 | 
				
			||||||
		mysqlbenefactor.New(db),
 | 
							mysqlbenefactor.New(db),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
| 
						 | 
					@ -86,3 +93,7 @@ func InitAdminReferTimeService(db *mysql.DB) adminrefertimeservice.Service {
 | 
				
			||||||
func InitBenefactorKindBoxService(db *mysql.DB) benefactorkindboxservice.Service {
 | 
					func InitBenefactorKindBoxService(db *mysql.DB) benefactorkindboxservice.Service {
 | 
				
			||||||
	return benefactorkindboxservice.New(mysqlkindbox.New(db))
 | 
						return benefactorkindboxservice.New(mysqlkindbox.New(db))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func InitNotificationService(cfg config.Config, redisAdapter redis.Adapter, db *mysql.DB) notification.Service {
 | 
				
			||||||
 | 
						return notification.New(initSmsNotification(cfg), InitAdminKindBoxReqService(db), InitBenefactorForAdminService(cfg, redisAdapter, db))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,8 +25,8 @@ type Validators struct {
 | 
				
			||||||
	AgentKindBoxVld         agentkindboxvalidator.Validator
 | 
						AgentKindBoxVld         agentkindboxvalidator.Validator
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func InitAdminKindBoxReqValidator(db *mysql.DB, cfg config.Config) adminkindboxreqvalidator.Validator {
 | 
					func InitAdminKindBoxReqValidator(db *mysql.DB, cfg config.Config, redisAdapter redis.Adapter) adminkindboxreqvalidator.Validator {
 | 
				
			||||||
	return adminkindboxreqvalidator.New(InitBenefactorKindBoxReqDB(db), InitAdminService(cfg, db), InitBenefactorForAdminService(db), InitAdminReferTimeService(db), InitBenefactorAddressService(db))
 | 
						return adminkindboxreqvalidator.New(InitBenefactorKindBoxReqDB(db), InitAdminService(cfg, db), InitBenefactorForAdminService(cfg, redisAdapter, db), InitAdminReferTimeService(db), InitBenefactorAddressService(db))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func InitAdminValidator(db *mysql.DB) adminvalidator.Validator {
 | 
					func InitAdminValidator(db *mysql.DB) adminvalidator.Validator {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										5
									
								
								main.go
								
								
								
								
							
							
						
						
									
										5
									
								
								main.go
								
								
								
								
							| 
						 | 
					@ -70,7 +70,7 @@ func initDependencies(cfg config.Config, redisAdapter redis.Adapter, db *mysql.D
 | 
				
			||||||
			BenefactorKindBoxReqVld: initial.InitBenefactorKindBoxReqValidator(cfg, redisAdapter, db),
 | 
								BenefactorKindBoxReqVld: initial.InitBenefactorKindBoxReqValidator(cfg, redisAdapter, db),
 | 
				
			||||||
			BenefactorAddressVld:    initial.InitBenefactorAddressValidator(cfg, redisAdapter, db),
 | 
								BenefactorAddressVld:    initial.InitBenefactorAddressValidator(cfg, redisAdapter, db),
 | 
				
			||||||
			BenefactorKindBoxVld:    initial.InitBenefactorKindBoxValidator(cfg, redisAdapter, db),
 | 
								BenefactorKindBoxVld:    initial.InitBenefactorKindBoxValidator(cfg, redisAdapter, db),
 | 
				
			||||||
			AdminKindBoxReqVld:      initial.InitAdminKindBoxReqValidator(db, cfg),
 | 
								AdminKindBoxReqVld:      initial.InitAdminKindBoxReqValidator(db, cfg, redisAdapter),
 | 
				
			||||||
			AdminVld:                initial.InitAdminValidator(db),
 | 
								AdminVld:                initial.InitAdminValidator(db),
 | 
				
			||||||
			AdminKindBoxVld:         initial.InitAdminKindBoxValidator(db, cfg),
 | 
								AdminKindBoxVld:         initial.InitAdminKindBoxValidator(db, cfg),
 | 
				
			||||||
			AgentKindBoxVld:         initial.InitAgentKindBoxValidator(db),
 | 
								AgentKindBoxVld:         initial.InitAgentKindBoxValidator(db),
 | 
				
			||||||
| 
						 | 
					@ -85,6 +85,7 @@ func initDependencies(cfg config.Config, redisAdapter redis.Adapter, db *mysql.D
 | 
				
			||||||
			AdminKindBoxReqSvc:      initial.InitAdminKindBoxReqService(db),
 | 
								AdminKindBoxReqSvc:      initial.InitAdminKindBoxReqService(db),
 | 
				
			||||||
			AdminSvc:                initial.InitAdminService(cfg, db),
 | 
								AdminSvc:                initial.InitAdminService(cfg, db),
 | 
				
			||||||
			AdminReferTimeSvc:       initial.InitAdminReferTimeService(db),
 | 
								AdminReferTimeSvc:       initial.InitAdminReferTimeService(db),
 | 
				
			||||||
 | 
								NotificationSvc:         initial.InitNotificationService(cfg, redisAdapter, db),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		initial.AdminAuthorization{
 | 
							initial.AdminAuthorization{
 | 
				
			||||||
			AdminAuthorizationSvc: initial.InitAdminAuthorizationService(db),
 | 
								AdminAuthorizationSvc: initial.InitAdminAuthorizationService(db),
 | 
				
			||||||
| 
						 | 
					@ -101,7 +102,7 @@ func initAndRunServer(cfg config.Config, dependencies *Dependencies) {
 | 
				
			||||||
		dependencies.AdminSvc, dependencies.AdminVld, dependencies.AdminAuthSvc,
 | 
							dependencies.AdminSvc, dependencies.AdminVld, dependencies.AdminAuthSvc,
 | 
				
			||||||
		dependencies.AdminKindBoxReqSvc, dependencies.AdminKindBoxReqVld, dependencies.AdminAuthorizationSvc,
 | 
							dependencies.AdminKindBoxReqSvc, dependencies.AdminKindBoxReqVld, dependencies.AdminAuthorizationSvc,
 | 
				
			||||||
		dependencies.AdminKindBoxSvc, dependencies.AdminKindBoxVld,
 | 
							dependencies.AdminKindBoxSvc, dependencies.AdminKindBoxVld,
 | 
				
			||||||
		dependencies.AgentKindBoxSvc, dependencies.AgentKindBoxVld)
 | 
							dependencies.AgentKindBoxSvc, dependencies.AgentKindBoxVld, dependencies.NotificationSvc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	server.Serve()
 | 
						server.Serve()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					package adminbenefactoreparam
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "git.gocasts.ir/ebhomengo/niki/entity"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GetBenefactorByIDRequest struct {
 | 
				
			||||||
 | 
						BenefactorID uint
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					type GetBenefactorByIDResponse struct {
 | 
				
			||||||
 | 
						entity.Benefactor
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					package param
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type NotificationKindBoxReqAccepted struct {
 | 
				
			||||||
 | 
						KindBoxReqID uint
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					package smsmsg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						SmsMsgKindBoxReqAccepted = "%s عزیز درخواست قلک شما پذیرفته شد"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -119,3 +119,25 @@ func mapNotNullToBenefactor(data nullableFields, benefactor *entity.Benefactor)
 | 
				
			||||||
		benefactor.BirthDate = data.birthdate.Time
 | 
							benefactor.BirthDate = data.birthdate.Time
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *DB) GetByID(ctx context.Context, benefactorID uint) (entity.Benefactor, error) {
 | 
				
			||||||
 | 
						const op = "mysqlbenefactor.IsExistBenefactorByID"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						row := d.conn.Conn().QueryRowContext(ctx, `select * from benefactors where id = ?`, benefactorID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bnf, err := scanBenefactor(row)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							sErr := sql.ErrNoRows
 | 
				
			||||||
 | 
							//TODO-errorsas: second argument to errors.As should not be *error
 | 
				
			||||||
 | 
							//nolint
 | 
				
			||||||
 | 
							if errors.As(err, &sErr) {
 | 
				
			||||||
 | 
								return bnf, nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// TODO - log unexpected error for better observability
 | 
				
			||||||
 | 
							return bnf, richerror.New(op).WithErr(err).
 | 
				
			||||||
 | 
								WithMessage(errmsg.ErrorMsgCantScanQueryResult).WithKind(richerror.KindUnexpected)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return bnf, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
package benefactor
 | 
					package adminbenefactorservice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,14 +1,26 @@
 | 
				
			||||||
package benefactor
 | 
					package adminbenefactorservice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	param "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
 | 
						param "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
 | 
				
			||||||
 | 
						params "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
 | 
				
			||||||
	richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
 | 
						richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s Service) GetByID(ctx context.Context, req params.GetBenefactorByIDRequest) (params.GetBenefactorByIDResponse, error) {
 | 
				
			||||||
 | 
						const op = "adminbenefactorservice.GetByID"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bnf, gErr := s.benefactorService.GetByID(ctx, req)
 | 
				
			||||||
 | 
						if gErr != nil {
 | 
				
			||||||
 | 
							return params.GetBenefactorByIDResponse{}, richerror.New(op).WithErr(gErr)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return params.GetBenefactorByIDResponse{Benefactor: bnf.Benefactor}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s Service) BenefactorExistByID(ctx context.Context, req param.BenefactorExistByIDRequest) (param.BenefactorExistByIDResponse, error) {
 | 
					func (s Service) BenefactorExistByID(ctx context.Context, req param.BenefactorExistByIDRequest) (param.BenefactorExistByIDResponse, error) {
 | 
				
			||||||
	const op = "adminservice.BenefactorExistByID"
 | 
						const op = "adminbenefactorservice.BenefactorExistByID"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	isExisted, err := s.repo.IsExistBenefactorByID(ctx, req.ID)
 | 
						isExisted, err := s.repo.IsExistBenefactorByID(ctx, req.ID)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,25 +1,25 @@
 | 
				
			||||||
package benefactor
 | 
					package adminbenefactorservice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.gocasts.ir/ebhomengo/niki/entity"
 | 
						"git.gocasts.ir/ebhomengo/niki/entity"
 | 
				
			||||||
	param "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
 | 
						params "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Repository interface {
 | 
					type Repository interface {
 | 
				
			||||||
	IsExistBenefactorByID(ctx context.Context, id uint) (bool, error)
 | 
						IsExistBenefactorByID(ctx context.Context, id uint) (bool, error)
 | 
				
			||||||
	GetAddressByID(ctx context.Context, id uint) (*entity.Address, error)
 | 
						GetAddressByID(ctx context.Context, id uint) (*entity.Address, error)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
type ForAdminSvc interface {
 | 
					type BenefactorService interface {
 | 
				
			||||||
	BenefactorExistByID(ctx context.Context, request param.BenefactorExistByIDRequest) (param.BenefactorExistByIDResponse, error)
 | 
						GetByID(ctx context.Context, req params.GetBenefactorByIDRequest) (params.GetBenefactorByIDResponse, error)
 | 
				
			||||||
	AddressExistByID(ctx context.Context, request param.GetAddressByIDRequest) (param.GetAddressByIDResponse, error)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Service struct {
 | 
					type Service struct {
 | 
				
			||||||
	repo Repository
 | 
						repo              Repository
 | 
				
			||||||
 | 
						benefactorService BenefactorService
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func New(repo Repository) Service {
 | 
					func New(repo Repository, benefactorService BenefactorService) Service {
 | 
				
			||||||
	return Service{repo: repo}
 | 
						return Service{repo: repo, benefactorService: benefactorService}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ package benefactorservice
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						params "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
 | 
				
			||||||
	param "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactore"
 | 
						param "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactore"
 | 
				
			||||||
	richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
 | 
						richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -17,3 +18,14 @@ func (s Service) BenefactorExistByID(ctx context.Context, req param.BenefactorEx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return param.BenefactorExistByIDResponse{Existed: isExisted}, nil
 | 
						return param.BenefactorExistByIDResponse{Existed: isExisted}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s Service) GetByID(ctx context.Context, req params.GetBenefactorByIDRequest) (params.GetBenefactorByIDResponse, error) {
 | 
				
			||||||
 | 
						const op = "benefactorservice.GetByID"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bnf, gErr := s.repo.GetByID(ctx, req.BenefactorID)
 | 
				
			||||||
 | 
						if gErr != nil {
 | 
				
			||||||
 | 
							return params.GetBenefactorByIDResponse{}, richerror.New(op).WithErr(gErr)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return params.GetBenefactorByIDResponse{Benefactor: bnf}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,7 @@ type Repository interface {
 | 
				
			||||||
	IsExistBenefactorByPhoneNumber(ctx context.Context, phoneNumber string) (bool, entity.Benefactor, error)
 | 
						IsExistBenefactorByPhoneNumber(ctx context.Context, phoneNumber string) (bool, entity.Benefactor, error)
 | 
				
			||||||
	CreateBenefactor(ctx context.Context, benefactor entity.Benefactor) (entity.Benefactor, error)
 | 
						CreateBenefactor(ctx context.Context, benefactor entity.Benefactor) (entity.Benefactor, error)
 | 
				
			||||||
	IsExistBenefactorByID(ctx context.Context, id uint) (bool, error)
 | 
						IsExistBenefactorByID(ctx context.Context, id uint) (bool, error)
 | 
				
			||||||
 | 
						GetByID(ctx context.Context, benefactorID uint) (entity.Benefactor, error)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type AuthGenerator interface {
 | 
					type AuthGenerator interface {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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) KindBoxReqAccepted(req params.NotificationKindBoxReqAccepted) {
 | 
				
			||||||
 | 
						const op = "notification.KindBoxReqAccepted"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 err != nil {
 | 
				
			||||||
 | 
							fmt.Println(fmt.Errorf("error(%s):%w", op, gErr))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						s.smsAdapter.Send(bnf.PhoneNumber, fmt.Sprintf(smsmsg.SmsMsgKindBoxReqAccepted, bnf.FirstName))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,15 +1,34 @@
 | 
				
			||||||
package notification
 | 
					package notification
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						params "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
 | 
				
			||||||
 | 
						param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SmsAdapter interface {
 | 
					type SmsAdapter interface {
 | 
				
			||||||
	Send(phoneNumber string, message string)
 | 
						Send(phoneNumber string, message string)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Service struct {
 | 
					type KindBoxReqSvc interface {
 | 
				
			||||||
	smsAdapter SmsAdapter
 | 
						Get(ctx context.Context, request param.GetKindBoxReqRequest) (param.GetKindBoxReqResponse, error)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func New(smsAdapter SmsAdapter) Service {
 | 
					type BenefactorSvc interface {
 | 
				
			||||||
 | 
						GetByID(ctx context.Context, req params.GetBenefactorByIDRequest) (params.GetBenefactorByIDResponse, error)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Service struct {
 | 
				
			||||||
 | 
						smsAdapter    SmsAdapter
 | 
				
			||||||
 | 
						KindBoxReqSvc KindBoxReqSvc
 | 
				
			||||||
 | 
						BenefactorSvc BenefactorSvc
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func New(smsAdapter SmsAdapter, kindBoxReqSvc KindBoxReqSvc, benefactorSvc BenefactorSvc) Service {
 | 
				
			||||||
	return Service{
 | 
						return Service{
 | 
				
			||||||
		smsAdapter: smsAdapter,
 | 
							smsAdapter:    smsAdapter,
 | 
				
			||||||
 | 
							KindBoxReqSvc: kindBoxReqSvc,
 | 
				
			||||||
 | 
							BenefactorSvc: benefactorSvc,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue