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

@@ -5,7 +5,7 @@ use serde::{Serialize, Deserialize};
use crate::database::*;
use crate::database::permissions::channel::{ ChannelPermission, DEFAULT_PERMISSION_DM };
use crate::notifications::events::ClientboundNotification;
use crate::util::result::{Error, Result};
use crate::util::result::{Error, Result, EmptyResponse};
#[derive(Serialize, Deserialize)]
pub struct Data {
@@ -13,14 +13,14 @@ 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_channel().await?;
match target {
Channel::Group { id, owner, .. } => {
if user.id == owner {
let permissions: u32 = ChannelPermission::View as u32 | (data.permissions & *DEFAULT_PERMISSION_DM);
get_collection("channels")
.update_one(
doc! { "_id": &id },
@@ -36,7 +36,7 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
operation: "update_one",
with: "channel"
})?;
ClientboundNotification::ChannelUpdate {
id: id.clone(),
data: json!({
@@ -45,8 +45,8 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
clear: None
}
.publish(id);
Ok(())
Ok(EmptyResponse {})
} else {
Err(Error::MissingPermission)
}
@@ -58,13 +58,13 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
.with_server(&target)
.for_server()
.await?;
if !perm.get_manage_roles() {
return Err(Error::MissingPermission);
}
let permissions: u32 = ChannelPermission::View as u32 | data.permissions;
get_collection("channels")
.update_one(
doc! { "_id": &id },
@@ -80,7 +80,7 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
operation: "update_one",
with: "channel"
})?;
ClientboundNotification::ChannelUpdate {
id: id.clone(),
data: json!({
@@ -90,7 +90,7 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
}
.publish(id);
Ok(())
Ok(EmptyResponse {})
}
_ => Err(Error::InvalidOperation)
}