mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-25 19:01:03 +00:00
fix lints
This commit is contained in:
parent
c130bee420
commit
4d3b4ba283
4 changed files with 40 additions and 45 deletions
|
@ -1,10 +1,10 @@
|
|||
use crate::{
|
||||
newtypes::{CommunityId, CommunityPostTagId, DbUrl, PostId},
|
||||
schema::{community_post_tag, post_community_post_tag},
|
||||
};
|
||||
use crate::newtypes::{CommunityId, CommunityPostTagId, DbUrl, PostId};
|
||||
#[cfg(feature = "full")]
|
||||
use crate::schema::{community_post_tag, post_community_post_tag};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
#[cfg(feature = "full")]
|
||||
use ts_rs::TS;
|
||||
|
||||
/// A tag that can be assigned to a post within a community.
|
||||
|
|
29
crates/db_views/src/community_post_tags_view.rs
Normal file
29
crates/db_views/src/community_post_tags_view.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use crate::structs::PostCommunityPostTags;
|
||||
use diesel::{
|
||||
deserialize::FromSql,
|
||||
pg::{Pg, PgValue},
|
||||
serialize::ToSql,
|
||||
sql_types::{self, Nullable},
|
||||
};
|
||||
|
||||
impl FromSql<Nullable<sql_types::Json>, Pg> for PostCommunityPostTags {
|
||||
fn from_sql(bytes: PgValue) -> diesel::deserialize::Result<Self> {
|
||||
let value = <serde_json::Value as FromSql<sql_types::Json, Pg>>::from_sql(bytes)?;
|
||||
Ok(serde_json::from_value::<PostCommunityPostTags>(value)?)
|
||||
}
|
||||
fn from_nullable_sql(
|
||||
bytes: Option<<Pg as diesel::backend::Backend>::RawValue<'_>>,
|
||||
) -> diesel::deserialize::Result<Self> {
|
||||
match bytes {
|
||||
Some(bytes) => Self::from_sql(bytes),
|
||||
None => Ok(Self { tags: vec![] }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSql<Nullable<sql_types::Json>, Pg> for PostCommunityPostTags {
|
||||
fn to_sql(&self, out: &mut diesel::serialize::Output<Pg>) -> diesel::serialize::Result {
|
||||
let value = serde_json::to_value(self)?;
|
||||
<serde_json::Value as ToSql<sql_types::Json, Pg>>::to_sql(&value, &mut out.reborrow())
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@ pub mod comment_report_view;
|
|||
#[cfg(feature = "full")]
|
||||
pub mod comment_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod community_post_tags_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod custom_emoji_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod local_image_view;
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
#[cfg(feature = "full")]
|
||||
use diesel::Queryable;
|
||||
use diesel::{
|
||||
deserialize::{FromSql, FromSqlRow},
|
||||
expression::AsExpression,
|
||||
pg::{Pg, PgValue},
|
||||
serialize::ToSql,
|
||||
sql_types::{self, Nullable},
|
||||
};
|
||||
#[cfg(feature = "full")]
|
||||
use diesel::{deserialize::FromSqlRow, expression::AsExpression, sql_types};
|
||||
use lemmy_db_schema::{
|
||||
aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates},
|
||||
source::{
|
||||
|
@ -238,41 +233,10 @@ pub struct LocalImageView {
|
|||
pub person: Person,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
Debug,
|
||||
PartialEq,
|
||||
TS,
|
||||
FromSqlRow,
|
||||
AsExpression,
|
||||
Default,
|
||||
)]
|
||||
#[derive(Clone, serde::Serialize, serde::Deserialize, Debug, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "full", derive(TS, FromSqlRow, AsExpression))]
|
||||
#[serde(transparent)]
|
||||
#[diesel(sql_type = Nullable<sql_types::Json>)]
|
||||
#[cfg_attr(feature = "full", diesel(sql_type = Nullable<sql_types::Json>))]
|
||||
pub struct PostCommunityPostTags {
|
||||
pub tags: Vec<CommunityPostTag>,
|
||||
}
|
||||
|
||||
impl FromSql<Nullable<sql_types::Json>, Pg> for PostCommunityPostTags {
|
||||
fn from_sql(bytes: PgValue) -> diesel::deserialize::Result<Self> {
|
||||
let value = <serde_json::Value as FromSql<sql_types::Json, Pg>>::from_sql(bytes)?;
|
||||
Ok(serde_json::from_value::<PostCommunityPostTags>(value)?)
|
||||
}
|
||||
fn from_nullable_sql(
|
||||
bytes: Option<<Pg as diesel::backend::Backend>::RawValue<'_>>,
|
||||
) -> diesel::deserialize::Result<Self> {
|
||||
match bytes {
|
||||
Some(bytes) => Self::from_sql(bytes),
|
||||
None => Ok(Self { tags: vec![] }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSql<Nullable<sql_types::Json>, Pg> for PostCommunityPostTags {
|
||||
fn to_sql(&self, out: &mut diesel::serialize::Output<Pg>) -> diesel::serialize::Result {
|
||||
let value = serde_json::to_value(self)?;
|
||||
<serde_json::Value as ToSql<sql_types::Json, Pg>>::to_sql(&value, &mut out.reborrow())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue