Add delete user endpoint

This commit is contained in:
Nathan Sobo 2021-12-25 11:57:37 -07:00
parent 56930972fe
commit b949b30f24

View file

@ -9,6 +9,7 @@ pub fn add_routes(app: &mut tide::Server<Arc<AppState>>) {
app.at("/users").get(get_users);
app.at("/users").post(create_user);
app.at("/users/:id").put(update_user);
app.at("/users/:id").delete(delete_user);
app.at("/users/:github_login").get(get_user);
app.at("/users/:github_login/access_tokens")
.post(create_access_token);
@ -88,6 +89,20 @@ async fn update_user(mut request: Request) -> tide::Result {
Ok(tide::Response::builder(StatusCode::Ok).build())
}
async fn delete_user(request: Request) -> tide::Result {
request.require_token().await?;
let user_id = UserId(
request
.param("id")?
.parse::<i32>()
.map_err(|error| surf::Error::from_str(StatusCode::BadRequest, error.to_string()))?,
);
request.db().delete_user(user_id).await?;
Ok(tide::Response::builder(StatusCode::Ok).build())
}
async fn create_access_token(request: Request) -> tide::Result {
request.require_token().await?;