You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

  1. package api
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "main/controller/servers"
  6. "main/model/dbModel"
  7. )
  8. type CreateApiParams struct {
  9. AuthorityId uint `json:"-"`
  10. Path string `json:"path"`
  11. Description string `json:"description"`
  12. }
  13. type DeleteApiParams struct {
  14. AuthorityId uint `json:"-"`
  15. }
  16. // @Tags Api
  17. // @Summary 为指定角色创建api
  18. // @Security ApiKeyAuth
  19. // @accept application/json
  20. // @Produce application/json
  21. // @Param data body api.CreateApiParams true "创建api"
  22. // @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
  23. // @Router /api/createApi [post]
  24. func CreateApi(c *gin.Context) {
  25. var api dbModel.Api
  26. _ = c.BindJSON(&api)
  27. err := api.CreateApi()
  28. if err != nil {
  29. servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{})
  30. } else {
  31. servers.ReportFormat(c, true, "创建成功", gin.H{})
  32. }
  33. }
  34. // @Tags Api
  35. // @Summary 删除指定角色api
  36. // @Security ApiKeyAuth
  37. // @accept application/json
  38. // @Produce application/json
  39. // @Param data body api.DeleteApiParams true "删除api"
  40. // @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
  41. // @Router /api/deleteApi [post]
  42. func DeleteApi(c *gin.Context) {
  43. var a dbModel.Api
  44. _ = c.BindJSON(&a)
  45. err := a.DeleteApi()
  46. if err != nil {
  47. servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
  48. } else {
  49. servers.ReportFormat(c, true, "删除成功", gin.H{})
  50. }
  51. }