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:
@@ -1,9 +1,9 @@
|
||||
package repository
|
||||
package repository
|
||||
|
||||
import (
|
||||
"with_you/internal/dto"
|
||||
"with_you/internal/model"
|
||||
"context"
|
||||
"with_you/internal/model"
|
||||
"with_you/internal/query"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -19,7 +19,7 @@ type ReportRepository interface {
|
||||
// FindByIDWithContext 使用上下文查询举报
|
||||
FindByIDWithContext(ctx context.Context, id string) (*model.Report, error)
|
||||
// List 查询举报列表
|
||||
List(query dto.AdminReportListQuery) ([]*model.Report, int64, error)
|
||||
List(query query.AdminReportListQuery) ([]*model.Report, int64, error)
|
||||
// GetReportCount 获取内容的举报次数
|
||||
GetReportCount(targetType model.ReportTargetType, targetID string) (int64, error)
|
||||
// HasUserReported 检查用户是否已举报过该内容
|
||||
@@ -87,7 +87,7 @@ func (r *reportRepository) FindByIDWithContext(ctx context.Context, id string) (
|
||||
}
|
||||
|
||||
// List 查询举报列表
|
||||
func (r *reportRepository) List(query dto.AdminReportListQuery) ([]*model.Report, int64, error) {
|
||||
func (r *reportRepository) List(query query.AdminReportListQuery) ([]*model.Report, int64, error) {
|
||||
var reports []*model.Report
|
||||
var total int64
|
||||
|
||||
|
||||
Reference in New Issue
Block a user