fix: 🩹 a little further adaptation for restful
This commit is contained in:
parent
8c04db05b8
commit
cfae099413
6 changed files with 33 additions and 29 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,7 +4,6 @@ debug/
|
|||
target/
|
||||
.vscode/
|
||||
certificates/
|
||||
configs/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
|
|
5
configs/databaseconfig
Normal file
5
configs/databaseconfig
Normal file
|
@ -0,0 +1,5 @@
|
|||
address=0.0.0.0:5000
|
||||
username=root
|
||||
password=root
|
||||
namespace=acapair
|
||||
database=acapair
|
|
@ -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<Client>) -> Vec<Opti
|
|||
match search_channel_by_username(username, db).await {
|
||||
Some(_) => {
|
||||
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");
|
||||
|
|
|
@ -28,7 +28,7 @@ async fn main() {
|
|||
};
|
||||
|
||||
let app = routing::routing(axum::extract::State(state)).await;
|
||||
let addr = SocketAddr::from(take_args().parse::<SocketAddr>().unwrap());
|
||||
let addr = take_args().parse::<SocketAddr>().unwrap();
|
||||
|
||||
axum_server::bind_rustls(addr, tls_config)
|
||||
.serve(app.into_make_service())
|
||||
|
|
|
@ -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<AppState>) -> 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<String>, State(state): State<AppState>) -> impl IntoResponse {
|
||||
async fn create_channel(
|
||||
Path(username): Path<String>,
|
||||
State(state): State<AppState>,
|
||||
) -> 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<String>, State(state): State<AppState>) ->
|
|||
None => (StatusCode::NOT_ACCEPTABLE, Json(serde_json::json!(""))),
|
||||
}
|
||||
}
|
||||
async fn delete(Path(username): Path<String>, State(state): State<AppState>) -> impl IntoResponse {
|
||||
async fn delete_channel(
|
||||
Path(username): Path<String>,
|
||||
State(state): State<AppState>,
|
||||
) -> impl IntoResponse {
|
||||
match db_operations::delete(&username, &state.db).await {
|
||||
Some(channel) => {
|
||||
let delete = serde_json::json!({
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue