Adding taglines to SiteResponse. Fixes #2925 (#2926)

* Adding taglines to SiteResponse. Fixes #2925

* Fixing CI line.
This commit is contained in:
Dessalines 2023-06-06 08:59:34 -04:00 committed by GitHub
parent bb625c3671
commit ef1aa18fd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 11 deletions

View file

@ -263,7 +263,7 @@ pipeline:
image: alpine:3 image: alpine:3
commands: commands:
- apk add curl - apk add curl
- "curl -d'Drone build failed: ${CI_BUILD_LINK}' ntfy.sh/lemmy_drone_ci" - "curl -d'Lemmy CI build failed: ${CI_BUILD_LINK}' ntfy.sh/lemmy_drone_ci"
when: when:
status: [failure] status: [failure]

View file

@ -283,6 +283,7 @@ pub struct GetSite {
/// The response for a site. /// The response for a site.
pub struct SiteResponse { pub struct SiteResponse {
pub site_view: SiteView, pub site_view: SiteView,
pub taglines: Vec<Tagline>,
} }
#[skip_serializing_none] #[skip_serializing_none]

View file

@ -19,6 +19,7 @@ use lemmy_db_schema::{
local_site::{LocalSite, LocalSiteUpdateForm}, local_site::{LocalSite, LocalSiteUpdateForm},
local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitUpdateForm}, local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitUpdateForm},
site::{Site, SiteUpdateForm}, site::{Site, SiteUpdateForm},
tagline::Tagline,
}, },
traits::Crud, traits::Crud,
utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now}, utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now},
@ -146,6 +147,9 @@ impl PerformCrud for CreateSite {
let site_view = SiteView::read_local(context.pool()).await?; let site_view = SiteView::read_local(context.pool()).await?;
let new_taglines = data.taglines.clone();
let taglines = Tagline::replace(context.pool(), local_site.id, new_taglines).await?;
let rate_limit_config = let rate_limit_config =
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit); local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
context context
@ -153,6 +157,9 @@ impl PerformCrud for CreateSite {
.send(rate_limit_config) .send(rate_limit_config)
.await?; .await?;
Ok(SiteResponse { site_view }) Ok(SiteResponse {
site_view,
taglines,
})
} }
} }

View file

@ -182,8 +182,8 @@ impl PerformCrud for EditSite {
.map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_email_verified"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_email_verified"))?;
} }
let taglines = data.taglines.clone(); let new_taglines = data.taglines.clone();
Tagline::replace(context.pool(), local_site.id, taglines).await?; let taglines = Tagline::replace(context.pool(), local_site.id, new_taglines).await?;
let site_view = SiteView::read_local(context.pool()).await?; let site_view = SiteView::read_local(context.pool()).await?;
@ -194,7 +194,10 @@ impl PerformCrud for EditSite {
.send(rate_limit_config) .send(rate_limit_config)
.await?; .await?;
let res = SiteResponse { site_view }; let res = SiteResponse {
site_view,
taglines,
};
context.send_all_ws_message(&UserOperationCrud::EditSite, &res, websocket_id)?; context.send_all_ws_message(&UserOperationCrud::EditSite, &res, websocket_id)?;

View file

@ -12,9 +12,9 @@ impl Tagline {
pool: &DbPool, pool: &DbPool,
for_local_site_id: LocalSiteId, for_local_site_id: LocalSiteId,
list_content: Option<Vec<String>>, list_content: Option<Vec<String>>,
) -> Result<(), Error> { ) -> Result<Vec<Self>, Error> {
if let Some(list) = list_content {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
if let Some(list) = list_content {
conn conn
.build_transaction() .build_transaction()
.run(|conn| { .run(|conn| {
@ -32,23 +32,30 @@ impl Tagline {
.get_result::<Self>(conn) .get_result::<Self>(conn)
.await?; .await?;
} }
Ok(()) Self::get_all_conn(conn, for_local_site_id).await
}) as _ }) as _
}) })
.await .await
} else { } else {
Ok(()) Self::get_all_conn(conn, for_local_site_id).await
} }
} }
async fn clear(conn: &mut AsyncPgConnection) -> Result<usize, Error> { async fn clear(conn: &mut AsyncPgConnection) -> Result<usize, Error> {
diesel::delete(tagline).execute(conn).await diesel::delete(tagline).execute(conn).await
} }
pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; async fn get_all_conn(
conn: &mut AsyncPgConnection,
for_local_site_id: LocalSiteId,
) -> Result<Vec<Self>, Error> {
tagline tagline
.filter(local_site_id.eq(for_local_site_id)) .filter(local_site_id.eq(for_local_site_id))
.get_results::<Self>(conn) .get_results::<Self>(conn)
.await .await
} }
pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
Self::get_all_conn(conn, for_local_site_id).await
}
} }