Rename functions

This commit is contained in:
flyingscorpio@clevo 2023-01-07 08:24:15 +01:00
parent e67de50ea7
commit 0f15c38cd3
3 changed files with 7 additions and 7 deletions

View file

@ -36,7 +36,7 @@ pub fn add_all_titles<'a>(
/// Inserts a favorite in the local database, if a matching Title exists.
/// Returns the matching Title if successful, otherwise an error.
pub fn insert_favorite(title_mirabelid: i32) -> Result<Title, DatabaseError> {
pub fn add_favorite(title_mirabelid: i32) -> Result<Title, DatabaseError> {
let connection = &mut crud::establish_connection()?;
// search for a matching title, and return error if not found
@ -58,9 +58,9 @@ pub fn insert_favorite(title_mirabelid: i32) -> Result<Title, DatabaseError> {
}
}
/// Searches for a titre with a keyword and returns the found Title instances.
pub fn search_titre(keyword: &str) -> Result<Vec<Title>, DatabaseError> {
/// Searches for a Title with a 'titre' and returns the found Title instances.
pub fn search_title_from_titre(keyword: &str) -> Result<Vec<Title>, DatabaseError> {
let connection = &mut crud::establish_connection()?;
crud::search_titre_from_keyword(connection, keyword)
crud::search_title_from_titre(connection, keyword)
}

View file

@ -71,7 +71,7 @@ pub(super) fn search_favorite_from_mirabelid(
}
/// Searches the title table for a 'titre', and returns a vector of Title items.
pub(super) fn search_titre_from_keyword(
pub(super) fn search_title_from_titre(
connection: &mut PgConnection,
keyword: &str,
) -> Result<Vec<Title>, DatabaseError> {

View file

@ -101,7 +101,7 @@ fn parse_uri(full_request: &str) -> Result<Request, ReqParseError> {
fn handle_request(request: Request, mut sender: Mouth) {
match request.method.as_str() {
"GET" => match request.section.as_str() {
"titre" => match database::search_titre(&request.requested_data) {
"titre" => match database::search_title_from_titre(&request.requested_data) {
Ok(result) => {
if result.len() == 0 {
sender.send_data(Status::NotFound, serde_json::json!(result));
@ -129,7 +129,7 @@ fn handle_request(request: Request, mut sender: Mouth) {
return;
},
};
match database::insert_favorite(mirabelid) {
match database::add_favorite(mirabelid) {
Ok(result) => sender.send_data(Status::OK, serde_json::json!(format!("Favori inséré avec succès : {}", result.titre))),
Err(err) => match err {
database::DatabaseError::NotFound => sender.send_data(Status::NotFound, serde_json::json!(format!("{}", err))),