Files
backend/internal/service/setup_service.go
lafay fb85c9c20a
Some checks failed
Build Backend / build-docker (push) Has been cancelled
Build Backend / build (push) Has been cancelled
feat(push): add JPush integration for offline message push
Add JPush (极光推送) integration to enable push notifications for offline users. This includes:
- New jpush client package with API for batch push notifications
- Configuration for jpush (enabled, app_key, master_secret, production mode)
- Updated push service to send messages via JPush when users are offline
- Added PushChatMessage method with do-not-disturb checking
- Integrated push service with chat service to notify offline users of new messages
- Updated deployment workflow with JPush and related environment variables
2026-04-27 23:20:24 +08:00

63 lines
1.4 KiB
Go

package service
import (
"context"
apperrors "with_you/internal/errors"
"with_you/internal/model"
"with_you/internal/repository"
)
type SetupService interface {
SetupSuperAdmin(ctx context.Context, userID, setupSecret string) error
}
type setupService struct {
userRepo repository.UserRepository
roleRepo repository.RoleRepository
casbinSvc CasbinService
setupSecret string
}
func NewSetupService(
userRepo repository.UserRepository,
roleRepo repository.RoleRepository,
casbinSvc CasbinService,
setupSecret string,
) SetupService {
return &setupService{
userRepo: userRepo,
roleRepo: roleRepo,
casbinSvc: casbinSvc,
setupSecret: setupSecret,
}
}
func (s *setupService) SetupSuperAdmin(ctx context.Context, userID, setupSecret string) error {
if s.setupSecret == "" {
return apperrors.ErrSetupSecretNotConfigured
}
if setupSecret != s.setupSecret {
return apperrors.ErrInvalidSetupSecret
}
count, err := s.roleRepo.GetRoleUserCount(ctx, model.RoleSuperAdmin)
if err != nil {
return apperrors.ErrInternal
}
if count > 0 {
return apperrors.ErrSetupAlreadyCompleted
}
user, err := s.userRepo.GetByID(userID)
if err != nil {
return apperrors.ErrUserNotFound
}
if user.Status == model.UserStatusBanned {
return apperrors.ErrUserBanned
}
return s.casbinSvc.AddRoleForUser(ctx, user.ID, model.RoleSuperAdmin)
}