Handle POST favoris
This commit is contained in:
parent
8509a32cbf
commit
b8a0190d91
2 changed files with 26 additions and 4 deletions
|
@ -10,7 +10,7 @@ use diesel::prelude::*;
|
||||||
use crate::models::{InsertFavorite, InsertTitle, Title};
|
use crate::models::{InsertFavorite, InsertTitle, Title};
|
||||||
use crate::schema::title;
|
use crate::schema::title;
|
||||||
use crate::schema::title::dsl::*;
|
use crate::schema::title::dsl::*;
|
||||||
use errors::DatabaseError;
|
pub use errors::DatabaseError;
|
||||||
|
|
||||||
/// Inserts all titles from Mirabel into the local database.
|
/// Inserts all titles from Mirabel into the local database.
|
||||||
pub fn add_all_titles<'a>(
|
pub fn add_all_titles<'a>(
|
||||||
|
|
28
src/ear.rs
28
src/ear.rs
|
@ -103,9 +103,9 @@ fn handle_request(request: Request, mut sender: Mouth) {
|
||||||
"titre" => match database::search_titre(&request.requested_data) {
|
"titre" => match database::search_titre(&request.requested_data) {
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
if result.len() == 0 {
|
if result.len() == 0 {
|
||||||
let result = sender.send_data(Status::NotFound, serde_json::json!(result));
|
sender.send_data(Status::NotFound, serde_json::json!(result));
|
||||||
} else {
|
} else {
|
||||||
let result = sender.send_data(Status::OK, serde_json::json!(result));
|
sender.send_data(Status::OK, serde_json::json!(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -119,7 +119,29 @@ fn handle_request(request: Request, mut sender: Mouth) {
|
||||||
serde_json::json!("La requête est mal formée, veuillez lire la documentation."),
|
serde_json::json!("La requête est mal formée, veuillez lire la documentation."),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
"POST" => todo!(),
|
"POST" => match request.section.as_str() {
|
||||||
|
"favoris" => {
|
||||||
|
let mirabelid: i32 = match request.requested_data.trim().parse() {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(_) => {
|
||||||
|
sender.send_data(Status::BadRequest, serde_json::json!("La requête est mal formée, veuillez lire la documentation."));
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
match database::insert_favorite(mirabelid) {
|
||||||
|
Ok(result) => sender.send_data(Status::OK, serde_json::json!(result)),
|
||||||
|
Err(err) => match err {
|
||||||
|
database::DatabaseError::NotFound => sender.send_data(Status::NotFound, serde_json::json!(format!("{}", err))),
|
||||||
|
database::DatabaseError::FoundDuplicate => sender.send_data(Status::BadRequest, serde_json::json!(format!("{}", err))),
|
||||||
|
_ => sender.send_data(Status::InternalError, serde_json::json!(format!("{}", err))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => sender.send_data(
|
||||||
|
Status::BadRequest,
|
||||||
|
serde_json::json!("La requête est mal formée, veuillez lire la documentation."),
|
||||||
|
),
|
||||||
|
},
|
||||||
_ => sender.send_data(
|
_ => sender.send_data(
|
||||||
Status::BadRequest,
|
Status::BadRequest,
|
||||||
serde_json::json!("La requête est mal formée, veuillez lire la documentation."),
|
serde_json::json!("La requête est mal formée, veuillez lire la documentation."),
|
||||||
|
|
Loading…
Reference in a new issue