mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-20 02:38:05 +00:00
Add tagline list route
This commit is contained in:
parent
fd275231bc
commit
b4a86157a5
|
@ -16,6 +16,7 @@ pub mod request;
|
|||
pub mod send_activity;
|
||||
pub mod sensitive;
|
||||
pub mod site;
|
||||
pub mod tagline;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod utils;
|
||||
|
||||
|
|
23
crates/api_common/src/tagline.rs
Normal file
23
crates/api_common/src/tagline.rs
Normal file
|
@ -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>,
|
||||
}
|
|
@ -4,4 +4,5 @@ pub mod custom_emoji;
|
|||
pub mod post;
|
||||
pub mod private_message;
|
||||
pub mod site;
|
||||
pub mod tagline;
|
||||
pub mod user;
|
||||
|
|
27
crates/api_crud/src/tagline/list.rs
Normal file
27
crates/api_crud/src/tagline/list.rs
Normal file
|
@ -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 }))
|
||||
}
|
1
crates/api_crud/src/tagline/mod.rs
Normal file
1
crates/api_crud/src/tagline/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod list;
|
|
@ -21,6 +21,8 @@ pub mod private_message_view;
|
|||
pub mod registration_application_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod site_view;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod tagline_view;
|
||||
pub mod structs;
|
||||
#[cfg(feature = "full")]
|
||||
pub mod vote_view;
|
||||
|
|
|
@ -18,7 +18,8 @@ use lemmy_db_schema::{
|
|||
private_message::PrivateMessage,
|
||||
private_message_report::PrivateMessageReport,
|
||||
registration_application::RegistrationApplication,
|
||||
site::Site,
|
||||
site::Site,
|
||||
tagline::Tagline,
|
||||
},
|
||||
SubscribedType,
|
||||
};
|
||||
|
@ -193,6 +194,15 @@ 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)))]
|
||||
|
|
39
crates/db_views/src/tagline_view.rs
Normal file
39
crates/db_views/src/tagline_view.rs
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -123,6 +123,7 @@ use lemmy_api_crud::{
|
|||
update::update_private_message,
|
||||
},
|
||||
site::{create::create_site, read::get_site, update::update_site},
|
||||
tagline::list::list_taglines,
|
||||
user::{create::register, delete::delete_account},
|
||||
};
|
||||
use lemmy_apub::api::{
|
||||
|
@ -364,7 +365,12 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
|||
.route("", web::put().to(update_custom_emoji))
|
||||
.route("/delete", web::post().to(delete_custom_emoji))
|
||||
.route("/list", web::get().to(list_custom_emojis)),
|
||||
),
|
||||
)
|
||||
.service(
|
||||
web::scope("/tagline")
|
||||
.wrap(rate_limit.message())
|
||||
.route("/list", web::get().to(list_taglines))
|
||||
)
|
||||
);
|
||||
cfg.service(
|
||||
web::scope("/sitemap.xml")
|
||||
|
|
Loading…
Reference in a new issue