code cleanup

This commit is contained in:
J-onasJones 2024-01-03 00:59:22 +01:00
parent 169be592ab
commit 2188f2acd5
5 changed files with 24 additions and 35 deletions

View file

@ -1,5 +1,3 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{Value, json}; use serde_json::{Value, json};
use warp::Filter; use warp::Filter;
@ -10,7 +8,7 @@ mod upcoming;
use filter::get_kcomebacks_filter_routes; use filter::get_kcomebacks_filter_routes;
use upcoming::get_kcomebacks_upcoming_routes; use upcoming::get_kcomebacks_upcoming_routes;
use crate::error_responses::{InternalServerError, BadRequestError, NotFoundError}; use crate::error_responses::InternalServerError;
pub fn get_kcomebacks_routes() -> impl warp::Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone { pub fn get_kcomebacks_routes() -> impl warp::Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
warp::path("v1").and(warp::path("kcomebacks")) warp::path("v1").and(warp::path("kcomebacks"))

View file

@ -2,7 +2,7 @@ use std::{collections::HashMap, ops::Add};
use warp::Filter; use warp::Filter;
use crate::{v1::kcomebacks::filter::filter_daterange_handler, error_responses::BadRequestError}; use crate::v1::kcomebacks::filter::filter_daterange_handler;
pub fn get_kcomebacks_upcoming_routes() -> impl warp::Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone { pub fn get_kcomebacks_upcoming_routes() -> impl warp::Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
warp::path("upcoming") warp::path("upcoming")

View file

@ -1,10 +1,9 @@
use std::{collections::{HashMap, HashSet}, vec}; use std::collections::HashMap;
use reqwest::StatusCode;
use serde_json::{Value, json}; use serde_json::{Value, json};
use warp::Filter; use warp::Filter;
use crate::{error_responses::{BadRequestError, InternalServerError, NotImplementedError}, v1::projects::{fetch_data, create_json_response, Project as EntryProject}}; use crate::{error_responses::{BadRequestError, NotImplementedError}, v1::projects::{fetch_data, create_json_response, Project as EntryProject}};
pub fn get_project_filter_routes() -> impl warp::Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone { pub fn get_project_filter_routes() -> impl warp::Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
warp::path("filter") warp::path("filter")
@ -452,16 +451,16 @@ async fn filter_getlangs_handler() -> Result<impl warp::Reply, warp::Rejection>
let data = fetch_data().await.unwrap(); let data = fetch_data().await.unwrap();
// filter the data // filter the data
let filtered_data: Vec<EntryProject> = match data { // let filtered_data: Vec<EntryProject> = match data {
Value::Array(items) => { // Value::Array(items) => {
items // items
.iter() // .iter()
.filter_map(|item| serde_json::from_value::<EntryProject>(item.clone()).ok()) // .filter_map(|item| serde_json::from_value::<EntryProject>(item.clone()).ok())
.filter(|project| project.visible) // .filter(|project| project.visible)
.collect() // .collect()
} // }
_ => Vec::new(), // _ => Vec::new(),
}; // };
// filter the data // filter the data
/*let all_language_keys: Vec<&String> = filtered_data /*let all_language_keys: Vec<&String> = filtered_data

View file

@ -73,11 +73,3 @@ pub fn create_json_response(items: Vec<&Project>, total_results: usize) -> Value
json_response json_response
} }
pub fn parse_item(item: &Value) -> Project {
// Parse the item into a struct
let item: Project = serde_json::from_value(item.clone()).unwrap();
// Return the parsed item
item
}

View file

@ -16,14 +16,14 @@ fn handle_path(modname: String, loadername: String, version: String, remote_ip:
format!("modname: {}, loadername: {}, version: {}, IP: {}", modname, loadername, version, remote_ip.unwrap_or(std::net::SocketAddr::from(([0, 0, 0, 0], 0))).ip()) format!("modname: {}, loadername: {}, version: {}, IP: {}", modname, loadername, version, remote_ip.unwrap_or(std::net::SocketAddr::from(([0, 0, 0, 0], 0))).ip())
} }
fn handle_with_headers( // fn handle_with_headers(
headers: warp::http::HeaderMap, // headers: warp::http::HeaderMap,
) -> String { // ) -> String {
// Iterate through the headers and print them // // Iterate through the headers and print them
for (name, value) in headers.iter() { // for (name, value) in headers.iter() {
println!("Header: {}: {}", name, value.to_str().unwrap_or("Invalid UTF-8")); // println!("Header: {}: {}", name, value.to_str().unwrap_or("Invalid UTF-8"));
} // }
// Respond with a message or perform other actions as needed // // Respond with a message or perform other actions as needed
"Headers received".to_string() // "Headers received".to_string()
} // }