mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-20 02:38:05 +00:00
Add delete tagline endpoint
This commit is contained in:
parent
ab938062e4
commit
e536d39c2b
|
@ -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))]
|
||||
|
|
25
crates/api_crud/src/tagline/delete.rs
Normal file
25
crates/api_crud/src/tagline/delete.rs
Normal 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()))
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
pub mod create;
|
||||
pub mod list;
|
||||
pub mod update;
|
||||
pub mod delete;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)),
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue