refactor(server): decouple services and improve architecture
- Introduce interfaces for all major services (JWT, PostAI, Comment, Message, Notification, QRCodeLogin, Upload, Vote, etc.) to support dependency inversion. - Move query parameters from `internal/dto` to a new `internal/query` package to separate request payloads from data transfer objects. - Refactor `internal/router` to use embedded `RouterDeps` for cleaner dependency management. - Decouple handlers from repositories by injecting services instead of direct repository access, ensuring proper layering. - Improve database initialization by moving it from `internal/model` to `internal/database`. - Optimize message decryption by implementing a more efficient `BatchDecrypt` method in `MessageEncryptor` using a worker pool. - Enhance error handling and security by implementing fail-fast checks for encryption key length during startup. - Clean up unused code, including the `avatar` package and several unused DTOs.
This commit is contained in:
@@ -19,7 +19,6 @@ import (
|
||||
"with_you/internal/model"
|
||||
"with_you/internal/pkg/response"
|
||||
"with_you/internal/pkg/ws"
|
||||
"with_you/internal/repository"
|
||||
"with_you/internal/service"
|
||||
)
|
||||
|
||||
@@ -69,9 +68,9 @@ type WSHandler struct {
|
||||
publisher ws.MessagePublisher
|
||||
chatService service.ChatService
|
||||
groupService service.GroupService
|
||||
jwtService *service.JWTService
|
||||
jwtService service.JWTService
|
||||
callService service.CallService
|
||||
userRepo repository.UserRepository
|
||||
userService service.UserService
|
||||
clientSeq uint64
|
||||
}
|
||||
|
||||
@@ -92,9 +91,9 @@ func NewWSHandler(
|
||||
publisher ws.MessagePublisher,
|
||||
chatService service.ChatService,
|
||||
groupService service.GroupService,
|
||||
jwtService *service.JWTService,
|
||||
jwtService service.JWTService,
|
||||
callService service.CallService,
|
||||
userRepo repository.UserRepository,
|
||||
userService service.UserService,
|
||||
) *WSHandler {
|
||||
return &WSHandler{
|
||||
publisher: publisher,
|
||||
@@ -102,7 +101,7 @@ func NewWSHandler(
|
||||
groupService: groupService,
|
||||
jwtService: jwtService,
|
||||
callService: callService,
|
||||
userRepo: userRepo,
|
||||
userService: userService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -578,7 +577,7 @@ func (h *WSHandler) handleAck(client *ws.Client, payload json.RawMessage) {
|
||||
|
||||
// isVerified 检查用户是否已通过身份认证
|
||||
func (h *WSHandler) isVerified(ctx context.Context, client *ws.Client) bool {
|
||||
user, err := h.userRepo.GetByID(client.UserID)
|
||||
user, err := h.userService.GetUserByID(ctx, client.UserID)
|
||||
if err != nil {
|
||||
h.publisher.SendError(client, "internal_error", "获取用户信息失败")
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user