Add delete tagline endpoint

This commit is contained in:
Freakazoid182 2024-04-03 22:42:25 +02:00
parent ab938062e4
commit e536d39c2b
5 changed files with 42 additions and 4 deletions

View file

@ -21,6 +21,14 @@ pub struct UpdateTagline {
pub content: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Delete a tagline
pub struct DeleteTagline {
pub id: TaglineId,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]

View file

@ -0,0 +1,25 @@
use activitypub_federation::config::Data;
use actix_web::web::Json;
use lemmy_api_common::{
context::LemmyContext,
tagline::DeleteTagline,
utils::is_admin,
SuccessResponse,
};
use lemmy_db_schema::source::tagline::Tagline;
use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError;
#[tracing::instrument(skip(context))]
pub async fn delete_tagline(
data: Json<DeleteTagline>,
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> {
// Make sure user is an admin
is_admin(&local_user_view)?;
Tagline::delete(&mut context.pool(), data.id).await?;
Ok(Json(SuccessResponse::default()))
}

View file

@ -1,3 +1,4 @@
pub mod create;
pub mod list;
pub mod update;
pub mod delete;

View file

@ -41,10 +41,7 @@ impl Tagline {
}
}
pub async fn create(
pool: &mut DbPool<'_>,
form: &TaglineInsertForm,
) -> Result<Self, Error> {
pub async fn create(pool: &mut DbPool<'_>, form: &TaglineInsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(tagline)
.values(form)
@ -64,6 +61,11 @@ impl Tagline {
.await
}
pub async fn delete(pool: &mut DbPool<'_>, tagline_id: TaglineId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(tagline.find(tagline_id)).execute(conn).await
}
async fn clear(conn: &mut AsyncPgConnection) -> Result<usize, Error> {
diesel::delete(tagline).execute(conn).await
}

View file

@ -125,6 +125,7 @@ use lemmy_api_crud::{
site::{create::create_site, read::get_site, update::update_site},
tagline::{
create::create_tagline,
delete::delete_tagline,
list::list_taglines,
update::update_tagline
},
@ -375,6 +376,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
.wrap(rate_limit.message())
.route("/", web::post().to(create_tagline))
.route("/", web::put().to(update_tagline))
.route("/delete", web::post().to(delete_tagline))
.route("/list", web::get().to(list_taglines)),
),
);