Skip to content

Commit

Permalink
chore(user/avatar-upload-complete): migrate ops & refs
Browse files Browse the repository at this point in the history
  • Loading branch information
ABCxFF committed Dec 21, 2024
1 parent 53fc6b2 commit 4c41e8e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 9 deletions.
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/api/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ token-get.workspace = true
token-revoke.workspace = true
upload-prepare.workspace = true
user.workspace = true
user-avatar-upload-complete.workspace = true
user-identity-get.workspace = true
rivet-config.workspace = true
rivet-env.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions packages/api/identity/src/route/identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ pub async fn complete_avatar_upload(
) -> GlobalResult<serde_json::Value> {
let user_ent = ctx.auth().user(ctx.op_ctx()).await?;

op!([ctx] user_avatar_upload_complete {
user_id: Some(user_ent.user_id.into()),
upload_id: Some(upload_id.into()),
(*ctx).op(::user::ops::avatar_upload_complete::Input {
user_id: user_ent.user_id,
upload_id: upload_id,
})
.await?;

Expand Down
2 changes: 1 addition & 1 deletion packages/services/user/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rivet-operation.workspace = true
token-create.workspace = true
upload-file-list.workspace = true
upload-get.workspace = true
user-get.workspace = true
upload-complete.workspace = true
user-identity-get.workspace = true

[dependencies.sqlx]
Expand Down
63 changes: 63 additions & 0 deletions packages/services/user/src/ops/avatar_upload_complete.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use chirp_workflow::prelude::*;
use rivet_operation::prelude::proto;
use proto::backend::{pkg::*};
use serde_json::json;

#[derive(Debug)]
pub struct Input {
pub user_id: Uuid,
pub upload_id: Uuid,
}

#[derive(Debug)]
pub struct Output {}


#[operation]
pub async fn avatar_upload_complete(
ctx: &OperationCtx,
input: &Input
) -> GlobalResult<Output> {
let user_id = input.user_id;

op!([ctx] upload_complete {
upload_id: Some(input.upload_id.into()),
bucket: Some("bucket-user-avatar".into()),
})
.await?;

// Set avatar id
sql_execute!(
[ctx]
"
UPDATE db_user.users set profile_id = $2
WHERE user_id = $1
",
user_id,
input.upload_id,
)
.await?;

ctx.cache().purge("user", [user_id]).await?;

msg!([ctx] user::msg::update(user_id) {
user_id: Some(user_id.into()),
})
.await?;

msg!([ctx] analytics::msg::event_create() {
events: vec![
analytics::msg::event_create::Event {
event_id: Some(Uuid::new_v4().into()),
name: "user.avatar_set".into(),
properties_json: Some(serde_json::to_string(&json!({
"user_id": user_id,
}))?),
..Default::default()
}
],
})
.await?;

Ok(Output {})
}
1 change: 1 addition & 0 deletions packages/services/user/src/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod avatar_upload_complete;
pub mod get;
pub mod pending_delete_toggle;
pub mod profile_validate;
Expand Down
1 change: 0 additions & 1 deletion packages/services/user/worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ team-get.workspace = true
team-member-list.workspace = true
upload-list-for-user.workspace = true
user.workspace = true
user-get.workspace = true
user-identity-delete.workspace = true
rivet-config.workspace = true

Expand Down

0 comments on commit 4c41e8e

Please sign in to comment.