Enhancement: Routes with no body should return 204 No Content.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket::serde::json::Json;
|
||||
@@ -13,7 +13,7 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[put("/<server>/bans/<target>", data = "<data>")]
|
||||
pub async fn req(user: User, server: Ref, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
pub async fn req(user: User, server: Ref, target: Ref, data: Json<Data>) -> Result<EmptyResponse> {
|
||||
let data = data.into_inner();
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
@@ -57,5 +57,6 @@ pub async fn req(user: User, server: Ref, target: Ref, data: Json<Data>) -> Resu
|
||||
with: "server_ban",
|
||||
})?;
|
||||
|
||||
server.remove_member(&target.id, RemoveMember::Ban).await
|
||||
server.remove_member(&target.id, RemoveMember::Ban).await;
|
||||
Ok(EmptyResponse {})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
|
||||
#[delete("/<server>/bans/<target>")]
|
||||
pub async fn req(user: User, server: Ref, target: Ref) -> Result<()> {
|
||||
pub async fn req(user: User, server: Ref, target: Ref) -> Result<EmptyResponse> {
|
||||
let server = server.fetch_server().await?;
|
||||
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
@@ -39,5 +39,5 @@ pub async fn req(user: User, server: Ref, target: Ref) -> Result<()> {
|
||||
with: "server_ban",
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
Ok(EmptyResponse {})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
use crate::{database::*, notifications::events::RemoveMemberField};
|
||||
|
||||
use mongodb::bson::{doc, to_document};
|
||||
@@ -19,7 +19,7 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[patch("/<server>/members/<target>", data = "<data>")]
|
||||
pub async fn req(user: User, server: Ref, target: String, data: Json<Data>) -> Result<()> {
|
||||
pub async fn req(user: User, server: Ref, target: String, data: Json<Data>) -> Result<EmptyResponse> {
|
||||
let data = data.into_inner();
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
@@ -154,5 +154,5 @@ pub async fn req(user: User, server: Ref, target: String, data: Json<Data>) -> R
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(EmptyResponse {})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
|
||||
#[delete("/<target>/members/<member>")]
|
||||
pub async fn req(user: User, target: Ref, member: String) -> Result<()> {
|
||||
pub async fn req(user: User, target: Ref, member: String) -> Result<EmptyResponse> {
|
||||
let target = target.fetch_server().await?;
|
||||
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
@@ -27,5 +27,7 @@ pub async fn req(user: User, target: Ref, member: String) -> Result<()> {
|
||||
|
||||
target
|
||||
.remove_member(&member.id.user, RemoveMember::Kick)
|
||||
.await
|
||||
.await;
|
||||
|
||||
Ok(EmptyResponse {})
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::database::*;
|
||||
use crate::database::permissions::channel::ChannelPermission;
|
||||
use crate::database::permissions::server::ServerPermission;
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Values {
|
||||
@@ -20,7 +20,7 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[put("/<target>/permissions/<role_id>", data = "<data>", rank = 2)]
|
||||
pub async fn req(user: User, target: Ref, role_id: String, data: Json<Data>) -> Result<()> {
|
||||
pub async fn req(user: User, target: Ref, role_id: String, data: Json<Data>) -> Result<EmptyResponse> {
|
||||
let target = target.fetch_server().await?;
|
||||
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
@@ -38,7 +38,7 @@ pub async fn req(user: User, target: Ref, role_id: String, data: Json<Data>) ->
|
||||
|
||||
let server_permissions: u32 = ServerPermission::View as u32 | data.permissions.server;
|
||||
let channel_permissions: u32 = ChannelPermission::View as u32 | data.permissions.channel;
|
||||
|
||||
|
||||
get_collection("servers")
|
||||
.update_one(
|
||||
doc! { "_id": &target.id },
|
||||
@@ -57,7 +57,7 @@ pub async fn req(user: User, target: Ref, role_id: String, data: Json<Data>) ->
|
||||
operation: "update_one",
|
||||
with: "server"
|
||||
})?;
|
||||
|
||||
|
||||
ClientboundNotification::ServerRoleUpdate {
|
||||
id: target.id.clone(),
|
||||
role_id,
|
||||
@@ -71,5 +71,5 @@ pub async fn req(user: User, target: Ref, role_id: String, data: Json<Data>) ->
|
||||
}
|
||||
.publish(target.id);
|
||||
|
||||
Ok(())
|
||||
Ok(EmptyResponse)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::database::*;
|
||||
use crate::database::permissions::channel::ChannelPermission;
|
||||
use crate::database::permissions::server::ServerPermission;
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Values {
|
||||
@@ -20,7 +20,7 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[put("/<target>/permissions/default", data = "<data>", rank = 1)]
|
||||
pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<EmptyResponse> {
|
||||
let target = target.fetch_server().await?;
|
||||
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
@@ -34,7 +34,7 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
|
||||
let server_permissions: u32 = ServerPermission::View as u32 | data.permissions.server;
|
||||
let channel_permissions: u32 = ChannelPermission::View as u32 | data.permissions.channel;
|
||||
|
||||
|
||||
get_collection("servers")
|
||||
.update_one(
|
||||
doc! { "_id": &target.id },
|
||||
@@ -53,7 +53,7 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
operation: "update_one",
|
||||
with: "server"
|
||||
})?;
|
||||
|
||||
|
||||
ClientboundNotification::ServerUpdate {
|
||||
id: target.id.clone(),
|
||||
data: json!({
|
||||
@@ -66,5 +66,5 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
}
|
||||
.publish(target.id);
|
||||
|
||||
Ok(())
|
||||
Ok(EmptyResponse {})
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use crate::database::*;
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
|
||||
#[delete("/<target>/roles/<role_id>")]
|
||||
pub async fn req(user: User, target: Ref, role_id: String) -> Result<()> {
|
||||
pub async fn req(user: User, target: Ref, role_id: String) -> Result<EmptyResponse> {
|
||||
let target = target.fetch_server().await?;
|
||||
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
@@ -70,12 +70,12 @@ pub async fn req(user: User, target: Ref, role_id: String) -> Result<()> {
|
||||
operation: "update_many",
|
||||
with: "server_members"
|
||||
})?;
|
||||
|
||||
|
||||
ClientboundNotification::ServerRoleDelete {
|
||||
id: target.id.clone(),
|
||||
role_id
|
||||
}
|
||||
.publish(target.id);
|
||||
|
||||
Ok(())
|
||||
Ok(EmptyResponse {})
|
||||
}
|
||||
|
||||
@@ -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::RemoveRoleField};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
@@ -19,7 +19,7 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[patch("/<target>/roles/<role_id>", data = "<data>")]
|
||||
pub async fn req(user: User, target: Ref, role_id: String, data: Json<Data>) -> Result<()> {
|
||||
pub async fn req(user: User, target: Ref, role_id: String, data: Json<Data>) -> Result<EmptyResponse> {
|
||||
let data = data.into_inner();
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
@@ -106,5 +106,5 @@ pub async fn req(user: User, target: Ref, role_id: String, data: Json<Data>) ->
|
||||
}
|
||||
.publish(target.id.clone());
|
||||
|
||||
Ok(())
|
||||
Ok(EmptyResponse {})
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
#[put("/<target>/ack")]
|
||||
pub async fn req(user: User, target: Ref) -> Result<()> {
|
||||
pub async fn req(user: User, target: Ref) -> Result<EmptyResponse> {
|
||||
if user.bot.is_some() {
|
||||
return Err(Error::IsBot)
|
||||
}
|
||||
|
||||
|
||||
let target = target.fetch_server().await?;
|
||||
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
@@ -18,5 +18,6 @@ pub async fn req(user: User, target: Ref) -> Result<()> {
|
||||
Err(Error::MissingPermission)?
|
||||
}
|
||||
|
||||
target.mark_as_read(&user.id).await
|
||||
target.mark_as_read(&user.id).await;
|
||||
Ok(EmptyResponse {})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
|
||||
#[delete("/<target>")]
|
||||
pub async fn req(user: User, target: Ref) -> Result<()> {
|
||||
pub async fn req(user: User, target: Ref) -> Result<EmptyResponse> {
|
||||
let target = target.fetch_server().await?;
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
.with_server(&target)
|
||||
|
||||
@@ -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::RemoveServerField};
|
||||
|
||||
use mongodb::bson::{doc, to_bson, to_document};
|
||||
@@ -21,14 +21,14 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[patch("/<target>", data = "<data>")]
|
||||
pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<EmptyResponse> {
|
||||
let data = data.into_inner();
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
if data.name.is_none() && data.description.is_none() && data.icon.is_none() && data.banner.is_none() && data.remove.is_none() && data.categories.is_none() && data.system_messages.is_none()
|
||||
{
|
||||
return Ok(());
|
||||
return Ok(EmptyResponse {});
|
||||
}
|
||||
|
||||
let target = target.fetch_server().await?;
|
||||
@@ -145,5 +145,5 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(EmptyResponse {})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user