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.

community.go 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // Copyright © 2023 OpenIM open source community. 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 api
  15. import (
  16. "github.com/gin-gonic/gin"
  17. "github.com/OpenIMSDK/OpenKF/server/internal/common"
  18. "github.com/OpenIMSDK/OpenKF/server/internal/common/response"
  19. requestparams "github.com/OpenIMSDK/OpenKF/server/internal/params/request"
  20. "github.com/OpenIMSDK/OpenKF/server/internal/service"
  21. "github.com/OpenIMSDK/OpenKF/server/internal/utils"
  22. "github.com/OpenIMSDK/OpenKF/server/pkg/log"
  23. )
  24. // CreateCommunity
  25. // @Tags community
  26. // @Summary CreateCommunity
  27. // @Description Create a new community
  28. // @Produce application/json
  29. // @Param data body requestparams.CommunityParams true "Community"
  30. // @Success 200 {object} response.Response{msg=string} "Success"
  31. // @Router /api/v1/community/create [post].
  32. func CreateCommunity(c *gin.Context) {
  33. var params requestparams.CommunityParams
  34. err := c.ShouldBindJSON(&params)
  35. if err != nil {
  36. response.FailWithCode(common.INVALID_PARAMS, c)
  37. return
  38. }
  39. svc := service.NewCommunityService(c)
  40. _, _, err = svc.Create(&params)
  41. if err != nil {
  42. log.Debug("CreateCommunity error", err)
  43. response.FailWithCode(common.ERROR, c)
  44. return
  45. }
  46. response.Success(c)
  47. }
  48. // GetCommunityInfo
  49. // @Tags community
  50. // @Summary GetCommunityInfo
  51. // @Description get community info
  52. // @Produce application/json
  53. // @Param data body requestparams.GetCommunityInfoParams true "GetCommunityInfoParams"
  54. // @Success 200 {object} response.Response{msg=string} "Success"
  55. // @Router /api/v1/community/info [post].
  56. func GetCommunityInfo(c *gin.Context) {
  57. param := requestparams.GetCommunityInfoParams{}
  58. err := c.ShouldBindJSON(&param)
  59. if err != nil {
  60. response.FailWithCode(common.INVALID_PARAMS, c)
  61. return
  62. }
  63. svc := service.NewCommunityService(c)
  64. resp, err := svc.GetCommunityInfoByUUID(param.UUID)
  65. if err != nil {
  66. response.FailWithCode(common.KF_RECORD_NOT_FOUND, c)
  67. return
  68. }
  69. response.SuccessWithData(resp, c)
  70. }
  71. // GetMyCommunityInfo
  72. // @Tags community
  73. // @Summary GetMyCommunityInfo
  74. // @Description get my community info
  75. // @Produce application/json
  76. // @Security ApiKeyAuth
  77. // @Success 200 {object} response.Response{msg=string} "Success"
  78. // @Router /api/v1/community/me [get].
  79. func GetMyCommunityInfo(c *gin.Context) {
  80. uuid, err := utils.GetCommunityUUID(c)
  81. if err != nil {
  82. response.FailWithCode(common.UNAUTHORIZED, c)
  83. return
  84. }
  85. svc := service.NewCommunityService(c)
  86. resp, err := svc.GetCommunityInfoByUUID(uuid)
  87. if err != nil {
  88. response.FailWithCode(common.KF_RECORD_NOT_FOUND, c)
  89. return
  90. }
  91. response.SuccessWithData(resp, c)
  92. }
  93. // GetMyCommunityInfo
  94. // @Tags community
  95. // @Summary GetMyCommunityInfo
  96. // @Description get my community info
  97. // @Produce application/json
  98. // @Security ApiKeyAuth
  99. // @Success 200 {object} response.Response{msg=string} "Success"
  100. // @Router /api/v1/community/update [post].
  101. func UpdateCommunity(c *gin.Context) {
  102. uuid, err := utils.GetCommunityUUID(c)
  103. if err != nil {
  104. response.FailWithCode(common.UNAUTHORIZED, c)
  105. return
  106. }
  107. var params requestparams.UpdateCommunityInfoParams
  108. err = c.ShouldBindJSON(&params)
  109. if err != nil {
  110. response.FailWithCode(common.INVALID_PARAMS, c)
  111. return
  112. }
  113. svc := service.NewCommunityService(c)
  114. info, err := svc.UpdateCommunity(uuid, &params)
  115. if err != nil {
  116. response.FailWithCode(common.ERROR, c)
  117. return
  118. }
  119. response.SuccessWithData(info, c)
  120. }