mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 03:11:08 +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::{
|
use crate::newtypes::{CommunityId, CommunityPostTagId, DbUrl, PostId};
|
||||||
newtypes::{CommunityId, CommunityPostTagId, DbUrl, PostId},
|
#[cfg(feature = "full")]
|
||||||
schema::{community_post_tag, post_community_post_tag},
|
use crate::schema::{community_post_tag, post_community_post_tag};
|
||||||
};
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
use ts_rs::TS;
|
use ts_rs::TS;
|
||||||
|
|
||||||
/// A tag that can be assigned to a post within a community.
|
/// 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")]
|
#[cfg(feature = "full")]
|
||||||
pub mod comment_view;
|
pub mod comment_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
pub mod community_post_tags_view;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
pub mod custom_emoji_view;
|
pub mod custom_emoji_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod local_image_view;
|
pub mod local_image_view;
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use diesel::Queryable;
|
use diesel::Queryable;
|
||||||
use diesel::{
|
#[cfg(feature = "full")]
|
||||||
deserialize::{FromSql, FromSqlRow},
|
use diesel::{deserialize::FromSqlRow, expression::AsExpression, sql_types};
|
||||||
expression::AsExpression,
|
|
||||||
pg::{Pg, PgValue},
|
|
||||||
serialize::ToSql,
|
|
||||||
sql_types::{self, Nullable},
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates},
|
aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates},
|
||||||
source::{
|
source::{
|
||||||
|
@ -238,41 +233,10 @@ pub struct LocalImageView {
|
||||||
pub person: Person,
|
pub person: Person,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(Clone, serde::Serialize, serde::Deserialize, Debug, PartialEq, Default)]
|
||||||
Clone,
|
#[cfg_attr(feature = "full", derive(TS, FromSqlRow, AsExpression))]
|
||||||
serde::Serialize,
|
|
||||||
serde::Deserialize,
|
|
||||||
Debug,
|
|
||||||
PartialEq,
|
|
||||||
TS,
|
|
||||||
FromSqlRow,
|
|
||||||
AsExpression,
|
|
||||||
Default,
|
|
||||||
)]
|
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
#[diesel(sql_type = Nullable<sql_types::Json>)]
|
#[cfg_attr(feature = "full", diesel(sql_type = Nullable<sql_types::Json>))]
|
||||||
pub struct PostCommunityPostTags {
|
pub struct PostCommunityPostTags {
|
||||||
pub tags: Vec<CommunityPostTag>,
|
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