Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ homepage = "https://waveflow.app"
# build is reproducible — bump the rev in tree when picking up a new
# core release. `default-features = false` because core's
# default-feature set is empty; we only want the `postgres` feature.
waveflow-core = { git = "https://github.com/InstaZDLL/WaveFlow", rev = "24ffa58ac2e2580a02e9018bc743c4fcdfdd892b", default-features = false, features = ["postgres"] }
waveflow-core = { git = "https://github.com/InstaZDLL/WaveFlow", rev = "bfb899b161a5a22c8ad4b8c92001b3fbdeb86a1a", default-features = false, features = ["postgres"] }

# Database. `runtime-tokio` matches our `#[tokio::main]` runtime;
# `postgres` is the driver; `macros` enables `query_as!`; `migrate`
Expand Down
26 changes: 6 additions & 20 deletions src/api/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,28 +250,14 @@ async fn update_profile(
Path(id): Path<i64>,
Json(req): Json<UpdateProfileRequest>,
) -> impl IntoResponse {
// `rename_for_user` now hands back the updated row via
// `UPDATE … RETURNING …` in one round-trip — no separate
// read-back, so a concurrent DELETE can no longer flip a
// successful rename into a misleading 404.
let repo = PostgresProfileRepository::new(state.db.clone());
match repo.rename_for_user(id, &req.name, user_id).await {
Ok(true) => match repo.get_for_user(id, user_id).await {
Ok(Some(profile)) => {
(StatusCode::OK, Json(ProfileResponse::from(profile))).into_response()
}
Ok(None) => {
// Race: profile deleted between rename and read.
// Surface 404 — the rename committed but the row is
// gone, so reporting success would lie.
(StatusCode::NOT_FOUND, "profile not found").into_response()
}
Err(err) => {
tracing::error!(error = %err, id, user_id, "read-after-rename failed");
(
StatusCode::INTERNAL_SERVER_ERROR,
"read-after-rename failed",
)
.into_response()
}
},
Ok(false) => (StatusCode::NOT_FOUND, "profile not found").into_response(),
Ok(Some(profile)) => (StatusCode::OK, Json(ProfileResponse::from(profile))).into_response(),
Ok(None) => (StatusCode::NOT_FOUND, "profile not found").into_response(),
Err(err) => {
tracing::error!(error = %err, id, user_id, "rename profile failed");
(StatusCode::INTERNAL_SERVER_ERROR, "rename failed").into_response()
Expand Down
Loading