From: Nutomic Date: Fri, 6 May 2022 20:55:07 +0000 (+0000) Subject: Derive default for api request structs, move type enums (#2245) X-Git-Url: http://these/git/%22https:/lemmy.ml/u/Liwott/%24%7Bargs.pageFn.prev%7D?a=commitdiff_plain;h=3053e14be7a47675b621e1c80aa88f4f0a5ce1ae;p=lemmy.git Derive default for api request structs, move type enums (#2245) * Derive default for api request structs, move type enums * Simplify api by using enum types directly, instead of string * Add default and clone for most api structs --- diff --git a/crates/api/src/local_user/notifications/list_mentions.rs b/crates/api/src/local_user/notifications/list_mentions.rs index 91409b6d..6e786841 100644 --- a/crates/api/src/local_user/notifications/list_mentions.rs +++ b/crates/api/src/local_user/notifications/list_mentions.rs @@ -4,7 +4,6 @@ use lemmy_api_common::{ person::{GetPersonMentions, GetPersonMentionsResponse}, utils::{blocking, get_local_user_view_from_jwt}, }; -use lemmy_db_schema::utils::{from_opt_str_to_opt_enum, SortType}; use lemmy_db_views_actor::person_mention_view::PersonMentionQueryBuilder; use lemmy_utils::{ConnectionId, LemmyError}; use lemmy_websocket::LemmyContext; @@ -23,8 +22,7 @@ impl Perform for GetPersonMentions { let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; - let sort: Option = from_opt_str_to_opt_enum(&data.sort); - + let sort = data.sort; let page = data.page; let limit = data.limit; let unread_only = data.unread_only; diff --git a/crates/api/src/local_user/notifications/list_replies.rs b/crates/api/src/local_user/notifications/list_replies.rs index 1d9aaa2f..643a1c9a 100644 --- a/crates/api/src/local_user/notifications/list_replies.rs +++ b/crates/api/src/local_user/notifications/list_replies.rs @@ -4,7 +4,6 @@ use lemmy_api_common::{ person::{GetReplies, GetRepliesResponse}, utils::{blocking, get_local_user_view_from_jwt}, }; -use lemmy_db_schema::utils::{from_opt_str_to_opt_enum, SortType}; use lemmy_db_views::comment_view::CommentQueryBuilder; use lemmy_utils::{ConnectionId, LemmyError}; use lemmy_websocket::LemmyContext; @@ -23,8 +22,7 @@ impl Perform for GetReplies { let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; - let sort: Option = from_opt_str_to_opt_enum(&data.sort); - + let sort = data.sort; let page = data.page; let limit = data.limit; let unread_only = data.unread_only; diff --git a/crates/api/src/site/search.rs b/crates/api/src/site/search.rs index b4d2069c..5e147423 100644 --- a/crates/api/src/site/search.rs +++ b/crates/api/src/site/search.rs @@ -5,11 +5,7 @@ use lemmy_api_common::{ utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt}, }; use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity}; -use lemmy_db_schema::{ - source::community::Community, - traits::DeleteableOrRemoveable, - utils::{from_opt_str_to_opt_enum, ListingType, SearchType, SortType}, -}; +use lemmy_db_schema::{source::community::Community, traits::DeleteableOrRemoveable, SearchType}; use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder}; use lemmy_db_views_actor::{ community_view::CommunityQueryBuilder, @@ -56,9 +52,9 @@ impl Perform for Search { let q = data.q.to_owned(); let page = data.page; let limit = data.limit; - let sort: Option = from_opt_str_to_opt_enum(&data.sort); - let listing_type: Option = from_opt_str_to_opt_enum(&data.listing_type); - let search_type: SearchType = from_opt_str_to_opt_enum(&data.type_).unwrap_or(SearchType::All); + let sort = data.sort; + let listing_type = data.listing_type; + let search_type = data.type_.unwrap_or(SearchType::All); let community_id = data.community_id; let community_actor_id = if let Some(name) = &data.community_name { resolve_actor_identifier::(name, context) diff --git a/crates/api_common/src/comment.rs b/crates/api_common/src/comment.rs index 048a3439..790f21ae 100644 --- a/crates/api_common/src/comment.rs +++ b/crates/api_common/src/comment.rs @@ -1,9 +1,13 @@ use crate::sensitive::Sensitive; -use lemmy_db_schema::newtypes::{CommentId, CommentReportId, CommunityId, LocalUserId, PostId}; +use lemmy_db_schema::{ + newtypes::{CommentId, CommentReportId, CommunityId, LocalUserId, PostId}, + ListingType, + SortType, +}; use lemmy_db_views::structs::{CommentReportView, CommentView}; use serde::{Deserialize, Serialize}; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct CreateComment { pub content: String, pub post_id: PostId, @@ -12,13 +16,13 @@ pub struct CreateComment { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetComment { pub id: CommentId, pub auth: Option>, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct EditComment { pub content: String, pub comment_id: CommentId, @@ -26,14 +30,14 @@ pub struct EditComment { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct DeleteComment { pub comment_id: CommentId, pub deleted: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct RemoveComment { pub comment_id: CommentId, pub removed: bool, @@ -41,14 +45,14 @@ pub struct RemoveComment { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct MarkCommentAsRead { pub comment_id: CommentId, pub read: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct SaveComment { pub comment_id: CommentId, pub save: bool, @@ -62,17 +66,17 @@ pub struct CommentResponse { pub form_id: Option, // An optional front end ID, to tell which is coming back } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct CreateCommentLike { pub comment_id: CommentId, pub score: i16, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetComments { - pub type_: Option, - pub sort: Option, + pub type_: Option, + pub sort: Option, pub page: Option, pub limit: Option, pub community_id: Option, @@ -81,12 +85,12 @@ pub struct GetComments { pub auth: Option>, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetCommentsResponse { pub comments: Vec, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct CreateCommentReport { pub comment_id: CommentId, pub reason: String, @@ -98,14 +102,14 @@ pub struct CommentReportResponse { pub comment_report_view: CommentReportView, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct ResolveCommentReport { pub report_id: CommentReportId, pub resolved: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct ListCommentReports { pub page: Option, pub limit: Option, @@ -116,7 +120,7 @@ pub struct ListCommentReports { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct ListCommentReportsResponse { pub comment_reports: Vec, } diff --git a/crates/api_common/src/community.rs b/crates/api_common/src/community.rs index 0635b9fa..90c86f1c 100644 --- a/crates/api_common/src/community.rs +++ b/crates/api_common/src/community.rs @@ -2,11 +2,13 @@ use crate::sensitive::Sensitive; use lemmy_db_schema::{ newtypes::{CommunityId, PersonId}, source::site::Site, + ListingType, + SortType, }; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonViewSafe}; use serde::{Deserialize, Serialize}; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetCommunity { pub id: Option, /// Example: star_trek , or star_trek@xyz.tld @@ -14,7 +16,7 @@ pub struct GetCommunity { pub auth: Option>, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetCommunityResponse { pub community_view: CommunityView, pub site: Option, @@ -22,7 +24,7 @@ pub struct GetCommunityResponse { pub online: usize, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct CreateCommunity { pub name: String, pub title: String, @@ -39,21 +41,21 @@ pub struct CommunityResponse { pub community_view: CommunityView, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct ListCommunities { - pub type_: Option, - pub sort: Option, + pub type_: Option, + pub sort: Option, pub page: Option, pub limit: Option, pub auth: Option>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct ListCommunitiesResponse { pub communities: Vec, } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct BanFromCommunity { pub community_id: CommunityId, pub person_id: PersonId, @@ -70,7 +72,7 @@ pub struct BanFromCommunityResponse { pub banned: bool, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct AddModToCommunity { pub community_id: CommunityId, pub person_id: PersonId, @@ -83,7 +85,7 @@ pub struct AddModToCommunityResponse { pub moderators: Vec, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct EditCommunity { pub community_id: CommunityId, pub title: Option, @@ -95,7 +97,7 @@ pub struct EditCommunity { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct HideCommunity { pub community_id: CommunityId, pub hidden: bool, @@ -103,14 +105,14 @@ pub struct HideCommunity { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct DeleteCommunity { pub community_id: CommunityId, pub deleted: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct RemoveCommunity { pub community_id: CommunityId, pub removed: bool, @@ -119,14 +121,14 @@ pub struct RemoveCommunity { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct FollowCommunity { pub community_id: CommunityId, pub follow: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct BlockCommunity { pub community_id: CommunityId, pub block: bool, @@ -139,7 +141,7 @@ pub struct BlockCommunityResponse { pub blocked: bool, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct TransferCommunity { pub community_id: CommunityId, pub person_id: PersonId, diff --git a/crates/api_common/src/lib.rs b/crates/api_common/src/lib.rs index 0dda34ec..6cb9a2f1 100644 --- a/crates/api_common/src/lib.rs +++ b/crates/api_common/src/lib.rs @@ -4,7 +4,7 @@ pub mod person; pub mod post; #[cfg(feature = "full")] pub mod request; -mod sensitive; +pub mod sensitive; pub mod site; #[cfg(feature = "full")] pub mod utils; diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index 3bc09f77..a9102325 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -3,14 +3,17 @@ use lemmy_db_views::structs::{CommentView, PostView, PrivateMessageView}; use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonMentionView, PersonViewSafe}; use serde::{Deserialize, Serialize}; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct Login { pub username_or_email: Sensitive, pub password: Sensitive, } -use lemmy_db_schema::newtypes::{CommunityId, PersonId, PersonMentionId, PrivateMessageId}; +use lemmy_db_schema::{ + newtypes::{CommunityId, PersonId, PersonMentionId, PrivateMessageId}, + SortType, +}; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct Register { pub username: String, pub password: Sensitive, @@ -25,22 +28,22 @@ pub struct Register { pub answer: Option, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetCaptcha {} -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetCaptchaResponse { pub ok: Option, // Will be None if captchas are disabled } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct CaptchaResponse { pub png: String, // A Base64 encoded png pub wav: String, // A Base64 encoded wav audio pub uuid: String, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct SaveUserSettings { pub show_nsfw: Option, pub show_scores: Option, @@ -63,7 +66,7 @@ pub struct SaveUserSettings { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct ChangePassword { pub new_password: Sensitive, pub new_password_verify: Sensitive, @@ -71,7 +74,7 @@ pub struct ChangePassword { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct LoginResponse { /// This is None in response to `Register` if email verification is enabled, or the server requires registration applications. pub jwt: Option>, @@ -79,12 +82,12 @@ pub struct LoginResponse { pub verify_email_sent: bool, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetPersonDetails { pub person_id: Option, // One of these two are required /// Example: dessalines , or dessalines@xyz.tld pub username: Option, - pub sort: Option, + pub sort: Option, pub page: Option, pub limit: Option, pub community_id: Option, @@ -92,7 +95,7 @@ pub struct GetPersonDetails { pub auth: Option>, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetPersonDetailsResponse { pub person_view: PersonViewSafe, pub comments: Vec, @@ -100,22 +103,22 @@ pub struct GetPersonDetailsResponse { pub moderates: Vec, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetRepliesResponse { pub replies: Vec, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetPersonMentionsResponse { pub mentions: Vec, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct MarkAllAsRead { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct AddAdmin { pub person_id: PersonId, pub added: bool, @@ -127,7 +130,7 @@ pub struct AddAdminResponse { pub admins: Vec, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct BanPerson { pub person_id: PersonId, pub ban: bool, @@ -137,12 +140,12 @@ pub struct BanPerson { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetBannedPersons { pub auth: String, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct BannedPersonsResponse { pub banned: Vec, } @@ -153,7 +156,7 @@ pub struct BanPersonResponse { pub banned: bool, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct BlockPerson { pub person_id: PersonId, pub block: bool, @@ -166,25 +169,25 @@ pub struct BlockPersonResponse { pub blocked: bool, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetReplies { - pub sort: Option, + pub sort: Option, pub page: Option, pub limit: Option, pub unread_only: Option, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetPersonMentions { - pub sort: Option, + pub sort: Option, pub page: Option, pub limit: Option, pub unread_only: Option, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct MarkPersonMentionAsRead { pub person_mention_id: PersonMentionId, pub read: bool, @@ -196,7 +199,7 @@ pub struct PersonMentionResponse { pub person_mention_view: PersonMentionView, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct DeleteAccount { pub password: Sensitive, pub auth: Sensitive, @@ -205,7 +208,7 @@ pub struct DeleteAccount { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct DeleteAccountResponse {} -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct PasswordReset { pub email: Sensitive, } @@ -213,42 +216,42 @@ pub struct PasswordReset { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct PasswordResetResponse {} -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct PasswordChangeAfterReset { pub token: Sensitive, pub password: Sensitive, pub password_verify: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct CreatePrivateMessage { pub content: String, pub recipient_id: PersonId, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct EditPrivateMessage { pub private_message_id: PrivateMessageId, pub content: String, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct DeletePrivateMessage { pub private_message_id: PrivateMessageId, pub deleted: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct MarkPrivateMessageAsRead { pub private_message_id: PrivateMessageId, pub read: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetPrivateMessages { pub unread_only: Option, pub page: Option, @@ -266,7 +269,7 @@ pub struct PrivateMessageResponse { pub private_message_view: PrivateMessageView, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetReportCount { pub community_id: Option, pub auth: Sensitive, @@ -279,7 +282,7 @@ pub struct GetReportCountResponse { pub post_reports: i64, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetUnreadCount { pub auth: Sensitive, } @@ -291,7 +294,7 @@ pub struct GetUnreadCountResponse { pub private_messages: i64, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone, Default)] pub struct VerifyEmail { pub token: String, } diff --git a/crates/api_common/src/post.rs b/crates/api_common/src/post.rs index afab5e30..38aceed9 100644 --- a/crates/api_common/src/post.rs +++ b/crates/api_common/src/post.rs @@ -1,11 +1,15 @@ use crate::sensitive::Sensitive; -use lemmy_db_schema::newtypes::{CommunityId, PostId, PostReportId}; +use lemmy_db_schema::{ + newtypes::{CommunityId, PostId, PostReportId}, + ListingType, + SortType, +}; use lemmy_db_views::structs::{CommentView, PostReportView, PostView}; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView}; use serde::{Deserialize, Serialize}; use url::Url; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct CreatePost { pub name: String, pub community_id: CommunityId, @@ -21,13 +25,13 @@ pub struct PostResponse { pub post_view: PostView, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetPost { pub id: PostId, pub auth: Option>, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetPostResponse { pub post_view: PostView, pub community_view: CommunityView, @@ -36,10 +40,10 @@ pub struct GetPostResponse { pub online: usize, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone, Default)] pub struct GetPosts { - pub type_: Option, - pub sort: Option, + pub type_: Option, + pub sort: Option, pub page: Option, pub limit: Option, pub community_id: Option, @@ -48,19 +52,19 @@ pub struct GetPosts { pub auth: Option>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct GetPostsResponse { pub posts: Vec, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct CreatePostLike { pub post_id: PostId, pub score: i16, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct EditPost { pub post_id: PostId, pub name: Option, @@ -70,14 +74,14 @@ pub struct EditPost { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct DeletePost { pub post_id: PostId, pub deleted: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct RemovePost { pub post_id: PostId, pub removed: bool, @@ -85,35 +89,35 @@ pub struct RemovePost { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct MarkPostAsRead { pub post_id: PostId, pub read: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct LockPost { pub post_id: PostId, pub locked: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct StickyPost { pub post_id: PostId, pub stickied: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct SavePost { pub post_id: PostId, pub save: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct CreatePostReport { pub post_id: PostId, pub reason: String, @@ -125,14 +129,14 @@ pub struct PostReportResponse { pub post_report_view: PostReportView, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct ResolvePostReport { pub report_id: PostReportId, pub resolved: bool, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct ListPostReports { pub page: Option, pub limit: Option, @@ -143,22 +147,22 @@ pub struct ListPostReports { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct ListPostReportsResponse { pub post_reports: Vec, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetSiteMetadata { pub url: Url, } -#[derive(Serialize, Deserialize, Clone, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetSiteMetadataResponse { pub metadata: SiteMetadata, } -#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)] +#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)] pub struct SiteMetadata { pub title: Option, pub description: Option, diff --git a/crates/api_common/src/sensitive.rs b/crates/api_common/src/sensitive.rs index 7713bc82..419e5ef6 100644 --- a/crates/api_common/src/sensitive.rs +++ b/crates/api_common/src/sensitive.rs @@ -4,7 +4,7 @@ use std::{ ops::{Deref, DerefMut}, }; -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize, Default)] #[serde(transparent)] pub struct Sensitive(T); diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index da17eb05..99c7b4e8 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -1,5 +1,10 @@ use crate::sensitive::Sensitive; -use lemmy_db_schema::newtypes::{CommunityId, PersonId}; +use lemmy_db_schema::{ + newtypes::{CommunityId, PersonId}, + ListingType, + SearchType, + SortType, +}; use lemmy_db_views::structs::{ CommentView, LocalUserSettingsView, @@ -30,21 +35,21 @@ use lemmy_db_views_moderator::structs::{ }; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct Search { pub q: String, pub community_id: Option, pub community_name: Option, pub creator_id: Option, - pub type_: Option, - pub sort: Option, - pub listing_type: Option, + pub type_: Option, + pub sort: Option, + pub listing_type: Option, pub page: Option, pub limit: Option, pub auth: Option>, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct SearchResponse { pub type_: String, pub comments: Vec, @@ -53,7 +58,7 @@ pub struct SearchResponse { pub users: Vec, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct ResolveObject { pub q: String, pub auth: Option>, @@ -67,7 +72,7 @@ pub struct ResolveObjectResponse { pub person: Option, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetModlog { pub mod_person_id: Option, pub community_id: Option, @@ -76,7 +81,7 @@ pub struct GetModlog { pub auth: Option>, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetModlogResponse { pub removed_posts: Vec, pub locked_posts: Vec, @@ -91,7 +96,7 @@ pub struct GetModlogResponse { pub hidden_communities: Vec, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct CreateSite { pub name: String, pub sidebar: Option, @@ -111,7 +116,7 @@ pub struct CreateSite { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct EditSite { pub name: Option, pub sidebar: Option, @@ -131,7 +136,7 @@ pub struct EditSite { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct GetSite { pub auth: Option>, } @@ -141,7 +146,7 @@ pub struct SiteResponse { pub site_view: SiteView, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetSiteResponse { pub site_view: Option, // Because the site might not be set up yet pub admins: Vec, @@ -151,7 +156,7 @@ pub struct GetSiteResponse { pub federated_instances: Option, // Federation may be disabled } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct MyUserInfo { pub local_user_view: LocalUserSettingsView, pub follows: Vec, @@ -160,35 +165,35 @@ pub struct MyUserInfo { pub person_blocks: Vec, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct LeaveAdmin { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetSiteConfig { pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetSiteConfigResponse { pub config_hjson: String, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct SaveSiteConfig { pub config_hjson: String, pub auth: Sensitive, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct FederatedInstances { pub linked: Vec, pub allowed: Option>, pub blocked: Option>, } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct ListRegistrationApplications { /// Only shows the unread applications (IE those without an admin actor) pub unread_only: Option, @@ -197,12 +202,12 @@ pub struct ListRegistrationApplications { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct ListRegistrationApplicationsResponse { pub registration_applications: Vec, } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct ApproveRegistrationApplication { pub id: i32, pub approve: bool, @@ -210,17 +215,17 @@ pub struct ApproveRegistrationApplication { pub auth: String, } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct RegistrationApplicationResponse { pub registration_application: RegistrationApplicationView, } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetUnreadRegistrationApplicationCount { pub auth: String, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetUnreadRegistrationApplicationCountResponse { pub registration_applications: i64, } diff --git a/crates/api_common/src/websocket.rs b/crates/api_common/src/websocket.rs index 80729fcc..23f7b2bc 100644 --- a/crates/api_common/src/websocket.rs +++ b/crates/api_common/src/websocket.rs @@ -2,7 +2,7 @@ use crate::sensitive::Sensitive; use lemmy_db_schema::newtypes::{CommunityId, PostId}; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct UserJoin { pub auth: Sensitive, } @@ -12,7 +12,7 @@ pub struct UserJoinResponse { pub joined: bool, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct CommunityJoin { pub community_id: CommunityId, } @@ -22,7 +22,7 @@ pub struct CommunityJoinResponse { pub joined: bool, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct ModJoin { pub community_id: CommunityId, } @@ -32,7 +32,7 @@ pub struct ModJoinResponse { pub joined: bool, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct PostJoin { pub post_id: PostId, } diff --git a/crates/api_crud/src/comment/list.rs b/crates/api_crud/src/comment/list.rs index ab9e25f1..f9c37de4 100644 --- a/crates/api_crud/src/comment/list.rs +++ b/crates/api_crud/src/comment/list.rs @@ -5,11 +5,7 @@ use lemmy_api_common::{ utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt}, }; use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity}; -use lemmy_db_schema::{ - source::community::Community, - traits::DeleteableOrRemoveable, - utils::{from_opt_str_to_opt_enum, ListingType, SortType}, -}; +use lemmy_db_schema::{source::community::Community, traits::DeleteableOrRemoveable}; use lemmy_db_views::comment_view::CommentQueryBuilder; use lemmy_utils::{ConnectionId, LemmyError}; use lemmy_websocket::LemmyContext; @@ -36,9 +32,6 @@ impl PerformCrud for GetComments { .map(|t| t.local_user.show_bot_accounts); let person_id = local_user_view.map(|u| u.person.id); - let sort: Option = from_opt_str_to_opt_enum(&data.sort); - let listing_type: Option = from_opt_str_to_opt_enum(&data.type_); - let community_id = data.community_id; let community_actor_id = if let Some(name) = &data.community_name { resolve_actor_identifier::(name, context) @@ -48,6 +41,8 @@ impl PerformCrud for GetComments { } else { None }; + let sort = data.sort; + let listing_type = data.type_; let saved_only = data.saved_only; let page = data.page; let limit = data.limit; diff --git a/crates/api_crud/src/community/list.rs b/crates/api_crud/src/community/list.rs index fac41c66..af41b83e 100644 --- a/crates/api_crud/src/community/list.rs +++ b/crates/api_crud/src/community/list.rs @@ -4,10 +4,7 @@ use lemmy_api_common::{ community::{ListCommunities, ListCommunitiesResponse}, utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt}, }; -use lemmy_db_schema::{ - traits::DeleteableOrRemoveable, - utils::{from_opt_str_to_opt_enum, ListingType, SortType}, -}; +use lemmy_db_schema::traits::DeleteableOrRemoveable; use lemmy_db_views_actor::community_view::CommunityQueryBuilder; use lemmy_utils::{ConnectionId, LemmyError}; use lemmy_websocket::LemmyContext; @@ -37,9 +34,8 @@ impl PerformCrud for ListCommunities { None => false, }; - let sort: Option = from_opt_str_to_opt_enum(&data.sort); - let listing_type: Option = from_opt_str_to_opt_enum(&data.type_); - + let sort = data.sort; + let listing_type = data.type_; let page = data.page; let limit = data.limit; let mut communities = blocking(context.pool(), move |conn| { diff --git a/crates/api_crud/src/post/list.rs b/crates/api_crud/src/post/list.rs index 4b871e54..574efeba 100644 --- a/crates/api_crud/src/post/list.rs +++ b/crates/api_crud/src/post/list.rs @@ -8,7 +8,7 @@ use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubComm use lemmy_db_schema::{ source::{community::Community, site::Site}, traits::DeleteableOrRemoveable, - utils::{from_opt_str_to_opt_enum, ListingType, SortType}, + ListingType, }; use lemmy_db_views::post_view::PostQueryBuilder; use lemmy_utils::{ConnectionId, LemmyError}; @@ -42,15 +42,14 @@ impl PerformCrud for GetPosts { .as_ref() .map(|t| t.local_user.show_read_posts); - let sort: Option = from_opt_str_to_opt_enum(&data.sort); - let listing_type: ListingType = match from_opt_str_to_opt_enum(&data.type_) { + let sort = data.sort; + let listing_type: ListingType = match data.type_ { Some(l) => l, None => { let site = blocking(context.pool(), Site::read_local_site).await??; ListingType::from_str(&site.default_post_listing_type)? } }; - let page = data.page; let limit = data.limit; let community_id = data.community_id; diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index ace19fd7..d0c37bea 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -16,7 +16,8 @@ use lemmy_db_schema::{ site::{Site, SiteForm}, }, traits::Crud, - utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now, ListingType}, + utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now}, + ListingType, }; use lemmy_db_views::structs::SiteView; use lemmy_utils::{utils::check_slurs_opt, ConnectionId, LemmyError}; diff --git a/crates/api_crud/src/user/read.rs b/crates/api_crud/src/user/read.rs index 4b54430d..e00f6027 100644 --- a/crates/api_crud/src/user/read.rs +++ b/crates/api_crud/src/user/read.rs @@ -5,10 +5,7 @@ use lemmy_api_common::{ utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt}, }; use lemmy_apub::{fetcher::resolve_actor_identifier, objects::person::ApubPerson}; -use lemmy_db_schema::{ - source::person::Person, - utils::{from_opt_str_to_opt_enum, SortType}, -}; +use lemmy_db_schema::source::person::Person; use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder}; use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonViewSafe}; use lemmy_utils::{ConnectionId, LemmyError}; @@ -39,8 +36,6 @@ impl PerformCrud for GetPersonDetails { .as_ref() .map(|t| t.local_user.show_read_posts); - let sort: Option = from_opt_str_to_opt_enum(&data.sort); - let person_details_id = match data.person_id { Some(id) => id, None => { @@ -66,6 +61,7 @@ impl PerformCrud for GetPersonDetails { }) .await??; + let sort = data.sort; let page = data.page; let limit = data.limit; let saved_only = data.saved_only; diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index b2e40ed8..eae82109 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -14,12 +14,14 @@ doctest = false [features] full = ["diesel", "diesel-derive-newtype", "diesel_migrations", "bcrypt", "lemmy_utils", - "lemmy_apub_lib", "strum", "strum_macros", "sha2", "regex", "once_cell", "serde_json"] + "lemmy_apub_lib", "sha2", "regex", "once_cell", "serde_json"] [dependencies] chrono = { version = "0.4.19", features = ["serde"], default-features = false } serde = { version = "1.0.136", features = ["derive"] } url = { version = "2.2.2", features = ["serde"] } +strum = "0.24.0" +strum_macros = "0.24.0" serde_json = { version = "1.0.79", features = ["preserve_order"], optional = true } lemmy_apub_lib = { version = "=0.16.3", path = "../apub_lib", optional = true } lemmy_utils = { version = "=0.16.3", path = "../utils", optional = true } @@ -27,8 +29,6 @@ bcrypt = { version = "0.12.1", optional = true } diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"], optional = true } diesel-derive-newtype = { version = "0.1.2", optional = true } diesel_migrations = { version = "1.4.0", optional = true } -strum = { version = "0.24.0", optional = true } -strum_macros = { version = "0.24.0", optional = true } sha2 = { version = "0.10.2", optional = true } regex = { version = "1.5.5", optional = true } once_cell = { version = "1.10.0", optional = true } diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index e6dee199..5c63f393 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -1,8 +1,5 @@ #[cfg(feature = "full")] #[macro_use] -extern crate strum_macros; -#[cfg(feature = "full")] -#[macro_use] extern crate diesel; #[cfg(feature = "full")] #[macro_use] @@ -24,3 +21,38 @@ pub mod source; pub mod traits; #[cfg(feature = "full")] pub mod utils; + +use serde::{Deserialize, Serialize}; +use strum_macros::{Display, EnumString}; + +#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)] +pub enum SortType { + Active, + Hot, + New, + TopDay, + TopWeek, + TopMonth, + TopYear, + TopAll, + MostComments, + NewComments, +} + +#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] +pub enum ListingType { + All, + Local, + Subscribed, + Community, +} + +#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)] +pub enum SearchType { + All, + Comments, + Posts, + Communities, + Users, + Url, +} diff --git a/crates/db_schema/src/newtypes.rs b/crates/db_schema/src/newtypes.rs index 946007a3..1e0ecf2b 100644 --- a/crates/db_schema/src/newtypes.rs +++ b/crates/db_schema/src/newtypes.rs @@ -20,7 +20,7 @@ impl fmt::Display for PostId { #[cfg_attr(feature = "full", derive(DieselNewType))] pub struct PersonId(pub i32); -#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] pub struct CommentId(pub i32); @@ -38,7 +38,7 @@ pub struct CommunityId(pub i32); #[cfg_attr(feature = "full", derive(DieselNewType))] pub struct LocalUserId(pub i32); -#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] pub struct PrivateMessageId(i32); @@ -48,23 +48,23 @@ impl fmt::Display for PrivateMessageId { } } -#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] pub struct PersonMentionId(i32); -#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] pub struct PersonBlockId(i32); -#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] pub struct CommunityBlockId(i32); -#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] pub struct CommentReportId(i32); -#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)] #[cfg_attr(feature = "full", derive(DieselNewType))] pub struct PostReportId(i32); diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 58543057..09c5ecdd 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -12,7 +12,6 @@ use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject}; use lemmy_utils::LemmyError; use once_cell::sync::Lazy; use regex::Regex; -use serde::{Deserialize, Serialize}; use std::{env, env::VarError, io::Write}; use url::Url; @@ -22,42 +21,6 @@ pub fn get_database_url_from_env() -> Result { env::var("LEMMY_DATABASE_URL") } -#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)] -pub enum SortType { - Active, - Hot, - New, - TopDay, - TopWeek, - TopMonth, - TopYear, - TopAll, - MostComments, - NewComments, -} - -#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] -pub enum ListingType { - All, - Local, - Subscribed, - Community, -} - -#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)] -pub enum SearchType { - All, - Comments, - Posts, - Communities, - Users, - Url, -} - -pub fn from_opt_str_to_opt_enum(opt: &Option) -> Option { - opt.as_ref().and_then(|t| T::from_str(t).ok()) -} - pub fn fuzzy_search(q: &str) -> String { let replaced = q.replace('%', "\\%").replace('_', "\\_").replace(' ', "%"); format!("%{}%", replaced) diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index c8b4d387..87ec3c07 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -26,7 +26,9 @@ use lemmy_db_schema::{ post::Post, }, traits::{MaybeOptional, ToSafe, ViewToVec}, - utils::{functions::hot_rank, fuzzy_search, limit_and_offset, ListingType, SortType}, + utils::{functions::hot_rank, fuzzy_search, limit_and_offset}, + ListingType, + SortType, }; type CommentViewTuple = ( diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 2fac5ade..2fe6d216 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -23,7 +23,9 @@ use lemmy_db_schema::{ post::{Post, PostRead, PostSaved}, }, traits::{MaybeOptional, ToSafe, ViewToVec}, - utils::{functions::hot_rank, fuzzy_search, limit_and_offset, ListingType, SortType}, + utils::{functions::hot_rank, fuzzy_search, limit_and_offset}, + ListingType, + SortType, }; use tracing::debug; @@ -505,7 +507,9 @@ mod tests { post::*, }, traits::{Blockable, Crud, Likeable}, - utils::{establish_unpooled_connection, ListingType, SortType}, + utils::establish_unpooled_connection, + ListingType, + SortType, }; use serial_test::serial; diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index 637a2d90..e6f82812 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -9,7 +9,9 @@ use lemmy_db_schema::{ community_block::CommunityBlock, }, traits::{MaybeOptional, ToSafe, ViewToVec}, - utils::{functions::hot_rank, fuzzy_search, limit_and_offset, ListingType, SortType}, + utils::{functions::hot_rank, fuzzy_search, limit_and_offset}, + ListingType, + SortType, }; type CommunityViewTuple = ( diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 59e90113..43c7f594 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -26,7 +26,8 @@ use lemmy_db_schema::{ post::Post, }, traits::{MaybeOptional, ToSafe, ViewToVec}, - utils::{functions::hot_rank, limit_and_offset, SortType}, + utils::{functions::hot_rank, limit_and_offset}, + SortType, }; type PersonMentionViewTuple = ( diff --git a/crates/db_views_actor/src/person_view.rs b/crates/db_views_actor/src/person_view.rs index 1849f80b..83886a19 100644 --- a/crates/db_views_actor/src/person_view.rs +++ b/crates/db_views_actor/src/person_view.rs @@ -6,7 +6,8 @@ use lemmy_db_schema::{ schema::{person, person_aggregates}, source::person::{Person, PersonSafe}, traits::{MaybeOptional, ToSafe, ViewToVec}, - utils::{fuzzy_search, limit_and_offset, SortType}, + utils::{fuzzy_search, limit_and_offset}, + SortType, }; type PersonViewSafeTuple = (PersonSafe, PersonAggregates); diff --git a/crates/routes/src/feeds.rs b/crates/routes/src/feeds.rs index 1bcfc6c3..878c68b9 100644 --- a/crates/routes/src/feeds.rs +++ b/crates/routes/src/feeds.rs @@ -7,7 +7,8 @@ use lemmy_db_schema::{ newtypes::LocalUserId, source::{community::Community, local_user::LocalUser, person::Person}, traits::{ApubActor, Crud}, - utils::{ListingType, SortType}, + ListingType, + SortType, }; use lemmy_db_views::{ comment_view::CommentQueryBuilder,