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.

60 lines
1.6 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 CreateAuthorityPatams struct {
  9. AuthorityId uint `json:"authorityId"`
  10. AuthorityName string `json:"authorityName"`
  11. }
  12. // @Tags authority
  13. // @Summary 创建角色
  14. // @Security ApiKeyAuth
  15. // @accept application/json
  16. // @Produce application/json
  17. // @Param data body api.CreateAuthorityPatams true "创建角色"
  18. // @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
  19. // @Router /authority/createAuthority [post]
  20. func CreateAuthority(c *gin.Context) {
  21. var auth dbModel.Authority
  22. _ = c.BindJSON(&auth)
  23. err, authBack := auth.CreateAuthority()
  24. if err != nil {
  25. servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{
  26. "authority": authBack,
  27. })
  28. } else {
  29. servers.ReportFormat(c, true, "创建成功", gin.H{
  30. "authority": authBack,
  31. })
  32. }
  33. }
  34. type DeleteAuthorityPatams struct {
  35. AuthorityId uint `json:"authorityId"`
  36. }
  37. // @Tags authority
  38. // @Summary 删除角色
  39. // @Security ApiKeyAuth
  40. // @accept application/json
  41. // @Produce application/json
  42. // @Param data body api.DeleteAuthorityPatams true "删除角色"
  43. // @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
  44. // @Router /authority/deleteAuthority [post]
  45. func DeleteAuthority(c *gin.Context) {
  46. var a dbModel.Authority
  47. _ = c.BindJSON(&a)
  48. //删除角色之前需要判断是否有用户正在使用此角色
  49. err := a.DeleteAuthority()
  50. if err != nil {
  51. servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
  52. } else {
  53. servers.ReportFormat(c, true, "删除成功", gin.H{})
  54. }
  55. }