62 lines
2.9 KiB
Go
62 lines
2.9 KiB
Go
package api
|
||
|
||
import (
|
||
camp_handler "dd_fiber_api/internal/camp/handler"
|
||
|
||
"github.com/gofiber/fiber/v2"
|
||
)
|
||
|
||
// SetupCampRoutes Camp接口
|
||
// 统一使用 GET 和 POST 两种方法,不使用 RESTful 风格
|
||
func SetupCampRoutes(router fiber.Router, campCategoryHandler *camp_handler.CategoryHandler, campHandler *camp_handler.CampHandler, sectionHandler *camp_handler.SectionHandler, taskHandler *camp_handler.TaskHandler, progressHandler *camp_handler.ProgressHandler, userCampHandler *camp_handler.UserCampHandler) {
|
||
// 如果所有handler都为空,则不设置路由
|
||
if campCategoryHandler == nil && campHandler == nil && sectionHandler == nil && taskHandler == nil && progressHandler == nil && userCampHandler == nil {
|
||
return
|
||
}
|
||
|
||
camp := router.Group("/camp")
|
||
|
||
// ==================== 分类管理 ====================
|
||
if campCategoryHandler != nil {
|
||
camp.Get("/categories", campCategoryHandler.ListCategories).Name("列出分类")
|
||
}
|
||
|
||
// ==================== 打卡营管理 ====================
|
||
if campHandler != nil {
|
||
camp.Get("/camps", campHandler.ListCamps).Name("列出打卡营")
|
||
camp.Get("/camps/detail", campHandler.GetCamp).Name("获取打卡营详情")
|
||
camp.Post("/camp_detail_with_user_status", campHandler.GetCampDetailWithStatus).Name("获取打卡营详情及状态")
|
||
camp.Post("/can_unlock_section", campHandler.CanUnlockSection).Name("检查是否可开启小节")
|
||
camp.Post("/can_start_task", campHandler.CanStartTask).Name("检查任务是否可开始")
|
||
}
|
||
|
||
// ==================== 小节管理 ====================
|
||
if sectionHandler != nil {
|
||
camp.Get("/sections", sectionHandler.ListSections).Name("列出小节")
|
||
camp.Post("/purchase_section", sectionHandler.PurchaseSection).Name("购买小节")
|
||
}
|
||
|
||
// ==================== 用户进度管理 ====================
|
||
// 注意:必须在任务路由之前注册,避免路由冲突
|
||
if progressHandler != nil {
|
||
camp.Get("/progress/info", progressHandler.GetUserProgress).Name("获取用户进度")
|
||
camp.Post("/progress/update", progressHandler.UpdateUserProgress).Name("更新用户进度")
|
||
camp.Post("/progress/reset", progressHandler.ResetTaskProgress).Name("重置任务进度")
|
||
// 兼容旧接口路径
|
||
camp.Post("/reset_task_progress", progressHandler.ResetTaskProgress).Name("重置任务进度(兼容)")
|
||
}
|
||
|
||
// ==================== 任务管理 ====================
|
||
if taskHandler != nil {
|
||
camp.Get("/tasks/detail", taskHandler.GetTask).Name("获取任务详情")
|
||
camp.Get("/tasks/list", taskHandler.ListTasks).Name("列出任务")
|
||
}
|
||
|
||
// ==================== 用户打卡营管理 ====================
|
||
if userCampHandler != nil {
|
||
camp.Post("/user_camp/join", userCampHandler.JoinCamp).Name("加入打卡营")
|
||
camp.Post("/user_camp/reset_progress", userCampHandler.ResetCampProgress).Name("重置打卡营进度")
|
||
camp.Post("/check_user_camp_status", userCampHandler.CheckUserCampStatusPost).Name("检查用户打卡营状态")
|
||
}
|
||
}
|