初始化项目,复制原投票系统后台代码
This commit is contained in:
@@ -0,0 +1,229 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"vote-admin-video-api/api/controller"
|
||||
"vote-admin-video-api/api/exception"
|
||||
"vote-admin-video-api/api/middlewares"
|
||||
"vote-admin-video-api/config"
|
||||
"vote-admin-video-api/consts"
|
||||
)
|
||||
|
||||
// Init 初始化路由
|
||||
func Init() *gin.Engine {
|
||||
r := gin.New()
|
||||
|
||||
// 环境设置
|
||||
if config.C.Env == "prod" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
// 获取请求参数中间件-json格式下会导致接口获取不到请求数据
|
||||
r.Use(middlewares.RequestParamsMiddleware())
|
||||
|
||||
// 日志中间件
|
||||
r.Use(middlewares.Logrus())
|
||||
|
||||
// 异常
|
||||
r.Use(gin.Recovery())
|
||||
|
||||
// 404处理
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
path := c.Request.URL.Path
|
||||
method := c.Request.Method
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"msg": fmt.Sprintf("%s %s not found", method, path),
|
||||
"code": consts.ClientHttpNotFound,
|
||||
"data": "",
|
||||
})
|
||||
})
|
||||
|
||||
// 异常处理
|
||||
r.Use(exception.Recover())
|
||||
|
||||
// 跨域处理
|
||||
r.Use(middlewares.Cors())
|
||||
|
||||
// 加载基础路由
|
||||
api := controller.Api{}
|
||||
|
||||
// 公开路由-不验证权限
|
||||
publicRouter(r, api)
|
||||
|
||||
// 验证jwt
|
||||
r.Use(middlewares.Jwt())
|
||||
|
||||
// 验证权限
|
||||
r.Use(middlewares.Auth())
|
||||
|
||||
// 私有路由-验证权限
|
||||
privateRouter(r, api)
|
||||
|
||||
// 公共路由-验证权限
|
||||
adminRouter(r, api)
|
||||
|
||||
// 基础数据-验证权限
|
||||
basicRouter(r, api)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// publicRouter 公开路由-不验证权限
|
||||
func publicRouter(r *gin.Engine, api controller.Api) {
|
||||
adminGroup := r.Group("/admin")
|
||||
|
||||
// 登录
|
||||
adminGroup.POST("/login", api.Public.Login)
|
||||
|
||||
// 验证码
|
||||
adminGroup.GET("/captcha", api.Public.GetCaptcha)
|
||||
|
||||
// 配置
|
||||
systemGroup := adminGroup.Group("/system")
|
||||
{
|
||||
// 编辑器配置
|
||||
editorGroup := systemGroup.Group("/editor")
|
||||
{
|
||||
// 编辑器-获取配置
|
||||
editorGroup.GET("", api.Editor.GetEditorConfig)
|
||||
|
||||
// 编辑器-上传
|
||||
editorGroup.POST("", api.Editor.EditorUpload)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// adminRouter 公共路由-验证权限
|
||||
func adminRouter(r *gin.Engine, api controller.Api) {
|
||||
adminGroup := r.Group("/admin")
|
||||
|
||||
// 首页
|
||||
indexGroup := adminGroup.Group("/index")
|
||||
{
|
||||
// 首页
|
||||
indexGroup.GET("", api.Public.GetIndex)
|
||||
|
||||
// 首页动态统计数据
|
||||
indexGroup.GET("/data", api.Public.GetIndexData)
|
||||
}
|
||||
}
|
||||
|
||||
// basicRouter 基础数据-验证权限
|
||||
func basicRouter(r *gin.Engine, api controller.Api) {
|
||||
|
||||
}
|
||||
|
||||
// privateRouter 私有路由-验证权限
|
||||
func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
adminGroup := r.Group("/admin")
|
||||
|
||||
// 图文
|
||||
articleGroup := adminGroup.Group("/article")
|
||||
{
|
||||
// 获取图文列表-分页
|
||||
articleGroup.POST("/page", api.Article.GetArticlePage)
|
||||
|
||||
// 获取图文详情
|
||||
articleGroup.GET("/:article_id", api.Article.GetArticle)
|
||||
|
||||
// 修改图文详情
|
||||
articleGroup.PUT("/:article_id", api.Article.PutArticle)
|
||||
|
||||
// 新增图文详情
|
||||
articleGroup.POST("", api.Article.AddArticle)
|
||||
|
||||
// 操作图文状态
|
||||
articleGroup.PUT("/status/:article_id", api.Article.PutArticleStatus)
|
||||
|
||||
// 投票记录列表-图文-分页
|
||||
articleGroup.GET("/vote/page", api.UserVoteDay.GetArticleVotePage)
|
||||
}
|
||||
|
||||
// 视频
|
||||
videoGroup := adminGroup.Group("/video")
|
||||
{
|
||||
// 获取视频列表-分页
|
||||
videoGroup.POST("/page", api.Video.GetVideoPage)
|
||||
|
||||
// 获取视频详情
|
||||
videoGroup.GET("/:video_id", api.Video.GetVideo)
|
||||
|
||||
// 修改视频详情
|
||||
videoGroup.PUT("/:video_id", api.Video.PutVideo)
|
||||
|
||||
// 新增视频详情
|
||||
videoGroup.POST("", api.Video.AddVideo)
|
||||
|
||||
// 操作视频状态
|
||||
videoGroup.PUT("/status/:video_id", api.Video.PutVideoStatus)
|
||||
|
||||
// 投票记录列表-视频-分页
|
||||
videoGroup.GET("/vote/page", api.UserVoteDay.GetVideoVotePage)
|
||||
}
|
||||
|
||||
// 基础数据
|
||||
basicGroup := adminGroup.Group("/basic")
|
||||
{
|
||||
// 协议
|
||||
agreementGroup := basicGroup.Group("/agreement")
|
||||
{
|
||||
// 获取协议列表-分页
|
||||
agreementGroup.GET("/page", api.BaseAgreement.GetBaseAgreementPage)
|
||||
|
||||
// 获取协议详情
|
||||
agreementGroup.GET("/:agreement_id", api.BaseAgreement.GetBaseAgreement)
|
||||
|
||||
// 修改协议
|
||||
agreementGroup.PUT("/:agreement_id", api.BaseAgreement.PutBaseAgreement)
|
||||
|
||||
// 新增协议
|
||||
agreementGroup.POST("", api.BaseAgreement.AddBaseAgreement)
|
||||
}
|
||||
|
||||
// 医院管理
|
||||
hospitalGroup := basicGroup.Group("/hospital")
|
||||
{
|
||||
// 获取医院列表-限制条数
|
||||
hospitalGroup.GET("/page", api.BaseHospital.GetHospitalList)
|
||||
}
|
||||
}
|
||||
|
||||
// 用户
|
||||
userGroup := adminGroup.Group("/user")
|
||||
{
|
||||
// 获取用户列表-分页
|
||||
userGroup.GET("/page", api.User.GetUserPage)
|
||||
|
||||
// 获取用户详情
|
||||
userGroup.GET("/:user_id", api.User.GetUser)
|
||||
|
||||
// 操作用户状态
|
||||
userGroup.PUT("/status/:user_id", api.User.PutUserStatus)
|
||||
|
||||
// 用户投票记录
|
||||
voteGroup := userGroup.Group("/vote")
|
||||
{
|
||||
// 用户投票记录列表-图文-分页
|
||||
voteGroup.GET("/article/page", api.UserVoteDay.GetUserArticleVotePage)
|
||||
|
||||
// 用户投票记录列表-视频-分页
|
||||
voteGroup.GET("/video/page", api.UserVoteDay.GetUserVideoVotePage)
|
||||
}
|
||||
}
|
||||
|
||||
// 配置
|
||||
systemGroup := adminGroup.Group("/system")
|
||||
{
|
||||
// 投票时间
|
||||
timeGroup := systemGroup.Group("/time")
|
||||
{
|
||||
// 获取投票时间详情
|
||||
timeGroup.GET("/:system_time_id", api.System.GetSystemTime)
|
||||
|
||||
// 修改投票时间
|
||||
timeGroup.PUT("/:system_time_id", api.System.PutSystemTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user