Skip to content

Commit 1ce7c79

Browse files
cmyuiCopilot
andauthored
Add ban and unban event publishing to user management functions (#32)
* Add ban and unban event publishing to user management functions - Implemented `publish_ban_event` and `publish_unban_event` functions in the users repository. - Updated `ban_user`, `unban_user`, `restrict_user`, and `unrestrict_user` functions to publish events for leaderboard updates upon user ban and unban actions. * Move ban/unban event publishing to usecase layer (#33) * Initial plan * Move event publishing from commands to usecases Co-authored-by: cmyui <17343631+cmyui@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: cmyui <17343631+cmyui@users.noreply.github.com> * ddeath to dead code * Simplify error handling in user management usecases (#34) * Initial plan * Use ? syntax for both calls in ban/unban/restrict/unrestrict usecases Co-authored-by: cmyui <17343631+cmyui@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: cmyui <17343631+cmyui@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: cmyui <17343631+cmyui@users.noreply.github.com>
1 parent a8e34fe commit 1ce7c79

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/repositories/users.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,15 @@ pub async fn update_previous_overwrite<C: Context>(
248248
.await?;
249249
Ok(())
250250
}
251+
252+
pub async fn publish_ban_event<C: Context>(ctx: &C, user_id: i64) -> anyhow::Result<()> {
253+
let mut redis = ctx.redis().await?;
254+
let _: () = redis.publish("peppy:ban", user_id.to_string()).await?;
255+
Ok(())
256+
}
257+
258+
pub async fn publish_unban_event<C: Context>(ctx: &C, user_id: i64) -> anyhow::Result<()> {
259+
let mut redis = ctx.redis().await?;
260+
let _: () = redis.publish("peppy:unban", user_id.to_string()).await?;
261+
Ok(())
262+
}

src/usecases/users.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,27 @@ pub async fn change_username<C: Context>(
9292
}
9393

9494
pub async fn ban_user<C: Context>(ctx: &C, user_id: i64) -> ServiceResult<()> {
95-
match users::ban(ctx, user_id).await {
96-
Ok(_) => Ok(()),
97-
Err(e) => unexpected(e),
98-
}
95+
users::ban(ctx, user_id).await?;
96+
users::publish_ban_event(ctx, user_id).await?;
97+
Ok(())
9998
}
10099

101100
pub async fn unban_user<C: Context>(ctx: &C, user_id: i64) -> ServiceResult<()> {
102-
match users::unban(ctx, user_id).await {
103-
Ok(_) => Ok(()),
104-
Err(e) => unexpected(e),
105-
}
101+
users::unban(ctx, user_id).await?;
102+
users::publish_unban_event(ctx, user_id).await?;
103+
Ok(())
106104
}
107105

108106
pub async fn restrict_user<C: Context>(ctx: &C, user_id: i64) -> ServiceResult<()> {
109-
match users::restrict(ctx, user_id).await {
110-
Ok(_) => Ok(()),
111-
Err(e) => unexpected(e),
112-
}
107+
users::restrict(ctx, user_id).await?;
108+
users::publish_ban_event(ctx, user_id).await?;
109+
Ok(())
113110
}
114111

115112
pub async fn unrestrict_user<C: Context>(ctx: &C, user_id: i64) -> ServiceResult<()> {
116-
match users::unrestrict(ctx, user_id).await {
117-
Ok(_) => Ok(()),
118-
Err(e) => unexpected(e),
119-
}
113+
users::unrestrict(ctx, user_id).await?;
114+
users::publish_unban_event(ctx, user_id).await?;
115+
Ok(())
120116
}
121117

122118
pub async fn freeze_user<C: Context>(ctx: &C, user_id: i64, reason: &str) -> ServiceResult<()> {

0 commit comments

Comments
 (0)