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

wordset.go 2.9 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2023 The casbin Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package controllers
  15. import (
  16. "encoding/json"
  17. "github.com/casbin/casibase/object"
  18. "github.com/casbin/casibase/util"
  19. )
  20. func (c *ApiController) GetGlobalWordsets() {
  21. wordsets, err := object.GetGlobalWordsets()
  22. if err != nil {
  23. c.ResponseError(err.Error())
  24. return
  25. }
  26. c.ResponseOk(wordsets)
  27. }
  28. func (c *ApiController) GetWordsets() {
  29. owner := c.Input().Get("owner")
  30. wordsets, err := object.GetWordsets(owner)
  31. if err != nil {
  32. c.ResponseError(err.Error())
  33. return
  34. }
  35. c.ResponseOk(wordsets)
  36. }
  37. func (c *ApiController) GetWordset() {
  38. id := c.Input().Get("id")
  39. wordset, err := object.GetWordset(id)
  40. if err != nil {
  41. c.ResponseError(err.Error())
  42. return
  43. }
  44. c.ResponseOk(wordset)
  45. }
  46. func (c *ApiController) GetWordsetGraph() {
  47. id := c.Input().Get("id")
  48. clusterNumber := util.ParseInt(c.Input().Get("clusterNumber"))
  49. distanceLimit := util.ParseInt(c.Input().Get("distanceLimit"))
  50. g, err := object.GetWordsetGraph(id, clusterNumber, distanceLimit)
  51. if err != nil {
  52. c.ResponseError(err.Error())
  53. return
  54. }
  55. c.ResponseOk(g)
  56. }
  57. func (c *ApiController) GetWordsetMatch() {
  58. id := c.Input().Get("id")
  59. wordset, err := object.GetWordsetMatch(id)
  60. if err != nil {
  61. c.ResponseError(err.Error())
  62. return
  63. }
  64. c.ResponseOk(wordset)
  65. }
  66. func (c *ApiController) UpdateWordset() {
  67. id := c.Input().Get("id")
  68. var wordset object.Wordset
  69. err := json.Unmarshal(c.Ctx.Input.RequestBody, &wordset)
  70. if err != nil {
  71. c.ResponseError(err.Error())
  72. return
  73. }
  74. success, err := object.UpdateWordset(id, &wordset)
  75. if err != nil {
  76. c.ResponseError(err.Error())
  77. return
  78. }
  79. c.ResponseOk(success)
  80. }
  81. func (c *ApiController) AddWordset() {
  82. var wordset object.Wordset
  83. err := json.Unmarshal(c.Ctx.Input.RequestBody, &wordset)
  84. if err != nil {
  85. c.ResponseError(err.Error())
  86. return
  87. }
  88. success, err := object.AddWordset(&wordset)
  89. if err != nil {
  90. c.ResponseError(err.Error())
  91. return
  92. }
  93. c.ResponseOk(success)
  94. }
  95. func (c *ApiController) DeleteWordset() {
  96. var wordset object.Wordset
  97. err := json.Unmarshal(c.Ctx.Input.RequestBody, &wordset)
  98. if err != nil {
  99. c.ResponseError(err.Error())
  100. return
  101. }
  102. success, err := object.DeleteWordset(&wordset)
  103. if err != nil {
  104. c.ResponseError(err.Error())
  105. return
  106. }
  107. c.ResponseOk(success)
  108. }