Enhancement: Routes with no body should return 204 No Content.

This commit is contained in:
heikkari
2021-08-16 15:34:44 +03:00
parent 48d2fbe5ae
commit 721ca3a4f5
30 changed files with 124 additions and 116 deletions

View File

@@ -1,11 +1,11 @@
use crate::database::*;
use crate::notifications::events::ClientboundNotification;
use crate::util::result::{Error, Result};
use crate::util::result::{Error, EmptyResponse, Result};
use mongodb::bson::doc;
#[delete("/<target>")]
pub async fn delete_bot(user: User, target: Ref) -> Result<()> {
pub async fn delete_bot(user: User, target: Ref) -> Result<EmptyResponse> {
let bot = target.fetch_bot().await?;
if bot.owner != user.id {
return Err(Error::MissingPermission);
@@ -58,6 +58,6 @@ pub async fn delete_bot(user: User, target: Ref) -> Result<()> {
with: "bot",
operation: "delete_one"
})?;
Ok(())
Ok(EmptyResponse {})
}

View File

@@ -1,5 +1,5 @@
use crate::notifications::events::ClientboundNotification;
use crate::util::result::{Error, Result};
use crate::util::result::{Error, Result, EmptyResponse};
use crate::{database::*, notifications::events::RemoveBotField};
use mongodb::bson::doc;
@@ -25,7 +25,7 @@ pub struct Data {
}
#[patch("/<target>", data = "<data>")]
pub async fn edit_bot(user: User, target: Ref, data: Json<Data>) -> Result<()> {
pub async fn edit_bot(user: User, target: Ref, data: Json<Data>) -> Result<EmptyResponse> {
let data = data.into_inner();
data.validate()
.map_err(|error| Error::FailedValidation { error })?;
@@ -112,5 +112,5 @@ pub async fn edit_bot(user: User, target: Ref, data: Json<Data>) -> Result<()> {
})?;
}
Ok(())
Ok(EmptyResponse {})
}

View File

@@ -1,5 +1,5 @@
use crate::database::*;
use crate::util::result::{Error, Result};
use crate::util::result::{Error, Result, EmptyResponse};
use rocket::serde::json::Json;
use serde::Deserialize;
@@ -22,7 +22,7 @@ pub enum Destination {
}
#[post("/<target>/invite", data = "<dest>")]
pub async fn invite_bot(user: User, target: Ref, dest: Json<Destination>) -> Result<()> {
pub async fn invite_bot(user: User, target: Ref, dest: Json<Destination>) -> Result<EmptyResponse> {
let bot = target.fetch_bot().await?;
if !bot.public {
@@ -39,13 +39,13 @@ pub async fn invite_bot(user: User, target: Ref, dest: Json<Destination>) -> Res
.with_server(&server)
.for_server()
.await?;
if !perm.get_manage_server() {
Err(Error::MissingPermission)?
}
server.join_member(&bot.id).await?;
Ok(())
Ok(EmptyResponse {})
}
Destination::Group(GroupId { group }) => {
let channel = Ref::from(group)?.fetch_channel().await?;
@@ -54,7 +54,7 @@ pub async fn invite_bot(user: User, target: Ref, dest: Json<Destination>) -> Res
.with_channel(&channel)
.for_channel()
.await?;
if !perm.get_invite_others() {
Err(Error::MissingPermission)?
}