Make POST /contributors API idempotent

Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
Max Brunsfeld 2024-01-22 12:49:35 -08:00
parent 1981de4cae
commit 6c937c4a90

View File

@ -37,11 +37,17 @@ impl Database {
&*tx,
)
.await?;
contributor::ActiveModel {
contributor::Entity::insert(contributor::ActiveModel {
user_id: ActiveValue::Set(user.id),
signed_at: ActiveValue::NotSet,
}
.insert(&*tx)
})
.on_conflict(
OnConflict::column(contributor::Column::UserId)
.do_nothing()
.to_owned(),
)
.exec_without_returning(&*tx)
.await?;
Ok(())
})