description: data.description.to_owned(),
icon,
banner,
- category_id: data.category_id,
creator_id: user.id,
removed: None,
deleted: None,
description: data.description.to_owned(),
icon,
banner,
- category_id: data.category_id.to_owned(),
creator_id: read_community.creator_id,
removed: Some(read_community.removed),
deleted: Some(read_community.deleted),
UserOperation::TransferSite => {
do_websocket_operation::<TransferSite>(context, id, op, data).await
}
- UserOperation::ListCategories => {
- do_websocket_operation::<ListCategories>(context, id, op, data).await
- }
// Community ops
UserOperation::GetCommunity => {
.route("/config", web::get().to(route_get::<GetSiteConfig>))
.route("/config", web::put().to(route_post::<SaveSiteConfig>)),
)
- .service(
- web::resource("/categories")
- .wrap(rate_limit.message())
- .route(web::get().to(route_get::<ListCategories>)),
- )
.service(
web::resource("/modlog")
.wrap(rate_limit.message())
use actix_web::web::Data;
use anyhow::Context;
use lemmy_apub::fetcher::search::search_by_apub_id;
-use lemmy_db_queries::{
- diesel_option_overwrite,
- source::{category::Category_, site::Site_},
- Crud,
- SearchType,
- SortType,
-};
+use lemmy_db_queries::{diesel_option_overwrite, source::site::Site_, Crud, SearchType, SortType};
use lemmy_db_schema::{
naive_now,
source::{
- category::Category,
moderator::*,
site::{Site, *},
},
use log::{debug, info};
use std::str::FromStr;
-#[async_trait::async_trait(?Send)]
-impl Perform for ListCategories {
- type Response = ListCategoriesResponse;
-
- async fn perform(
- &self,
- context: &Data<LemmyContext>,
- _websocket_id: Option<ConnectionId>,
- ) -> Result<ListCategoriesResponse, LemmyError> {
- let _data: &ListCategories = &self;
-
- let categories = blocking(context.pool(), move |conn| Category::list_all(conn)).await??;
-
- // Return the jwt
- Ok(ListCategoriesResponse { categories })
- }
-}
-
#[async_trait::async_trait(?Send)]
impl Perform for GetModlog {
type Response = GetModlogResponse;
name: default_community_name.to_string(),
title: "The Default Community".to_string(),
description: Some("The Default Community".to_string()),
- category_id: 1,
nsfw: false,
creator_id: inserted_user.id,
removed: None,
use activitystreams::unparsed::UnparsedMutExt;
use activitystreams_ext::UnparsedExtension;
-use diesel::PgConnection;
-use lemmy_db_queries::Crud;
-use lemmy_db_schema::source::category::Category;
use lemmy_utils::LemmyError;
use serde::{Deserialize, Serialize};
-/// Activitystreams extension to allow (de)serializing additional Community fields `category` and
+/// Activitystreams extension to allow (de)serializing additional Community field
/// `sensitive` (called 'nsfw' in Lemmy).
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GroupExtension {
- pub category: Option<GroupCategory>,
pub sensitive: Option<bool>,
}
-#[derive(Clone, Debug, Default, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct GroupCategory {
- // Using a string because that's how Peertube does it.
- pub identifier: String,
- pub name: String,
-}
-
impl GroupExtension {
- pub fn new(
- conn: &PgConnection,
- category_id: i32,
- sensitive: bool,
- ) -> Result<GroupExtension, LemmyError> {
- let category = Category::read(conn, category_id)?;
- let group_category = GroupCategory {
- identifier: category_id.to_string(),
- name: category.name,
- };
+ pub fn new(sensitive: bool) -> Result<GroupExtension, LemmyError> {
Ok(GroupExtension {
- category: Some(group_category),
sensitive: Some(sensitive),
})
}
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
Ok(GroupExtension {
- category: unparsed_mut.remove("category")?,
sensitive: unparsed_mut.remove("sensitive")?,
})
}
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
- unparsed_mut.insert("category", self.category)?;
unparsed_mut.insert("sensitive", self.sensitive)?;
Ok(())
}
..Default::default()
});
- let nsfw = self.nsfw;
- let category_id = self.category_id;
- let group_extension = blocking(pool, move |conn| {
- GroupExtension::new(conn, category_id, nsfw)
- })
- .await??;
-
Ok(Ext2::new(
ap_actor,
- group_extension,
+ GroupExtension::new(self.nsfw)?,
self.get_public_key_ext()?,
))
}
name,
title,
description,
- category_id: group
- .ext_one
- .category
- .clone()
- .map(|c| c.identifier.parse::<i32>().ok())
- .flatten()
- .unwrap_or(1),
creator_id: creator.id,
removed: None,
published: group.inner.published().map(|u| u.to_owned().naive_local()),
creator_id: inserted_user.id,
title: "nada".to_owned(),
description: None,
- category_id: 1,
nsfw: false,
removed: None,
deleted: None,
creator_id: inserted_user.id,
title: "nada".to_owned(),
description: None,
- category_id: 1,
nsfw: false,
removed: None,
deleted: None,
creator_id: inserted_user.id,
title: "nada".to_owned(),
description: None,
- category_id: 1,
nsfw: false,
removed: None,
deleted: None,
creator_id: inserted_user.id,
title: "nada".to_owned(),
description: None,
- category_id: 1,
nsfw: false,
removed: None,
deleted: None,
creator_id: inserted_user.id,
title: "nada".to_owned(),
description: None,
- category_id: 1,
nsfw: false,
removed: None,
deleted: None,
creator_id: inserted_user.id,
title: "nada".to_owned(),
description: None,
- category_id: 1,
nsfw: false,
removed: None,
deleted: None,
+++ /dev/null
-use crate::Crud;
-use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{schema::category::dsl::*, source::category::*};
-
-impl Crud<CategoryForm> for Category {
- fn read(conn: &PgConnection, category_id: i32) -> Result<Self, Error> {
- category.find(category_id).first::<Self>(conn)
- }
-
- fn create(conn: &PgConnection, new_category: &CategoryForm) -> Result<Self, Error> {
- insert_into(category)
- .values(new_category)
- .get_result::<Self>(conn)
- }
-
- fn update(
- conn: &PgConnection,
- category_id: i32,
- new_category: &CategoryForm,
- ) -> Result<Self, Error> {
- diesel::update(category.find(category_id))
- .set(new_category)
- .get_result::<Self>(conn)
- }
-}
-
-pub trait Category_ {
- fn list_all(conn: &PgConnection) -> Result<Vec<Category>, Error>;
-}
-
-impl Category_ for Category {
- fn list_all(conn: &PgConnection) -> Result<Vec<Category>, Error> {
- category.load::<Self>(conn)
- }
-}
-
-#[cfg(test)]
-mod tests {
- use crate::{establish_unpooled_connection, source::category::Category_};
- use lemmy_db_schema::source::category::Category;
-
- #[test]
- fn test_crud() {
- let conn = establish_unpooled_connection();
-
- let categories = Category::list_all(&conn).unwrap();
- let expected_first_category = Category {
- id: 1,
- name: "Discussion".into(),
- };
-
- assert_eq!(expected_first_category, categories[0]);
- }
-}
name: "test community".to_string(),
title: "nada".to_owned(),
description: None,
- category_id: 1,
creator_id: inserted_user.id,
removed: None,
deleted: None,
name,
title,
description,
- category_id,
creator_id,
removed,
published,
name,
title,
description,
- category_id,
creator_id,
removed,
published,
creator_id: inserted_user.id,
title: "nada".to_owned(),
description: None,
- category_id: 1,
nsfw: false,
removed: None,
deleted: None,
name: "TIL".into(),
title: "nada".to_owned(),
description: None,
- category_id: 1,
nsfw: false,
removed: false,
deleted: false,
pub mod activity;
-pub mod category;
pub mod comment;
pub mod comment_report;
pub mod community;
name: "mod_community".to_string(),
title: "nada".to_owned(),
description: None,
- category_id: 1,
creator_id: inserted_user.id,
removed: None,
deleted: None,
name: "test community_3".to_string(),
title: "nada".to_owned(),
description: None,
- category_id: 1,
creator_id: inserted_user.id,
removed: None,
deleted: None,
name: "test community lake".to_string(),
title: "nada".to_owned(),
description: None,
- category_id: 1,
creator_id: inserted_user.id,
removed: None,
deleted: None,
}
}
-table! {
- category (id) {
- id -> Int4,
- name -> Varchar,
- }
-}
-
table! {
comment (id) {
id -> Int4,
name -> Varchar,
title -> Varchar,
description -> Nullable<Text>,
- category_id -> Int4,
creator_id -> Int4,
removed -> Bool,
published -> Timestamp,
joinable!(comment_report -> comment (comment_id));
joinable!(comment_saved -> comment (comment_id));
joinable!(comment_saved -> user_ (user_id));
-joinable!(community -> category (category_id));
joinable!(community -> user_ (creator_id));
joinable!(community_aggregates -> community (community_id));
joinable!(community_follower -> community (community_id));
allow_tables_to_appear_in_same_query!(
activity,
- category,
comment,
comment_aggregates,
comment_like,
+++ /dev/null
-use crate::schema::category;
-use serde::Serialize;
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Clone)]
-#[table_name = "category"]
-pub struct Category {
- pub id: i32,
- pub name: String,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "category"]
-pub struct CategoryForm {
- pub name: String,
-}
pub name: String,
pub title: String,
pub description: Option<String>,
- pub category_id: i32,
pub creator_id: i32,
pub removed: bool,
pub published: chrono::NaiveDateTime,
pub name: String,
pub title: String,
pub description: Option<String>,
- pub category_id: i32,
pub creator_id: i32,
pub removed: bool,
pub published: chrono::NaiveDateTime,
pub name: String,
pub title: String,
pub description: Option<String>,
- pub category_id: i32,
pub creator_id: i32,
pub removed: Option<bool>,
pub published: Option<chrono::NaiveDateTime>,
pub mod activity;
-pub mod category;
pub mod comment;
pub mod comment_report;
pub mod community;
name: "test community 5".to_string(),
title: "nada".to_owned(),
description: None,
- category_id: 1,
creator_id: inserted_user.id,
removed: None,
deleted: None,
title: "nada".to_owned(),
description: None,
creator_id: inserted_user.id,
- category_id: 1,
updated: None,
banner: None,
published: inserted_community.published,
title: "nada".to_owned(),
description: None,
creator_id: inserted_user.id,
- category_id: 1,
removed: None,
deleted: None,
updated: None,
title: "nada".to_owned(),
description: None,
creator_id: inserted_user.id,
- category_id: 1,
updated: None,
banner: None,
published: inserted_community.published,
ViewToVec,
};
use lemmy_db_schema::{
- schema::{category, community, community_aggregates, community_follower, user_},
+ schema::{community, community_aggregates, community_follower, user_},
source::{
- category::Category,
community::{Community, CommunityFollower, CommunitySafe},
user::{UserSafe, User_},
},
pub struct CommunityView {
pub community: CommunitySafe,
pub creator: UserSafe,
- pub category: Category,
pub subscribed: bool,
pub counts: CommunityAggregates,
}
type CommunityViewTuple = (
CommunitySafe,
UserSafe,
- Category,
CommunityAggregates,
Option<CommunityFollower>,
);
// The left join below will return None in this case
let user_id_join = my_user_id.unwrap_or(-1);
- let (community, creator, category, counts, follower) = community::table
+ let (community, creator, counts, follower) = community::table
.find(community_id)
.inner_join(user_::table)
- .inner_join(category::table)
.inner_join(community_aggregates::table)
.left_join(
community_follower::table.on(
.select((
Community::safe_columns_tuple(),
User_::safe_columns_tuple(),
- category::all_columns,
community_aggregates::all_columns,
community_follower::all_columns.nullable(),
))
Ok(CommunityView {
community,
creator,
- category,
subscribed: follower.is_some(),
counts,
})
let mut query = community::table
.inner_join(user_::table)
- .inner_join(category::table)
.inner_join(community_aggregates::table)
.left_join(
community_follower::table.on(
.select((
Community::safe_columns_tuple(),
User_::safe_columns_tuple(),
- category::all_columns,
community_aggregates::all_columns,
community_follower::all_columns.nullable(),
))
.map(|a| Self {
community: a.0.to_owned(),
creator: a.1.to_owned(),
- category: a.2.to_owned(),
- counts: a.3.to_owned(),
- subscribed: a.4.is_some(),
+ counts: a.2.to_owned(),
+ subscribed: a.3.is_some(),
})
.collect::<Vec<Self>>()
}
-use lemmy_db_schema::source::{category::*, user::UserSafeSettings};
+use lemmy_db_schema::source::user::UserSafeSettings;
use lemmy_db_views::{comment_view::CommentView, post_view::PostView, site_view::SiteView};
use lemmy_db_views_actor::{community_view::CommunityView, user_view::UserViewSafe};
use lemmy_db_views_moderator::{
};
use serde::{Deserialize, Serialize};
-#[derive(Deserialize)]
-pub struct ListCategories {}
-
-#[derive(Serialize)]
-pub struct ListCategoriesResponse {
- pub categories: Vec<Category>,
-}
-
#[derive(Deserialize, Debug)]
pub struct Search {
pub q: String,
CreateCommunity,
CreatePost,
ListCommunities,
- ListCategories,
GetPost,
GetCommunity,
CreateComment,
--- /dev/null
+create table category (
+ id serial primary key,
+ name varchar(100) not null unique
+);
+
+insert into category (name) values
+('Discussion'),
+('Humor/Memes'),
+('Gaming'),
+('Movies'),
+('TV'),
+('Music'),
+('Literature'),
+('Comics'),
+('Photography'),
+('Art'),
+('Learning'),
+('DIY'),
+('Lifestyle'),
+('News'),
+('Politics'),
+('Society'),
+('Gender/Identity/Sexuality'),
+('Race/Colonisation'),
+('Religion'),
+('Science/Technology'),
+('Programming/Software'),
+('Health/Sports/Fitness'),
+('Porn'),
+('Places'),
+('Meta'),
+('Other');
+
+ALTER TABLE community ADD category_id int references category on update cascade on delete cascade not null;
\ No newline at end of file
--- /dev/null
+ALTER TABLE community DROP COLUMN category_id;
+DROP TABLE category;
name: ccommunity.name.to_owned(),
title: ccommunity.title.to_owned(),
description: ccommunity.description.to_owned(),
- category_id: ccommunity.category_id,
creator_id: ccommunity.creator_id,
removed: None,
deleted: None,
creator_id,
title: "test_community".to_owned(),
description: None,
- category_id: 1,
nsfw: false,
removed: None,
deleted: None,