mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-02 13:39:21 +00:00
Remove unecessary TaglineView
This commit is contained in:
parent
10a8f01fad
commit
17e2834e1b
|
@ -1,4 +1,4 @@
|
||||||
use lemmy_db_views::structs::TaglineView;
|
use lemmy_db_schema::source::tagline::Tagline;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
@ -9,7 +9,7 @@ use ts_rs::TS;
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
/// A response for custom emojis.
|
/// A response for custom emojis.
|
||||||
pub struct ListTaglinesResponse {
|
pub struct ListTaglinesResponse {
|
||||||
pub taglines: Vec<TaglineView>,
|
pub taglines: Vec<Tagline>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
|
|
|
@ -3,7 +3,8 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
tagline::{ListTaglines, ListTaglinesResponse},
|
tagline::{ListTaglines, ListTaglinesResponse},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{LocalUserView, SiteView, TaglineView};
|
use lemmy_db_schema::source::tagline::Tagline;
|
||||||
|
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
|
@ -13,14 +14,13 @@ pub async fn list_taglines(
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<Json<ListTaglinesResponse>, LemmyError> {
|
) -> Result<Json<ListTaglinesResponse>, LemmyError> {
|
||||||
let local_site = SiteView::read_local(&mut context.pool()).await?;
|
let local_site = SiteView::read_local(&mut context.pool()).await?;
|
||||||
let taglines = TaglineView::list(
|
let taglines = Tagline::list(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
local_site.local_site.id,
|
local_site.local_site.id,
|
||||||
data.page,
|
data.page,
|
||||||
data.limit,
|
data.limit,
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to construct taglines response: {e}"))?;
|
|
||||||
|
|
||||||
Ok(Json(ListTaglinesResponse { taglines }))
|
Ok(Json(ListTaglinesResponse { taglines }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::LocalSiteId,
|
newtypes::LocalSiteId,
|
||||||
schema::tagline::dsl::{local_site_id, tagline},
|
schema::tagline::dsl::{local_site_id, published, tagline},
|
||||||
source::tagline::{Tagline, TaglineForm},
|
source::tagline::{Tagline, TaglineForm},
|
||||||
utils::{get_conn, DbPool},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
||||||
|
@ -55,4 +55,21 @@ impl Tagline {
|
||||||
.get_results::<Self>(conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn list(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
for_local_site_id: LocalSiteId,
|
||||||
|
page: Option<i64>,
|
||||||
|
limit: Option<i64>,
|
||||||
|
) -> Result<Vec<Self>, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
let (limit, offset) = limit_and_offset(page, limit)?;
|
||||||
|
tagline
|
||||||
|
.order(published.desc())
|
||||||
|
.offset(offset)
|
||||||
|
.limit(limit)
|
||||||
|
.filter(local_site_id.eq(for_local_site_id))
|
||||||
|
.get_results::<Self>(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,4 @@ pub mod registration_application_view;
|
||||||
pub mod site_view;
|
pub mod site_view;
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod tagline_view;
|
|
||||||
#[cfg(feature = "full")]
|
|
||||||
pub mod vote_view;
|
pub mod vote_view;
|
||||||
|
|
|
@ -19,7 +19,6 @@ use lemmy_db_schema::{
|
||||||
private_message_report::PrivateMessageReport,
|
private_message_report::PrivateMessageReport,
|
||||||
registration_application::RegistrationApplication,
|
registration_application::RegistrationApplication,
|
||||||
site::Site,
|
site::Site,
|
||||||
tagline::Tagline,
|
|
||||||
},
|
},
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
};
|
};
|
||||||
|
@ -194,15 +193,6 @@ pub struct SiteView {
|
||||||
pub counts: SiteAggregates,
|
pub counts: SiteAggregates,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
|
||||||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// A custom emoji view.
|
|
||||||
pub struct TaglineView {
|
|
||||||
pub tagline: Tagline,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
||||||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
use crate::structs::TaglineView;
|
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
|
||||||
newtypes::LocalSiteId,
|
|
||||||
schema::tagline,
|
|
||||||
source::tagline::Tagline,
|
|
||||||
utils::{get_conn, limit_and_offset, DbPool},
|
|
||||||
};
|
|
||||||
|
|
||||||
impl TaglineView {
|
|
||||||
pub async fn list(
|
|
||||||
pool: &mut DbPool<'_>,
|
|
||||||
for_local_site_id: LocalSiteId,
|
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut get_conn(pool).await?;
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
|
||||||
let taglines = tagline::table
|
|
||||||
.filter(tagline::local_site_id.eq(for_local_site_id))
|
|
||||||
.order(tagline::id)
|
|
||||||
.select(tagline::all_columns)
|
|
||||||
.limit(limit)
|
|
||||||
.offset(offset)
|
|
||||||
.load::<Tagline>(conn)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let mut result = Vec::new();
|
|
||||||
for tagline in &taglines {
|
|
||||||
result.push(TaglineView {
|
|
||||||
tagline: tagline.clone(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(result)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue