mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-20 02:38:05 +00:00
Get random tagline on site requets
This commit is contained in:
parent
2b1fdf106b
commit
f1b993f90e
|
@ -7,6 +7,7 @@ use lemmy_db_schema::{
|
|||
local_site_url_blocklist::LocalSiteUrlBlocklist,
|
||||
local_user::{LocalUser, LocalUserUpdateForm},
|
||||
moderator::{ModAdd, ModAddForm},
|
||||
tagline::Tagline,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
|
@ -60,6 +61,7 @@ pub async fn leave_admin(
|
|||
let all_languages = Language::read_all(&mut context.pool()).await?;
|
||||
let discussion_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
|
||||
let blocked_urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
|
||||
let tagline = Tagline::get_random(&mut context.pool(), site_view.local_site.id).await?;
|
||||
|
||||
Ok(Json(GetSiteResponse {
|
||||
site_view,
|
||||
|
@ -69,5 +71,6 @@ pub async fn leave_admin(
|
|||
all_languages,
|
||||
discussion_languages,
|
||||
blocked_urls,
|
||||
tagline,
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use lemmy_db_schema::{
|
|||
instance::Instance,
|
||||
language::Language,
|
||||
local_site_url_blocklist::LocalSiteUrlBlocklist,
|
||||
tagline::Tagline,
|
||||
},
|
||||
ListingType,
|
||||
ModlogActionType,
|
||||
|
@ -298,6 +299,7 @@ pub struct GetSiteResponse {
|
|||
pub my_user: Option<MyUserInfo>,
|
||||
pub all_languages: Vec<Language>,
|
||||
pub discussion_languages: Vec<LanguageId>,
|
||||
pub tagline: Option<Tagline>,
|
||||
pub blocked_urls: Vec<LocalSiteUrlBlocklist>,
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use lemmy_db_schema::source::{
|
|||
actor_language::{LocalUserLanguage, SiteLanguage},
|
||||
language::Language,
|
||||
local_site_url_blocklist::LocalSiteUrlBlocklist,
|
||||
tagline::Tagline,
|
||||
};
|
||||
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
||||
use lemmy_db_views_actor::structs::{
|
||||
|
@ -45,6 +46,7 @@ pub async fn get_site(
|
|||
let all_languages = Language::read_all(&mut context.pool()).await?;
|
||||
let discussion_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
|
||||
let blocked_urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
|
||||
let tagline = Tagline::get_random(&mut context.pool(), site_view.local_site.id).await?;
|
||||
Ok(GetSiteResponse {
|
||||
site_view,
|
||||
admins,
|
||||
|
@ -53,6 +55,7 @@ pub async fn get_site(
|
|||
all_languages,
|
||||
discussion_languages,
|
||||
blocked_urls,
|
||||
tagline,
|
||||
})
|
||||
})
|
||||
.await
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
source::tagline::{Tagline, TaglineInsertForm, TaglineUpdateForm},
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||
use diesel::{insert_into, result::Error, ExpressionMethods, OptionalExtension, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
||||
impl Tagline {
|
||||
|
@ -60,4 +60,19 @@ impl Tagline {
|
|||
.get_results::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_random(
|
||||
pool: &mut DbPool<'_>,
|
||||
for_local_site_id: LocalSiteId,
|
||||
) -> Result<Option<Self>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
sql_function!(fn random() -> Text);
|
||||
tagline
|
||||
.order(random())
|
||||
.limit(1)
|
||||
.filter(local_site_id.eq(for_local_site_id))
|
||||
.first::<Self>(conn)
|
||||
.await
|
||||
.optional()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue