mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-20 02:38:05 +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_with::skip_serializing_none;
|
||||
#[cfg(feature = "full")]
|
||||
|
@ -9,7 +9,7 @@ use ts_rs::TS;
|
|||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// A response for custom emojis.
|
||||
pub struct ListTaglinesResponse {
|
||||
pub taglines: Vec<TaglineView>,
|
||||
pub taglines: Vec<Tagline>,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
|
|
|
@ -3,7 +3,8 @@ use lemmy_api_common::{
|
|||
context::LemmyContext,
|
||||
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;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
|
@ -13,14 +14,13 @@ pub async fn list_taglines(
|
|||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<ListTaglinesResponse>, LemmyError> {
|
||||
let local_site = SiteView::read_local(&mut context.pool()).await?;
|
||||
let taglines = TaglineView::list(
|
||||
let taglines = Tagline::list(
|
||||
&mut context.pool(),
|
||||
local_site.local_site.id,
|
||||
data.page,
|
||||
data.limit,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to construct taglines response: {e}"))?;
|
||||
.await?;
|
||||
|
||||
Ok(Json(ListTaglinesResponse { taglines }))
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{
|
||||
newtypes::LocalSiteId,
|
||||
schema::tagline::dsl::{local_site_id, tagline},
|
||||
schema::tagline::dsl::{local_site_id, published, tagline},
|
||||
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_async::{AsyncPgConnection, RunQueryDsl};
|
||||
|
@ -55,4 +55,21 @@ impl Tagline {
|
|||
.get_results::<Self>(conn)
|
||||
.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 structs;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod tagline_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod vote_view;
|
||||
|
|
|
@ -19,7 +19,6 @@ use lemmy_db_schema::{
|
|||
private_message_report::PrivateMessageReport,
|
||||
registration_application::RegistrationApplication,
|
||||
site::Site,
|
||||
tagline::Tagline,
|
||||
},
|
||||
SubscribedType,
|
||||
};
|
||||
|
@ -194,15 +193,6 @@ pub struct SiteView {
|
|||
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)]
|
||||
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
||||
#[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