diff --git a/src/db/db_utils.rs b/src/db/db_utils.rs index bf3acf3..0014519 100644 --- a/src/db/db_utils.rs +++ b/src/db/db_utils.rs @@ -57,7 +57,7 @@ pub async fn search_channel_by_username( for element in searched { match element { Some(channel) => { - if channel.username == username.to_string() { + if channel.username == *username { return Some(channel); } } @@ -73,7 +73,7 @@ pub async fn create_channel(username: &String, db: &Surreal) -> Vec { eprintln!("Already Exists"); - return vec![]; + vec![] } None => { db.query("DEFINE INDEX usernameINDEX ON TABLE channel COLUMNS username UNIQUE") @@ -485,13 +485,10 @@ pub async fn is_follower_by_username( Some(follower_channel) => match search_channel_by_username(followed, db).await { Some(mut followed_channel) => { followed_channel.follower_list.sort(); - match followed_channel + followed_channel .follower_list .binary_search(&follower_channel.id.unwrap().id) - { - Ok(_) => true, - Err(_) => false, - } + .is_ok() } None => { eprintln!("Error: Can't Check Is Follower | Followed Not Exists"); @@ -510,13 +507,10 @@ pub async fn is_banned_by_username(victim: &String, judge: &String, db: &Surreal Some(victim_channel) => match search_channel_by_username(judge, db).await { Some(mut judge_channel) => { judge_channel.banned_list.sort(); - match judge_channel + judge_channel .banned_list .binary_search(&victim_channel.id.unwrap().id) - { - Ok(_) => true, - Err(_) => false, - } + .is_ok() } None => { eprintln!("Error: Can't Check Is Banned | Judge Not Exists"); diff --git a/src/main.rs b/src/main.rs index 3b849b8..4aba1d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ async fn main() { }; let app = routing::routing(axum::extract::State(state)).await; - let addr = SocketAddr::from(take_args().parse::().unwrap()); + let addr = take_args().parse::().unwrap(); axum_server::bind_rustls(addr, tls_config) .serve(app.into_make_service()) diff --git a/src/routing.rs b/src/routing.rs index 2779119..8e79fff 100644 --- a/src/routing.rs +++ b/src/routing.rs @@ -2,7 +2,7 @@ use axum::{ extract::{Path, State}, http::StatusCode, response::IntoResponse, - routing::get, + routing::{delete, get, patch, post}, Json, Router, }; use tower_http::cors::CorsLayer; @@ -12,18 +12,18 @@ use crate::{db::db_operations, utils::database_config, AppState}; pub async fn routing(State(state): State) -> Router { Router::new() .route("/", get(alive)) - .route("/create/:username", get(create)) - .route("/delete/:username", get(delete)) - .route("/search-username/:username", get(search_username)) - .route("/search-id/:id", get(search_id)) + .route("/:username", post(create_channel)) + .route("/:username", delete(delete_channel)) + .route("/:username", get(search_username)) + .route("/id/:id", get(search_id)) .route( - "/change-username/:username/:updated_username", - get(change_username), + "/username/:username/:updated_username", + patch(change_username), ) - .route("/follow/:follower/:followed", get(follow)) - .route("/unfollow/:follower/:followed", get(unfollow)) - .route("/ban/:victim/:judge", get(ban)) - .route("/unban/:victim/:judge", get(unban)) + .route("/follow/:follower/:followed", patch(follow)) + .route("/unfollow/:follower/:followed", patch(unfollow)) + .route("/ban/:victim/:judge", patch(ban)) + .route("/unban/:victim/:judge", patch(unban)) .route("/is-follower/:follower/:followed", get(is_follower)) .route("/is-banned/:victim/:judge", get(is_banned)) .layer(CorsLayer::permissive()) @@ -42,7 +42,10 @@ async fn alive() -> impl IntoResponse { (StatusCode::OK, Json(alive_json)) } -async fn create(Path(username): Path, State(state): State) -> impl IntoResponse { +async fn create_channel( + Path(username): Path, + State(state): State, +) -> impl IntoResponse { match db_operations::create(&username, &state.db).await { Some(channel) => { let create = serde_json::json!({ @@ -53,7 +56,10 @@ async fn create(Path(username): Path, State(state): State) -> None => (StatusCode::NOT_ACCEPTABLE, Json(serde_json::json!(""))), } } -async fn delete(Path(username): Path, State(state): State) -> impl IntoResponse { +async fn delete_channel( + Path(username): Path, + State(state): State, +) -> impl IntoResponse { match db_operations::delete(&username, &state.db).await { Some(channel) => { let delete = serde_json::json!({ diff --git a/src/utils.rs b/src/utils.rs index ea6e2d1..749bcd6 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -17,11 +17,11 @@ pub async fn database_config() -> DataBaseConfig { .await .unwrap(); - let configs_parsed: Vec<&str> = config_unparsed.split_terminator("\n").collect(); + let configs_parsed: Vec<&str> = config_unparsed.split_terminator('\n').collect(); let mut configs_cleaned: Vec<&str> = vec![]; for element in configs_parsed { - let dirty: Vec<&str> = element.split(": ").collect(); + let dirty: Vec<&str> = element.split('=').collect(); configs_cleaned.push(dirty[1]); }