summaryrefslogtreecommitdiffstats
path: root/server/src/api/site.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/api/site.rs')
-rw-r--r--server/src/api/site.rs46
1 files changed, 14 insertions, 32 deletions
diff --git a/server/src/api/site.rs b/server/src/api/site.rs
index ce07724a..a5faf34d 100644
--- a/server/src/api/site.rs
+++ b/server/src/api/site.rs
@@ -7,7 +7,6 @@ pub struct ListCategories;
#[derive(Serialize, Deserialize)]
pub struct ListCategoriesResponse {
- op: String,
categories: Vec<Category>,
}
@@ -24,7 +23,6 @@ pub struct Search {
#[derive(Serialize, Deserialize)]
pub struct SearchResponse {
- op: String,
type_: String,
comments: Vec<CommentView>,
posts: Vec<PostView>,
@@ -42,7 +40,6 @@ pub struct GetModlog {
#[derive(Serialize, Deserialize)]
pub struct GetModlogResponse {
- op: String,
removed_posts: Vec<ModRemovePostView>,
locked_posts: Vec<ModLockPostView>,
stickied_posts: Vec<ModStickyPostView>,
@@ -79,13 +76,11 @@ pub struct GetSite;
#[derive(Serialize, Deserialize)]
pub struct SiteResponse {
- op: String,
site: SiteView,
}
#[derive(Serialize, Deserialize)]
pub struct GetSiteResponse {
- op: String,
site: Option<SiteView>,
admins: Vec<UserView>,
banned: Vec<UserView>,
@@ -105,10 +100,7 @@ impl Perform<ListCategoriesResponse> for Oper<ListCategories> {
let categories: Vec<Category> = Category::list_all(&conn)?;
// Return the jwt
- Ok(ListCategoriesResponse {
- op: self.op.to_string(),
- categories,
- })
+ Ok(ListCategoriesResponse { categories })
}
}
@@ -172,7 +164,6 @@ impl Perform<GetModlogResponse> for Oper<GetModlog> {
// Return the jwt
Ok(GetModlogResponse {
- op: self.op.to_string(),
removed_posts,
locked_posts,
stickied_posts,
@@ -192,20 +183,20 @@ impl Perform<SiteResponse> for Oper<CreateSite> {
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
- Err(_e) => return Err(APIError::err(&self.op, "not_logged_in").into()),
+ Err(_e) => return Err(APIError::err("not_logged_in").into()),
};
if has_slurs(&data.name)
|| (data.description.is_some() && has_slurs(&data.description.to_owned().unwrap()))
{
- return Err(APIError::err(&self.op, "no_slurs").into());
+ return Err(APIError::err("no_slurs").into());
}
let user_id = claims.id;
// Make sure user is an admin
if !UserView::read(&conn, user_id)?.admin {
- return Err(APIError::err(&self.op, "not_an_admin").into());
+ return Err(APIError::err("not_an_admin").into());
}
let site_form = SiteForm {
@@ -220,15 +211,12 @@ impl Perform<SiteResponse> for Oper<CreateSite> {
match Site::create(&conn, &site_form) {
Ok(site) => site,
- Err(_e) => return Err(APIError::err(&self.op, "site_already_exists").into()),
+ Err(_e) => return Err(APIError::err("site_already_exists").into()),
};
let site_view = SiteView::read(&conn)?;
- Ok(SiteResponse {
- op: self.op.to_string(),
- site: site_view,
- })
+ Ok(SiteResponse { site: site_view })
}
}
@@ -238,20 +226,20 @@ impl Perform<SiteResponse> for Oper<EditSite> {
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
- Err(_e) => return Err(APIError::err(&self.op, "not_logged_in").into()),
+ Err(_e) => return Err(APIError::err("not_logged_in").into()),
};
if has_slurs(&data.name)
|| (data.description.is_some() && has_slurs(&data.description.to_owned().unwrap()))
{
- return Err(APIError::err(&self.op, "no_slurs").into());
+ return Err(APIError::err("no_slurs").into());
}
let user_id = claims.id;
// Make sure user is an admin
if !UserView::read(&conn, user_id)?.admin {
- return Err(APIError::err(&self.op, "not_an_admin").into());
+ return Err(APIError::err("not_an_admin").into());
}
let found_site = Site::read(&conn, 1)?;
@@ -268,15 +256,12 @@ impl Perform<SiteResponse> for Oper<EditSite> {
match Site::update(&conn, 1, &site_form) {
Ok(site) => site,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_site").into()),
+ Err(_e) => return Err(APIError::err("couldnt_update_site").into()),
};
let site_view = SiteView::read(&conn)?;
- Ok(SiteResponse {
- op: self.op.to_string(),
- site: site_view,
- })
+ Ok(SiteResponse { site: site_view })
}
}
@@ -301,7 +286,6 @@ impl Perform<GetSiteResponse> for Oper<GetSite> {
let banned = UserView::banned(&conn)?;
Ok(GetSiteResponse {
- op: self.op.to_string(),
site: site_view,
admins,
banned,
@@ -419,7 +403,6 @@ impl Perform<SearchResponse> for Oper<Search> {
// Return the jwt
Ok(SearchResponse {
- op: self.op.to_string(),
type_: data.type_.to_owned(),
comments,
posts,
@@ -435,7 +418,7 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> {
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
- Err(_e) => return Err(APIError::err(&self.op, "not_logged_in").into()),
+ Err(_e) => return Err(APIError::err("not_logged_in").into()),
};
let user_id = claims.id;
@@ -444,7 +427,7 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> {
// Make sure user is the creator
if read_site.creator_id != user_id {
- return Err(APIError::err(&self.op, "not_an_admin").into());
+ return Err(APIError::err("not_an_admin").into());
}
let site_form = SiteForm {
@@ -459,7 +442,7 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> {
match Site::update(&conn, 1, &site_form) {
Ok(site) => site,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_site").into()),
+ Err(_e) => return Err(APIError::err("couldnt_update_site").into()),
};
// Mod tables
@@ -484,7 +467,6 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> {
let banned = UserView::banned(&conn)?;
Ok(GetSiteResponse {
- op: self.op.to_string(),
site: Some(site_view),
admins,
banned,