pixelqm
5 years ago
13 changed files with 664 additions and 58 deletions
-
56QMPlusServer/controller/api/api.go
-
60QMPlusServer/controller/api/authority.go
-
1QMPlusServer/controller/api/menu.go
-
189QMPlusServer/docs/docs.go
-
187QMPlusServer/docs/swagger.json
-
129QMPlusServer/docs/swagger.yaml
-
8QMPlusServer/init/initRouter/initRouter.go
-
2QMPlusServer/init/registTable/registTable.go
-
43QMPlusServer/model/dbModel/api.go
-
16QMPlusServer/model/dbModel/authority.go
-
1QMPlusServer/model/dbModel/menu.go
-
15QMPlusServer/router/api.go
-
15QMPlusServer/router/authority.go
@ -0,0 +1,56 @@ |
|||
package api |
|||
|
|||
import ( |
|||
"fmt" |
|||
"github.com/gin-gonic/gin" |
|||
"main/controller/servers" |
|||
"main/model/dbModel" |
|||
) |
|||
|
|||
type CreateApiParams struct { |
|||
AuthorityId uint `json:"-"` |
|||
Path string `json:"path"` |
|||
Description string `json:"description"` |
|||
} |
|||
|
|||
type DeleteApiParams struct { |
|||
AuthorityId uint `json:"-"` |
|||
} |
|||
|
|||
// @Tags Api
|
|||
// @Summary 为指定角色创建api
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body api.CreateApiParams true "创建api"
|
|||
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /api/createApi [post]
|
|||
func CreateApi(c *gin.Context) { |
|||
var api dbModel.Api |
|||
_ = c.BindJSON(&api) |
|||
err := api.CreateApi() |
|||
if err != nil { |
|||
servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{}) |
|||
} else { |
|||
servers.ReportFormat(c, true, "创建成功", gin.H{}) |
|||
} |
|||
} |
|||
|
|||
// @Tags Api
|
|||
// @Summary 删除指定角色api
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body api.DeleteApiParams true "删除api"
|
|||
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /api/deleteApi [post]
|
|||
func DeleteApi(c *gin.Context) { |
|||
var a dbModel.Api |
|||
_ = c.BindJSON(&a) |
|||
err := a.DeleteApi() |
|||
if err != nil { |
|||
servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{}) |
|||
} else { |
|||
servers.ReportFormat(c, true, "删除成功", gin.H{}) |
|||
} |
|||
} |
@ -0,0 +1,60 @@ |
|||
package api |
|||
|
|||
import ( |
|||
"fmt" |
|||
"github.com/gin-gonic/gin" |
|||
"main/controller/servers" |
|||
"main/model/dbModel" |
|||
) |
|||
|
|||
type CreateAuthorityPatams struct { |
|||
AuthorityId uint `json:"authorityId"` |
|||
AuthorityName string `json:"authorityName"` |
|||
} |
|||
|
|||
// @Tags authority
|
|||
// @Summary 创建角色
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body api.CreateAuthorityPatams true "创建角色"
|
|||
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /authority/createAuthority [post]
|
|||
func CreateAuthority(c *gin.Context) { |
|||
var auth dbModel.Authority |
|||
_ = c.BindJSON(&auth) |
|||
err, authBack := auth.CreateAuthority() |
|||
if err != nil { |
|||
servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{ |
|||
"authority": authBack, |
|||
}) |
|||
} else { |
|||
servers.ReportFormat(c, true, "创建成功", gin.H{ |
|||
"authority": authBack, |
|||
}) |
|||
} |
|||
} |
|||
|
|||
type DeleteAuthorityPatams struct { |
|||
AuthorityId uint `json:"authorityId"` |
|||
} |
|||
|
|||
// @Tags authority
|
|||
// @Summary 删除角色
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body api.DeleteAuthorityPatams true "删除角色"
|
|||
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /authority/deleteAuthority [post]
|
|||
func DeleteAuthority(c *gin.Context) { |
|||
var a dbModel.Authority |
|||
_ = c.BindJSON(&a) |
|||
//删除角色之前需要判断是否有用户正在使用此角色
|
|||
err := a.DeleteAuthority() |
|||
if err != nil { |
|||
servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{}) |
|||
} else { |
|||
servers.ReportFormat(c, true, "删除成功", gin.H{}) |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
package dbModel |
|||
|
|||
import ( |
|||
"github.com/jinzhu/gorm" |
|||
"main/controller/servers" |
|||
"main/init/qmsql" |
|||
"main/model/modelInterface" |
|||
) |
|||
|
|||
type Api struct { |
|||
gorm.Model `json:"-"` |
|||
AuthorityId uint `json:"-"` |
|||
Path string `json:"path"` |
|||
Description string `json:"description"` |
|||
} |
|||
|
|||
func (a *Api) CreateApi() (err error) { |
|||
err = qmsql.DEFAULTDB.Create(a).Error |
|||
return err |
|||
} |
|||
|
|||
func (a *Api) DeleteApi() (err error) { |
|||
err = qmsql.DEFAULTDB.Where("id = ?", a.AuthorityId).Delete(a).Error |
|||
return err |
|||
} |
|||
|
|||
func (a *Api) EditApi() (err error) { |
|||
err = qmsql.DEFAULTDB.Update(a).Error |
|||
return err |
|||
} |
|||
|
|||
// 分页获取数据 需要分页实现这个接口即可
|
|||
func (a *Api) GetInfoList(info modelInterface.PageInfo) (err error, list interface{}, total int) { |
|||
// 封装分页方法 调用即可 传入 当前的结构体和分页信息
|
|||
err, db, total := servers.PagingServer(a, info) |
|||
if err != nil { |
|||
return |
|||
} else { |
|||
var apiList []Api |
|||
err = db.Find(&apiList).Error |
|||
return err, apiList, total |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
package router |
|||
|
|||
import ( |
|||
"github.com/gin-gonic/gin" |
|||
"main/controller/api" |
|||
"main/middleware" |
|||
) |
|||
|
|||
func InitApiRouter(Router *gin.Engine) { |
|||
UserRouter := Router.Group("api").Use(middleware.JWTAuth()) |
|||
{ |
|||
UserRouter.POST("createApi", api.CreateApi) |
|||
UserRouter.POST("deleteApi", api.DeleteApi) |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
package router |
|||
|
|||
import ( |
|||
"github.com/gin-gonic/gin" |
|||
"main/controller/api" |
|||
"main/middleware" |
|||
) |
|||
|
|||
func InitAuthorityRouter(Router *gin.Engine) { |
|||
AuthorityRouter := Router.Group("authority").Use(middleware.JWTAuth()) |
|||
{ |
|||
AuthorityRouter.POST("createAuthority", api.CreateAuthority) |
|||
AuthorityRouter.POST("deleteAuthority", api.DeleteAuthority) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue