From: Dessalines Date: Tue, 6 Jun 2023 12:59:34 +0000 (-0400) Subject: Adding taglines to SiteResponse. Fixes #2925 (#2926) X-Git-Url: http://these/git/ui/assets/favicon.svg?a=commitdiff_plain;h=ef1aa18fd20cc03d492a81cb70cc75cf3281649f;p=lemmy.git Adding taglines to SiteResponse. Fixes #2925 (#2926) * Adding taglines to SiteResponse. Fixes #2925 * Fixing CI line. --- diff --git a/.woodpecker.yml b/.woodpecker.yml index c9a1f3d7..918a26af 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -263,7 +263,7 @@ pipeline: image: alpine:3 commands: - 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: status: [failure] diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 2d3ebbe0..2ba6611c 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -283,6 +283,7 @@ pub struct GetSite { /// The response for a site. pub struct SiteResponse { pub site_view: SiteView, + pub taglines: Vec, } #[skip_serializing_none] diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index 0f3e8c56..05b41e35 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -19,6 +19,7 @@ use lemmy_db_schema::{ local_site::{LocalSite, LocalSiteUpdateForm}, local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitUpdateForm}, site::{Site, SiteUpdateForm}, + tagline::Tagline, }, traits::Crud, 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 new_taglines = data.taglines.clone(); + let taglines = Tagline::replace(context.pool(), local_site.id, new_taglines).await?; + let rate_limit_config = local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit); context @@ -153,6 +157,9 @@ impl PerformCrud for CreateSite { .send(rate_limit_config) .await?; - Ok(SiteResponse { site_view }) + Ok(SiteResponse { + site_view, + taglines, + }) } } diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index 693be690..31c4e483 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -182,8 +182,8 @@ impl PerformCrud for EditSite { .map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_email_verified"))?; } - let taglines = data.taglines.clone(); - Tagline::replace(context.pool(), local_site.id, taglines).await?; + let new_taglines = data.taglines.clone(); + let taglines = Tagline::replace(context.pool(), local_site.id, new_taglines).await?; let site_view = SiteView::read_local(context.pool()).await?; @@ -194,7 +194,10 @@ impl PerformCrud for EditSite { .send(rate_limit_config) .await?; - let res = SiteResponse { site_view }; + let res = SiteResponse { + site_view, + taglines, + }; context.send_all_ws_message(&UserOperationCrud::EditSite, &res, websocket_id)?; diff --git a/crates/db_schema/src/impls/tagline.rs b/crates/db_schema/src/impls/tagline.rs index a4100523..ec985a3c 100644 --- a/crates/db_schema/src/impls/tagline.rs +++ b/crates/db_schema/src/impls/tagline.rs @@ -12,9 +12,9 @@ impl Tagline { pool: &DbPool, for_local_site_id: LocalSiteId, list_content: Option>, - ) -> Result<(), Error> { + ) -> Result, Error> { + let conn = &mut get_conn(pool).await?; if let Some(list) = list_content { - let conn = &mut get_conn(pool).await?; conn .build_transaction() .run(|conn| { @@ -32,23 +32,30 @@ impl Tagline { .get_result::(conn) .await?; } - Ok(()) + Self::get_all_conn(conn, for_local_site_id).await }) as _ }) .await } else { - Ok(()) + Self::get_all_conn(conn, for_local_site_id).await } } async fn clear(conn: &mut AsyncPgConnection) -> Result { diesel::delete(tagline).execute(conn).await } - pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result, Error> { - let conn = &mut get_conn(pool).await?; + + async fn get_all_conn( + conn: &mut AsyncPgConnection, + for_local_site_id: LocalSiteId, + ) -> Result, Error> { tagline .filter(local_site_id.eq(for_local_site_id)) .get_results::(conn) .await } + pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result, Error> { + let conn = &mut get_conn(pool).await?; + Self::get_all_conn(conn, for_local_site_id).await + } }