123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- package v1
- import (
- "fmt"
- "gin-vue-admin/global/response"
- "gin-vue-admin/model"
- "github.com/gin-gonic/gin"
- )
- type CreateApiParams struct {
- Path string `json:"path"`
- Description string `json:"description"`
- }
- type DeleteApiParams struct {
- ID uint `json:"id"`
- }
- func CreateApi(c *gin.Context) {
- var api model.SysApi
- _ = c.ShouldBindJSON(&api)
- err := api.CreateApi()
- if err != nil {
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("创建失败,%v", err), c)
- } else {
- response.Result(response.SUCCESS, gin.H{}, "创建成功", c)
- }
- }
- func DeleteApi(c *gin.Context) {
- var a model.SysApi
- _ = c.ShouldBindJSON(&a)
- err := a.DeleteApi()
- if err != nil {
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("删除失败,%v", err), c)
- } else {
- response.Result(response.SUCCESS, gin.H{}, "删除成功", c)
- }
- }
- type AuthAndPathIn struct {
- AuthorityId string `json:"authorityId"`
- ApiIds []uint `json:"apiIds"`
- }
- func GetApiList(c *gin.Context) {
-
- type searchParams struct {
- model.SysApi
- model.PageInfo
- }
- var sp searchParams
- _ = c.ShouldBindJSON(&sp)
- err, list, total := sp.SysApi.GetInfoList(sp.PageInfo)
- if err != nil {
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
- } else {
- response.Result(response.SUCCESS, gin.H{
- "list": list,
- "total": total,
- "page": sp.PageInfo.Page,
- "pageSize": sp.PageInfo.PageSize,
- }, "删除成功", c)
- }
- }
- func GetApiById(c *gin.Context) {
- var idInfo GetById
- _ = c.ShouldBindJSON(&idInfo)
- err, api := new(model.SysApi).GetApiById(idInfo.Id)
- if err != nil {
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
- } else {
- response.Result(response.SUCCESS, gin.H{
- "api": api,
- }, "获取数据成功", c)
- }
- }
- func UpdateApi(c *gin.Context) {
- var api model.SysApi
- _ = c.ShouldBindJSON(&api)
- err := api.UpdateApi()
- if err != nil {
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("修改数据失败,%v", err), c)
- } else {
- response.Result(response.SUCCESS, gin.H{}, "修改数据成功", c)
- }
- }
- func GetAllApis(c *gin.Context) {
- err, apis := new(model.SysApi).GetAllApis()
- if err != nil {
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
- } else {
- response.Result(response.SUCCESS, gin.H{
- "apis": apis,
- }, "获取数据成功", c)
- }
- }
|