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.

admin.go 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. // CreateStaff
  25. // @Tags user
  26. // @Summary CreateStaff
  27. // @Description Create a new staff
  28. // @Produce application/json
  29. // @Security ApiKeyAuth
  30. // @Param data body requestparams.RegisterStaffParams true "RegisterStaffParams"
  31. // @Success 200 {object} response.Response{msg=string} "Success"
  32. // @Router /api/v1/admin/staff/create [post].
  33. func CreateStaff(c *gin.Context) {
  34. uuid, err := utils.GetCommunityUUID(c)
  35. if err != nil {
  36. response.FailWithCode(common.ERROR, c)
  37. return
  38. }
  39. var params requestparams.RegisterStaffParams
  40. err = c.ShouldBindJSON(&params)
  41. if err != nil {
  42. response.FailWithCode(common.INVALID_PARAMS, c)
  43. return
  44. }
  45. svc := service.NewUserService(c)
  46. _, _, err = svc.CreateStaff(uuid, &params)
  47. if err != nil {
  48. response.FailWithCode(common.ERROR, c)
  49. return
  50. }
  51. response.Success(c)
  52. }
  53. // DeleteStaff
  54. // @Tags user
  55. // @Summary DeleteStaff
  56. // @Description Delete a new staff
  57. // @Produce application/json
  58. // @Param data body requestparams.DeleteUserParams true "DeleteUserParams"
  59. // @Success 200 {object} response.Response{msg=string} "Success"
  60. // @Router /api/v1/admin/staff/delete [post].
  61. func DeleteStaff(c *gin.Context) {
  62. var params requestparams.DeleteUserParams
  63. err := c.ShouldBindJSON(&params)
  64. if err != nil {
  65. response.FailWithCode(common.INVALID_PARAMS, c)
  66. return
  67. }
  68. svc := service.NewUserService(c)
  69. err = svc.DeleteStaff(params.UUID)
  70. if err != nil {
  71. log.Debug("DeleteStaff error", err)
  72. response.FailWithCode(common.ERROR, c)
  73. return
  74. }
  75. response.Success(c)
  76. }
  77. // UpdateStaff
  78. // @Tags user
  79. // @Summary UpdateStaff
  80. // @Description Update staff info
  81. // @Produce application/json
  82. // @Param data body requestparams.UpdateUserInfoParams true "UpdateUserInfoParams"
  83. // @Success 200 {object} response.Response{msg=string} "Success"
  84. // @Router /api/v1/admin/staff/update [post].
  85. func UpdateStaff(c *gin.Context) {
  86. var params requestparams.UpdateUserInfoParams
  87. err := c.ShouldBindJSON(&params)
  88. if err != nil || params.UUID == nil {
  89. response.FailWithCode(common.INVALID_PARAMS, c)
  90. return
  91. }
  92. svc := service.NewUserService(c)
  93. _, err = svc.UpdateUserInfo(*params.UUID, &params)
  94. if err != nil {
  95. log.Debug("UpdateStaff error", err)
  96. response.FailWithCode(common.ERROR, c)
  97. return
  98. }
  99. response.Success(c)
  100. }