delete_admin_user.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package admin_user
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "net/http"
  5. "sghgogs.com/micro/auth-client/response"
  6. "sghgogs.com/micro/auth-client/utils"
  7. pb "sghgogs.com/micro/auth-service/proto"
  8. "sghgogs.com/micro/common"
  9. "strconv"
  10. )
  11. // DeleteAdminUser
  12. // @summary 删除
  13. // @Description 删除管理员
  14. // @Tags User 用户管理
  15. // @Accept json
  16. // @Produce json
  17. // @Param Authorization header string true "Bearer 用户令牌"
  18. // @Param id path int true "用户ID"
  19. // @Success 200 {object} response.ApiResponse "成功"
  20. // @Failure 400 {object} response.ApiResponse "请求错误"
  21. // @Failure 500 {object} response.ApiResponse "内部错误"
  22. // @Router /v1/api/admin/user/{userID} [delete]
  23. func (svc *ApiAdminUser) DeleteAdminUser(c *gin.Context) {
  24. UserId, err := strconv.ParseInt(c.Param("userID"), 10, 64)
  25. if err != nil || UserId <= 0 {
  26. c.JSON(http.StatusBadRequest, gin.H{"error": common.ErrorMessage[common.InvalidUserID]})
  27. return
  28. }
  29. ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "AdminUserService.DeleteAdminUser")
  30. _, err = svc.Service.DeleteAdminUser(ctx, &pb.DeleteAdminUserRequest{
  31. UserId: UserId,
  32. })
  33. if err != nil {
  34. code, mgs := response.MicroErrorRequest(err)
  35. c.JSON(code, response.ErrorResponse(code, mgs))
  36. return
  37. }
  38. c.JSON(http.StatusOK, response.SuccessResponse(nil))
  39. }