mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-20 02:38:05 +00:00
Add category filter for custom emoji
This commit is contained in:
parent
17e2834e1b
commit
486c746eb9
|
@ -57,11 +57,12 @@ pub struct ListCustomEmojisResponse {
|
|||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "full", derive(TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// Fetches a list of registration applications.
|
||||
/// Fetches a list of custom emojis.
|
||||
pub struct ListCustomEmojis {
|
||||
pub page: Option<i64>,
|
||||
pub limit: Option<i64>,
|
||||
pub category: Option<String>,
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ pub async fn list_custom_emojis(
|
|||
let custom_emojis = CustomEmojiView::list(
|
||||
&mut context.pool(),
|
||||
local_site.local_site.id,
|
||||
&data.category,
|
||||
data.page,
|
||||
data.limit,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to construct custom emojis response: {e}"))?;
|
||||
.await?;
|
||||
|
||||
Ok(Json(ListCustomEmojisResponse { custom_emojis }))
|
||||
}
|
||||
|
|
|
@ -60,16 +60,25 @@ impl CustomEmojiView {
|
|||
pub async fn list(
|
||||
pool: &mut DbPool<'_>,
|
||||
for_local_site_id: LocalSiteId,
|
||||
category: &Option<String>,
|
||||
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 emojis = custom_emoji::table
|
||||
.filter(custom_emoji::local_site_id.eq(for_local_site_id))
|
||||
let mut query = custom_emoji::table
|
||||
.left_join(
|
||||
custom_emoji_keyword::table.on(custom_emoji_keyword::custom_emoji_id.eq(custom_emoji::id)),
|
||||
)
|
||||
.into_boxed();
|
||||
|
||||
query = query.filter(custom_emoji::local_site_id.eq(for_local_site_id));
|
||||
|
||||
if let Some(category) = category {
|
||||
query = query.filter(custom_emoji::category.eq(category))
|
||||
}
|
||||
|
||||
let emojis = query
|
||||
.order(custom_emoji::category)
|
||||
.then_order_by(custom_emoji::id)
|
||||
.select((
|
||||
|
|
Loading…
Reference in a new issue