From 169071af8c97d985f0282c611b302e293dedb196 Mon Sep 17 00:00:00 2001 From: darkicewolf50 Date: Mon, 5 May 2025 17:08:04 -0600 Subject: [PATCH] feat(projects): added projects backend, todo add blogs --- data_txt/projects.yaml | 80 ++++++++++++++ {src/data_txt => data_txt}/skill_level.yaml | 2 +- src/lib.rs | 116 ++++++++++++++------ src/main.rs | 10 +- 4 files changed, 168 insertions(+), 40 deletions(-) create mode 100644 data_txt/projects.yaml rename {src/data_txt => data_txt}/skill_level.yaml (99%) diff --git a/data_txt/projects.yaml b/data_txt/projects.yaml new file mode 100644 index 0000000..2eaf34e --- /dev/null +++ b/data_txt/projects.yaml @@ -0,0 +1,80 @@ +--- +- project_name: Portfolio Site + website_link: https://darkicewolf50.github.io + github_link: https://github.com/darkicewolf50/darkicewolf50.github.io + project_img: https://res.cloudinary.com/dpgrgsh7g/image/upload/v1745630861/Portfolio_site_k4mhmj.png + techs_used: + - Rust + - CSS + - Dioxus + - Github Actions + - Git + - Github + project_des: + This project was a great test of my newly learned Rust. It was certainly + interesting to go through all of the stages of front end web developement, while + the orignal and new found scope is not currently achieved, it will be on a later + pass through. I am very happy with how it turned out in compairison to my origanl + site map, and wireframes. Considering this phase one was accomplished in 3 working + days I believe it is an excellent show of my skill. +- project_name: UCalgary Baja Backend + project_img: https://www.svgrepo.com/show/448221/docker.svg + techs_used: + - Python + - FastAPI + - Github Actions + - Docker + - Traefik + - Git + - Github + project_des: + This is going to be extremely cost saving for the non-profit club UCalgary + Baja. Using automated uploads and linting to check the Python and FastAPI code + was excellent for learning how to self-host a web server. This was then upgraded + later with the addition of treafik so that it could be SSL certified, this is + also known as supporting HTTPS transmissions. Ultimately it will serve as a great + stepping stone for both myself an anyone else in UCalgary Baja Software subteam. + This will lead into using Actixs in the migration Soon™ to be. +- project_name: UCalgary Baja Website + website_link: https://uofcbaja.pages.dev + project_img: https://res.cloudinary.com/dpgrgsh7g/image/upload/v1745633714/ucalgary-baja-site-April.png + techs_used: + - HTML5 + - CSS + - JavaScript + - Markdown + - YAML + - React + - Git + - Github + - Cloudflare + project_des: + The flexibility that we achieved using React, rather than a locked + down platform or framework has allows all the Software members of UCalgary Baja + to learn infinitely more. This isn't to say that it is faster or have additional + perks of using 'non-code website builders'. This is provided massive opportunities + to learn teach and save on cost compaired to the website builders. Overall I would + say this will be worth it in the long run and opened my eyes to different website + hosting providers, with their associated perks and costs. When we change it, it + will most likely we re-written in Vue as there is a good non-depreciated way to + initalize the framework. +- project_name: Backend for Portfolio Site + website_link: + github_link: https://gitea.bajacloud.duckdns.org/darkicewolf50/darkicewolf50Cloud + project_img: https://www.svgrepo.com/show/448221/docker.svg + techs_used: + - Rust + - Actix + - YAML + - Git + - Gitea + project_des: + The flexibility that we achieved using React, rather than a locked + down platform or framework has allows all the Software members of UCalgary Baja + to learn infinitely more. This isn't to say that it is faster or have additional + perks of using 'non-code website builders'. This is provided massive opportunities + to learn teach and save on cost compaired to the website builders. Overall I would + say this will be worth it in the long run and opened my eyes to different website + hosting providers, with their associated perks and costs. When we change it, it + will most likely we re-written in Vue as there is a good non-depreciated way to + initalize the framework. diff --git a/src/data_txt/skill_level.yaml b/data_txt/skill_level.yaml similarity index 99% rename from src/data_txt/skill_level.yaml rename to data_txt/skill_level.yaml index b37c61a..b05c06e 100644 --- a/src/data_txt/skill_level.yaml +++ b/data_txt/skill_level.yaml @@ -195,7 +195,7 @@ skill_level: 15 tech_cat: - Tools - +# remove later - tech_name: Email tech_logo: https://www.svgrepo.com/show/491226/email.svg project_site: mailto:darkicewolf50@gmail.com diff --git a/src/lib.rs b/src/lib.rs index 5e26d94..26d5c8a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,33 +1,32 @@ -use actix_web::{HttpResponse, Responder, get, post, web}; +use actix_web::{HttpRequest, Responder, get, web}; +// use actix_web::{HttpResponse, post}; use serde::{Deserialize, Serialize}; +use serde_json::json; use std::fs; -pub fn add(left: u64, right: u64) -> u64 { - left + right +pub fn log_incoming(req: HttpRequest, method: &str, path_source: &str) { + let peer_addr = req.peer_addr(); + if let Some(ip_addr_other) = peer_addr { + println!( + "{} request from: {}, subaddress: {}", + method, ip_addr_other, path_source + ); + } else { + println!( + "{} request from: unknown, subaddress: {}", + method, path_source + ); + } } #[get("/")] -pub async fn hello() -> impl Responder { - HttpResponse::Ok().body("Hello world!") -} - -#[post("/echo")] -pub async fn echo(req_body: String) -> impl Responder { - HttpResponse::Ok().body(req_body) -} - -pub async fn manual_hello() -> impl Responder { - HttpResponse::Ok().body("Hello there!\nGeneral Kenobi") -} - -// the path to get to the html response -#[get("/resend")] -// function signature, data that is passed in, return type must implement the Responder trait -pub async fn resend(req_body: String) -> impl Responder { - // this returns a html response with a 200 code - // this should be used for final serialization - // possibly main functionality - HttpResponse::Ok().body(req_body) +pub async fn hello(req: HttpRequest) -> impl Responder { + log_incoming(req, "GET", "/"); + web::Json(json!({ + "body": { + "message": "Hello I am alive, this does nothing" + } + })) } #[derive(Deserialize, Serialize, Debug)] @@ -40,8 +39,9 @@ struct TechDes { } #[get("/skills")] -pub async fn skills_home() -> impl Responder { - let raw_yaml: String = fs::read_to_string("./src/data_txt/skill_level.yaml").unwrap(); +pub async fn skills_home(req: HttpRequest) -> impl Responder { + log_incoming(req, "GET", "/skills"); + let raw_yaml: String = fs::read_to_string("./data_txt/skill_level.yaml").unwrap(); // .expect("Cannot open file or missing file."); let vec_yaml = yaml_rust2::YamlLoader::load_from_str(&raw_yaml).unwrap()[0].clone(); @@ -66,13 +66,59 @@ pub async fn skills_home() -> impl Responder { web::Json(res_vec) } -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +#[derive(Deserialize, Serialize, Debug, Clone)] +struct ProjectDes { + project_name: String, + website_link: String, + github_link: String, + project_img: String, + techs_used: Vec, + project_des: String, } + +#[get("/projects/{num_limit}")] +pub async fn project(limit: web::Path, req: HttpRequest) -> impl Responder { + log_incoming(req, "GET", "/projects/{num_limit}"); + + let limit = limit.into_inner(); + + let raw_yaml: String = fs::read_to_string("./data_txt/projects.yaml").unwrap(); + let vec_yaml = yaml_rust2::YamlLoader::load_from_str(&raw_yaml).unwrap()[0].clone(); + + let raw_vec: Vec = vec_yaml + .as_vec() + .unwrap_or(&vec![]) + .iter() + .map(|item| ProjectDes { + project_name: item["project_name"].as_str().unwrap_or("").to_string(), + website_link: item["website_link"].as_str().unwrap_or("").to_string(), + github_link: item["github_link"].as_str().unwrap_or("").to_string(), + project_img: item["project_img"].as_str().unwrap_or("").to_string(), + techs_used: item["techs_used"] + .as_vec() + .unwrap_or(&vec![]) + .iter() + .filter_map(|item_str| item_str.as_str().map(|inner_item| inner_item.to_string())) + .collect(), + project_des: item["project_des"].as_str().unwrap_or("").to_string(), + }) + .collect(); + let res_vec: Vec = if limit == 0 || limit >= raw_vec.len() { + raw_vec + } else { + raw_vec[..limit].to_vec() + }; + + web::Json(res_vec) +} + +// #[cfg(test)] +// mod tests { +// use super::*; + +// #[test] +// fn it_works() { +// let result = add(2, 2); +// assert_eq!(result, 4); +// } +// } diff --git a/src/main.rs b/src/main.rs index c7167a2..9a0f089 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,17 @@ use actix_web::{App, HttpServer, web}; -use darkicewolf50_cloud::{echo, hello, manual_hello, resend, skills_home}; +use darkicewolf50_cloud::{hello, project, skills_home}; +// use darkicewolf50_cloud:: {echo, manual_hello, resend,}; #[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .service(hello) - .service(echo) - .service(resend) - .route("/hey", web::get().to(manual_hello)) + // .service(echo) + // .service(resend) + // .route("/hey", web::get().to(manual_hello)) + .service(project) .service(web::scope("/home").service(skills_home)) }) .bind(("127.0.0.1", 8080))?