[BE] Delete register
This commit is contained in:
parent
28816fdba1
commit
a808c8d0a9
@ -7,6 +7,11 @@ pub fn options() -> Status {
|
||||
Status::Ok
|
||||
}
|
||||
|
||||
#[options("/register/<_r>")]
|
||||
pub fn options_delete(_r: i32) -> Status {
|
||||
Status::Ok
|
||||
}
|
||||
|
||||
#[post("/register/batch", format = "json", data = "<data>")]
|
||||
pub async fn insert_all(data: Json<Vec<RegisterCreate>>) -> Status {
|
||||
for register_create in data.iter() {
|
||||
@ -34,3 +39,17 @@ pub async fn get_by_dni(dni: i32) -> (Status, Json<Vec<Register>>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[delete("/register/<register_id>")]
|
||||
pub async fn delete(register_id: i32) -> Status {
|
||||
let res = Register::delete(register_id).await;
|
||||
|
||||
match res {
|
||||
Ok(_) => Status::Ok,
|
||||
Err(err) => {
|
||||
eprintln!("{:?}", err);
|
||||
|
||||
Status::InternalServerError
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ impl Fairing for Cors {
|
||||
response.set_header(Header::new("Access-Control-Allow-Origin", "*"));
|
||||
response.set_header(Header::new(
|
||||
"Access-Control-Allow-Methods",
|
||||
"POST, GET, OPTIONS",
|
||||
"POST, GET, DELETE, OPTIONS",
|
||||
));
|
||||
response.set_header(Header::new("Access-Control-Allow-Headers", "Content-Type"));
|
||||
}
|
||||
|
@ -45,7 +45,9 @@ async fn rocket() -> _ {
|
||||
controller::course::get_all,
|
||||
controller::register::insert_all,
|
||||
controller::register::options,
|
||||
controller::register::options_delete,
|
||||
controller::register::get_by_dni,
|
||||
controller::register::delete,
|
||||
],
|
||||
)
|
||||
}
|
||||
|
@ -133,4 +133,15 @@ impl Register {
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub async fn delete(register_id: i32) -> Result<(), sqlx::Error> {
|
||||
let db = db();
|
||||
|
||||
let _ = sqlx::query!("DELETE FROM register WHERE register_id = ?", register_id)
|
||||
.execute(db)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user