feat(material): add material handling and routing functionality
Some checks failed
Build Backend / build (push) Failing after 12m1s
Build Backend / build-docker (push) Has been skipped

- Introduced MaterialHandler for managing learning materials and subjects.
- Updated router to include routes for public and admin material management.
- Enhanced database initialization with material subject and file models.
- Implemented seeding logic for material subjects and files.
- Updated wire generation to include MaterialHandler and related services.
This commit is contained in:
lafay
2026-03-25 20:44:12 +08:00
parent 28a45caad3
commit 0ef8e5a7e1
10 changed files with 1122 additions and 22 deletions

View File

@@ -33,6 +33,7 @@ type Router struct {
adminDashboardHandler *handler.AdminDashboardHandler
adminLogHandler *handler.AdminLogHandler
qrcodeHandler *handler.QRCodeHandler
materialHandler *handler.MaterialHandler
logService *service.LogService
jwtService *service.JWTService
casbinService service.CasbinService
@@ -62,6 +63,7 @@ func New(
adminDashboardHandler *handler.AdminDashboardHandler,
adminLogHandler *handler.AdminLogHandler,
qrcodeHandler *handler.QRCodeHandler,
materialHandler *handler.MaterialHandler,
logService *service.LogService,
activityService service.UserActivityService,
casbinService service.CasbinService,
@@ -94,6 +96,7 @@ func New(
adminDashboardHandler: adminDashboardHandler,
adminLogHandler: adminLogHandler,
qrcodeHandler: qrcodeHandler,
materialHandler: materialHandler,
logService: logService,
jwtService: jwtService,
casbinService: casbinService,
@@ -262,6 +265,21 @@ func (r *Router) setupRoutes() {
}
}
// 学习资料路由(公开)
if r.materialHandler != nil {
materials := v1.Group("/materials")
{
// 学科相关
materials.GET("/subjects", r.materialHandler.ListSubjects)
materials.GET("/subjects/:id", r.materialHandler.GetSubject)
// 资料相关
materials.GET("", r.materialHandler.ListMaterials)
materials.GET("/search", r.materialHandler.SearchMaterials)
materials.GET("/:id", r.materialHandler.GetMaterial)
materials.GET("/:id/download", r.materialHandler.DownloadMaterial)
}
}
// 投票选项路由
voteOptions := v1.Group("/vote-options")
voteOptions.Use(authMiddleware)
@@ -508,6 +526,21 @@ func (r *Router) setupRoutes() {
logs.GET("/export", r.adminLogHandler.ExportLogs)
}
}
// 学习资料管理
if r.materialHandler != nil {
// 学科管理
admin.GET("/materials/subjects", r.materialHandler.AdminListSubjects)
admin.POST("/materials/subjects", r.materialHandler.AdminCreateSubject)
admin.PUT("/materials/subjects/:id", r.materialHandler.AdminUpdateSubject)
admin.DELETE("/materials/subjects/:id", r.materialHandler.AdminDeleteSubject)
// 资料管理
admin.GET("/materials", r.materialHandler.AdminListMaterials)
admin.GET("/materials/:id", r.materialHandler.AdminGetMaterial)
admin.POST("/materials", r.materialHandler.AdminCreateMaterial)
admin.PUT("/materials/:id", r.materialHandler.AdminUpdateMaterial)
admin.DELETE("/materials/:id", r.materialHandler.AdminDeleteMaterial)
}
}
}
}