refactor: update repository interfaces and improve dependency injection
- Refactored repository structures to use interfaces instead of concrete types, enhancing flexibility and testability. - Updated various repository methods to accept interfaces, allowing for better dependency management. - Modified wire generation to accommodate new repository interfaces, ensuring proper service injection throughout the application. - Enhanced handler methods to utilize DTOs for filtering and data handling, improving code clarity and maintainability.
This commit is contained in:
@@ -2,6 +2,8 @@ package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"carrot_bbs/internal/dto"
|
||||
"carrot_bbs/internal/model"
|
||||
"carrot_bbs/internal/repository"
|
||||
)
|
||||
@@ -21,7 +23,7 @@ type MaterialService interface {
|
||||
DeleteSubject(id string) error
|
||||
|
||||
// 资料相关
|
||||
ListMaterials(params repository.MaterialFileQueryParams) ([]*model.MaterialFile, int64, error)
|
||||
ListMaterials(params dto.MaterialFileQueryParams) ([]*model.MaterialFile, int64, error)
|
||||
GetMaterialByID(id string) (*model.MaterialFile, error)
|
||||
GetMaterialByIDWithSubject(id string) (*model.MaterialFile, error)
|
||||
GetMaterialsBySubject(subjectID string, page, pageSize int) ([]*model.MaterialFile, int64, error)
|
||||
@@ -36,14 +38,14 @@ type MaterialService interface {
|
||||
|
||||
// materialServiceImpl 学习资料服务实现
|
||||
type materialServiceImpl struct {
|
||||
subjectRepo *repository.MaterialSubjectRepository
|
||||
fileRepo *repository.MaterialFileRepository
|
||||
subjectRepo repository.MaterialSubjectRepository
|
||||
fileRepo repository.MaterialFileRepository
|
||||
}
|
||||
|
||||
// NewMaterialService 创建学习资料服务
|
||||
func NewMaterialService(
|
||||
subjectRepo *repository.MaterialSubjectRepository,
|
||||
fileRepo *repository.MaterialFileRepository,
|
||||
subjectRepo repository.MaterialSubjectRepository,
|
||||
fileRepo repository.MaterialFileRepository,
|
||||
) MaterialService {
|
||||
return &materialServiceImpl{
|
||||
subjectRepo: subjectRepo,
|
||||
@@ -127,7 +129,7 @@ func (s *materialServiceImpl) DeleteSubject(id string) error {
|
||||
// 资料相关方法
|
||||
// =====================================================
|
||||
|
||||
func (s *materialServiceImpl) ListMaterials(params repository.MaterialFileQueryParams) ([]*model.MaterialFile, int64, error) {
|
||||
func (s *materialServiceImpl) ListMaterials(params dto.MaterialFileQueryParams) ([]*model.MaterialFile, int64, error) {
|
||||
return s.fileRepo.List(params)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user