Feat: Allow Deleting Account via JSON API
This commit is contained in:
parent
5b3a544bbb
commit
ce0c5032ba
3 changed files with 26 additions and 1 deletions
23
src/json_api/users/delete.rs
Normal file
23
src/json_api/users/delete.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use crate::Pool;
|
||||
use crate::account::account::{Auth, User};
|
||||
use rocket::http::Status;
|
||||
use rocket::{State, get};
|
||||
|
||||
#[get("/api/v2/users/@me/delete")]
|
||||
pub async fn delete_account(pool: &State<Pool>, auth: Auth<true>) -> Result<(), Status> {
|
||||
let pool = pool.inner();
|
||||
let user: User = auth.into();
|
||||
|
||||
let result = sqlx::query!(
|
||||
"DELETE FROM users WHERE username = $1",
|
||||
user.username
|
||||
).execute(pool)
|
||||
.await
|
||||
.map_err(|_| Status::InternalServerError)?;
|
||||
|
||||
if result.rows_affected() == 0 { // Account doesn't exist
|
||||
Err(Status::NotFound)
|
||||
} else { // Account existed and was deleted
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue