2026-05-19 11:00:28 +00:00
|
|
|
// Code scaffolded by goctl. Safe to edit.
|
|
|
|
|
// goctl 1.10.1
|
|
|
|
|
|
|
|
|
|
package svc
|
|
|
|
|
|
|
|
|
|
import (
|
2026-05-20 07:01:08 +00:00
|
|
|
"context"
|
|
|
|
|
|
2026-05-19 11:00:28 +00:00
|
|
|
"gateway/internal/config"
|
2026-05-20 23:51:22 +00:00
|
|
|
libmongo "gateway/internal/library/mongo"
|
2026-05-20 07:01:08 +00:00
|
|
|
redislib "gateway/internal/library/redis"
|
2026-05-19 12:56:32 +00:00
|
|
|
"gateway/internal/library/validate"
|
2026-05-21 06:45:35 +00:00
|
|
|
"gateway/internal/library/zitadel"
|
|
|
|
|
authdomrepo "gateway/internal/model/auth/domain/repository"
|
|
|
|
|
domauth "gateway/internal/model/auth/domain/usecase"
|
|
|
|
|
authrepo "gateway/internal/model/auth/repository"
|
|
|
|
|
authusecase "gateway/internal/model/auth/usecase"
|
2026-05-20 13:03:59 +00:00
|
|
|
domrepo "gateway/internal/model/member/domain/repository"
|
2026-05-20 07:01:08 +00:00
|
|
|
dommember "gateway/internal/model/member/domain/usecase"
|
|
|
|
|
memberusecase "gateway/internal/model/member/usecase"
|
|
|
|
|
domnotif "gateway/internal/model/notification/domain/usecase"
|
|
|
|
|
notifusecase "gateway/internal/model/notification/usecase"
|
|
|
|
|
"gateway/internal/worker/notification_retry"
|
2026-05-19 11:00:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ServiceContext struct {
|
2026-05-21 06:45:35 +00:00
|
|
|
Config config.Config
|
|
|
|
|
Validator validate.Validate
|
|
|
|
|
Redis *redislib.Client
|
|
|
|
|
AuthToken domauth.TokenUseCase
|
|
|
|
|
AuthInvite domauth.InviteUseCase
|
|
|
|
|
AuthRegistrationMeta domauth.RegistrationMetaUseCase
|
|
|
|
|
AuthRegistrationSession domauth.RegistrationSessionUseCase
|
|
|
|
|
AuthLoginSession domauth.LoginSessionUseCase
|
|
|
|
|
Zitadel *zitadel.Client
|
|
|
|
|
Notifier domnotif.NotifierUseCase
|
|
|
|
|
NotificationAdmin domnotif.AdminNotifierUseCase
|
|
|
|
|
NotificationRetry *notification_retry.Runner
|
2026-05-20 13:03:59 +00:00
|
|
|
|
2026-05-20 23:51:22 +00:00
|
|
|
MemberOTP dommember.OTPUseCase
|
|
|
|
|
MemberTOTP dommember.TOTPUseCase
|
|
|
|
|
MemberProfile dommember.ProfileUseCase
|
|
|
|
|
MemberLifecycle dommember.LifecycleUseCase
|
|
|
|
|
MemberProvisioning dommember.ProvisioningUseCase
|
|
|
|
|
MemberTenant dommember.TenantUseCase
|
2026-05-21 06:45:35 +00:00
|
|
|
MemberVerifyRate dommember.VerifyRateUseCase
|
2026-05-20 23:51:22 +00:00
|
|
|
MemberRepo domrepo.MemberRepository
|
2026-05-19 11:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
2026-05-19 12:56:32 +00:00
|
|
|
v, err := validate.NewWithDefaultEN()
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 07:01:08 +00:00
|
|
|
rds, err := redislib.NewClient(c.Redis)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sc := &ServiceContext{
|
2026-05-19 12:56:32 +00:00
|
|
|
Config: c,
|
|
|
|
|
Validator: v,
|
2026-05-20 07:01:08 +00:00
|
|
|
Redis: rds,
|
|
|
|
|
}
|
2026-05-21 06:45:35 +00:00
|
|
|
authCfg := c.Auth.Defaults()
|
|
|
|
|
if authCfg.Enabled() {
|
|
|
|
|
var revoke authdomrepo.TokenRevokeStore
|
|
|
|
|
if rds != nil && rds.Zero() != nil {
|
|
|
|
|
revoke = authrepo.NewRedisTokenRevokeStore(rds)
|
|
|
|
|
}
|
|
|
|
|
sc.AuthToken = authusecase.MustTokenUseCase(authusecase.TokenUseCaseParam{
|
|
|
|
|
Config: authCfg,
|
|
|
|
|
Revoke: revoke,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
zClient, err := zitadel.NewClient(c.Zitadel)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
sc.Zitadel = zClient
|
2026-05-20 07:01:08 +00:00
|
|
|
if c.Mongo.Host != "" {
|
|
|
|
|
mod, err := notifusecase.NewModuleFromParam(notifusecase.FactoryParam{
|
|
|
|
|
MongoConf: &c.Mongo,
|
|
|
|
|
Redis: rds,
|
|
|
|
|
Config: c.Notification,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
sc.Notifier = mod.Notifier
|
|
|
|
|
sc.NotificationAdmin = mod.Admin
|
|
|
|
|
sc.NotificationRetry = notification_retry.NewRunner(mod.RetryWorker)
|
2026-05-21 06:45:35 +00:00
|
|
|
|
|
|
|
|
authMod, err := authusecase.NewModuleFromParam(authusecase.ModuleParam{
|
|
|
|
|
MongoConf: &c.Mongo,
|
|
|
|
|
Redis: rds,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
sc.AuthInvite = authMod.Invite
|
|
|
|
|
sc.AuthRegistrationMeta = authMod.RegistrationMeta
|
|
|
|
|
sc.AuthRegistrationSession = authMod.RegistrationSession
|
|
|
|
|
sc.AuthLoginSession = authMod.LoginSession
|
2026-05-20 07:01:08 +00:00
|
|
|
}
|
2026-05-20 13:03:59 +00:00
|
|
|
if rds != nil && rds.Zero() != nil {
|
2026-05-20 23:51:22 +00:00
|
|
|
var mongoConf *libmongo.Conf
|
|
|
|
|
if c.Mongo.Host != "" {
|
|
|
|
|
mongoConf = &c.Mongo
|
|
|
|
|
}
|
2026-05-20 07:01:08 +00:00
|
|
|
memberMod, err := memberusecase.NewModuleFromParam(memberusecase.ModuleParam{
|
2026-05-20 23:51:22 +00:00
|
|
|
Redis: rds,
|
|
|
|
|
MongoConf: mongoConf,
|
|
|
|
|
Config: c.Member,
|
2026-05-20 07:01:08 +00:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2026-05-20 13:03:59 +00:00
|
|
|
sc.MemberOTP = memberMod.OTP
|
|
|
|
|
sc.MemberTOTP = memberMod.TOTP
|
|
|
|
|
sc.MemberProfile = memberMod.Profile
|
2026-05-20 23:51:22 +00:00
|
|
|
sc.MemberLifecycle = memberMod.Lifecycle
|
|
|
|
|
sc.MemberProvisioning = memberMod.Provisioning
|
|
|
|
|
sc.MemberTenant = memberMod.Tenant
|
|
|
|
|
sc.MemberVerifyRate = memberMod.VerifyRate
|
|
|
|
|
sc.MemberRepo = memberMod.Members
|
2026-05-20 07:01:08 +00:00
|
|
|
}
|
|
|
|
|
return sc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (sc *ServiceContext) StartWorkers(ctx context.Context) {
|
|
|
|
|
if sc.NotificationRetry != nil {
|
|
|
|
|
sc.NotificationRetry.Start(ctx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (sc *ServiceContext) StopWorkers() {
|
|
|
|
|
if sc.NotificationRetry != nil {
|
|
|
|
|
sc.NotificationRetry.Stop()
|
2026-05-19 11:00:28 +00:00
|
|
|
}
|
|
|
|
|
}
|