f
This commit is contained in:
@@ -445,6 +445,12 @@ func (h *UserHandler) ListUsers(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if isBlacklisted := c.Query("is_blacklisted"); isBlacklisted != "" {
|
||||
if blacklisted, err := strconv.ParseBool(isBlacklisted); err == nil {
|
||||
query.IsBlacklisted = &blacklisted
|
||||
}
|
||||
}
|
||||
|
||||
// 调用应用服务
|
||||
resp, err := h.appService.ListUsers(c.Request.Context(), query)
|
||||
if err != nil {
|
||||
@@ -520,6 +526,71 @@ func (h *UserHandler) GetUserStats(c *gin.Context) {
|
||||
h.response.Success(c, resp, "获取用户统计信息成功")
|
||||
}
|
||||
|
||||
// BlacklistUser 管理员将用户列入黑名单
|
||||
func (h *UserHandler) BlacklistUser(c *gin.Context) {
|
||||
operatorID := h.getCurrentUserID(c)
|
||||
if operatorID == "" {
|
||||
h.response.Unauthorized(c, "用户未登录")
|
||||
return
|
||||
}
|
||||
|
||||
targetUserID := c.Param("user_id")
|
||||
if targetUserID == "" {
|
||||
h.response.BadRequest(c, "用户ID不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
var body struct {
|
||||
Reason string `json:"reason" binding:"required"`
|
||||
Source string `json:"source"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
h.response.BadRequest(c, "请填写纳入原因")
|
||||
return
|
||||
}
|
||||
|
||||
cmd := &commands.BlacklistUserCommand{
|
||||
UserID: targetUserID,
|
||||
OperatorUserID: operatorID,
|
||||
Reason: body.Reason,
|
||||
Source: body.Source,
|
||||
}
|
||||
if err := h.appService.BlacklistUser(c.Request.Context(), cmd); err != nil {
|
||||
h.logger.Error("列入黑名单失败", zap.Error(err), zap.String("user_id", targetUserID))
|
||||
h.response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
h.response.Success(c, nil, "已列入黑名单")
|
||||
}
|
||||
|
||||
// UnblacklistUser 管理员将用户移出黑名单
|
||||
func (h *UserHandler) UnblacklistUser(c *gin.Context) {
|
||||
operatorID := h.getCurrentUserID(c)
|
||||
if operatorID == "" {
|
||||
h.response.Unauthorized(c, "用户未登录")
|
||||
return
|
||||
}
|
||||
|
||||
targetUserID := c.Param("user_id")
|
||||
if targetUserID == "" {
|
||||
h.response.BadRequest(c, "用户ID不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
cmd := &commands.UnblacklistUserCommand{
|
||||
UserID: targetUserID,
|
||||
OperatorUserID: operatorID,
|
||||
}
|
||||
if err := h.appService.UnblacklistUser(c.Request.Context(), cmd); err != nil {
|
||||
h.logger.Error("移出黑名单失败", zap.Error(err), zap.String("user_id", targetUserID))
|
||||
h.response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
h.response.Success(c, nil, "已移出黑名单")
|
||||
}
|
||||
|
||||
// getCurrentUserID 获取当前用户ID
|
||||
func (h *UserHandler) getCurrentUserID(c *gin.Context) string {
|
||||
if userID, exists := c.Get("user_id"); exists {
|
||||
|
||||
Reference in New Issue
Block a user