mirror of https://github.com/LemmyNet/lemmy
Add tagline list route
parent
fd275231bc
commit
b4a86157a5
@ -0,0 +1,23 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use lemmy_db_views::structs::TaglineView;
|
||||
use serde_with::skip_serializing_none;
|
||||
#[cfg(feature = "full")]
|
||||
use ts_rs::TS;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// A response for custom emojis.
|
||||
pub struct ListTaglinesResponse {
|
||||
pub taglines: Vec<TaglineView>,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "full", derive(TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// Fetches a list of registration applications.
|
||||
pub struct ListTaglines {
|
||||
pub page: Option<i64>,
|
||||
pub limit: Option<i64>,
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
tagline::{ListTaglines, ListTaglinesResponse},
|
||||
};
|
||||
use lemmy_db_views::structs::{TaglineView, LocalUserView, SiteView};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
pub async fn list_taglines(
|
||||
data: Query<ListTaglines>,
|
||||
local_user_view: Option<LocalUserView>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<ListTaglinesResponse>, LemmyError> {
|
||||
|
||||
let local_site = SiteView::read_local(&mut context.pool()).await?;
|
||||
let taglines = TaglineView::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}"))?;
|
||||
|
||||
Ok(Json(ListTaglinesResponse { taglines }))
|
||||
}
|
@ -0,0 +1 @@
|
||||
pub mod list;
|
@ -0,0 +1,39 @@
|
||||
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 New Issue