25 lines
701 B
Rust
25 lines
701 B
Rust
use actix_web::{web, HttpResponse, Responder};
|
|
use sqlx::PgPool;
|
|
|
|
use crate::{
|
|
endpoints::IdPath,
|
|
models::{Availabillity, User},
|
|
};
|
|
|
|
#[actix_web::delete("/availabillity/delete/{id}")]
|
|
pub async fn delete(
|
|
user: web::ReqData<User>,
|
|
pool: web::Data<PgPool>,
|
|
path: web::Path<IdPath>,
|
|
) -> impl Responder {
|
|
if let Ok(availabillity_in_db) = Availabillity::read_by_id(pool.get_ref(), path.id).await {
|
|
if availabillity_in_db.user_id == user.id {
|
|
if let Ok(_) = Availabillity::delete(pool.get_ref(), availabillity_in_db.id).await {
|
|
return HttpResponse::Ok().finish();
|
|
}
|
|
}
|
|
}
|
|
|
|
return HttpResponse::BadRequest().finish();
|
|
}
|