mirror of https://github.com/LemmyNet/lemmy
Add update tagline endpoint
parent
a1a7e2ca33
commit
ab938062e4
@ -1,2 +1,3 @@
|
||||
pub mod create;
|
||||
pub mod list;
|
||||
pub mod update;
|
||||
|
@ -0,0 +1,34 @@
|
||||
use activitypub_federation::config::Data;
|
||||
use actix_web::web::Json;
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
tagline::{UpdateTagline, TaglineResponse},
|
||||
utils::is_admin,
|
||||
};
|
||||
use lemmy_db_schema::{source::{
|
||||
local_site::LocalSite,
|
||||
tagline::{Tagline, TaglineUpdateForm},
|
||||
}, utils::naive_now};
|
||||
use lemmy_db_views::structs::LocalUserView;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
pub async fn update_tagline(
|
||||
data: Json<UpdateTagline>,
|
||||
context: Data<LemmyContext>,
|
||||
local_user_view: LocalUserView,
|
||||
) -> Result<Json<TaglineResponse>, LemmyError> {
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
// Make sure user is an admin
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
let tagline_form = TaglineUpdateForm {
|
||||
local_site_id: local_site.id,
|
||||
content: data.content.to_string(),
|
||||
updated: Some(naive_now()),
|
||||
};
|
||||
|
||||
let tagline = Tagline::update(&mut context.pool(), data.id, &tagline_form).await?;
|
||||
|
||||
Ok(Json(TaglineResponse { tagline }))
|
||||
}
|
Loading…
Reference in New Issue