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"
|
||||
"with_you/internal/pkg/utils"
|
||||
"with_you/internal/query"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -80,7 +80,7 @@ func (r *materialSubjectRepository) CountMaterials(subjectID string) (int64, err
|
||||
|
||||
// MaterialFileRepository 文件资料仓储接口
|
||||
type MaterialFileRepository interface {
|
||||
List(params dto.MaterialFileQueryParams) ([]*model.MaterialFile, int64, error)
|
||||
List(params query.MaterialFileQueryParams) ([]*model.MaterialFile, int64, error)
|
||||
GetByID(id string) (*model.MaterialFile, error)
|
||||
GetByIDWithSubject(id string) (*model.MaterialFile, error)
|
||||
Create(file *model.MaterialFile) error
|
||||
@@ -103,7 +103,7 @@ func NewMaterialFileRepository(db *gorm.DB) MaterialFileRepository {
|
||||
}
|
||||
|
||||
// List 获取资料列表(支持筛选和分页)
|
||||
func (r *materialFileRepository) List(params dto.MaterialFileQueryParams) ([]*model.MaterialFile, int64, error) {
|
||||
func (r *materialFileRepository) List(params query.MaterialFileQueryParams) ([]*model.MaterialFile, int64, error) {
|
||||
var files []*model.MaterialFile
|
||||
var total int64
|
||||
|
||||
@@ -260,4 +260,4 @@ func (r *materialFileRepository) GetLatestMaterials(limit int) ([]*model.Materia
|
||||
Limit(limit).
|
||||
Find(&files).Error
|
||||
return files, err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user