feat(projects): added projects backend, todo add blogs
This commit is contained in:
parent
8a60c5097e
commit
169071af8c
80
data_txt/projects.yaml
Normal file
80
data_txt/projects.yaml
Normal file
@ -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.
|
@ -195,7 +195,7 @@
|
|||||||
skill_level: 15
|
skill_level: 15
|
||||||
tech_cat:
|
tech_cat:
|
||||||
- Tools
|
- Tools
|
||||||
|
# remove later
|
||||||
- tech_name: Email
|
- tech_name: Email
|
||||||
tech_logo: https://www.svgrepo.com/show/491226/email.svg
|
tech_logo: https://www.svgrepo.com/show/491226/email.svg
|
||||||
project_site: mailto:darkicewolf50@gmail.com
|
project_site: mailto:darkicewolf50@gmail.com
|
116
src/lib.rs
116
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::{Deserialize, Serialize};
|
||||||
|
use serde_json::json;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
pub fn add(left: u64, right: u64) -> u64 {
|
pub fn log_incoming(req: HttpRequest, method: &str, path_source: &str) {
|
||||||
left + right
|
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("/")]
|
#[get("/")]
|
||||||
pub async fn hello() -> impl Responder {
|
pub async fn hello(req: HttpRequest) -> impl Responder {
|
||||||
HttpResponse::Ok().body("Hello world!")
|
log_incoming(req, "GET", "/");
|
||||||
}
|
web::Json(json!({
|
||||||
|
"body": {
|
||||||
#[post("/echo")]
|
"message": "Hello I am alive, this does nothing"
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
@ -40,8 +39,9 @@ struct TechDes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/skills")]
|
#[get("/skills")]
|
||||||
pub async fn skills_home() -> impl Responder {
|
pub async fn skills_home(req: HttpRequest) -> impl Responder {
|
||||||
let raw_yaml: String = fs::read_to_string("./src/data_txt/skill_level.yaml").unwrap();
|
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.");
|
// .expect("Cannot open file or missing file.");
|
||||||
let vec_yaml = yaml_rust2::YamlLoader::load_from_str(&raw_yaml).unwrap()[0].clone();
|
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)
|
web::Json(res_vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||||
mod tests {
|
struct ProjectDes {
|
||||||
use super::*;
|
project_name: String,
|
||||||
|
website_link: String,
|
||||||
#[test]
|
github_link: String,
|
||||||
fn it_works() {
|
project_img: String,
|
||||||
let result = add(2, 2);
|
techs_used: Vec<String>,
|
||||||
assert_eq!(result, 4);
|
project_des: String,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/projects/{num_limit}")]
|
||||||
|
pub async fn project(limit: web::Path<usize>, 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<ProjectDes> = 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<ProjectDes> = 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);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
10
src/main.rs
10
src/main.rs
@ -1,15 +1,17 @@
|
|||||||
use actix_web::{App, HttpServer, web};
|
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]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
.service(hello)
|
.service(hello)
|
||||||
.service(echo)
|
// .service(echo)
|
||||||
.service(resend)
|
// .service(resend)
|
||||||
.route("/hey", web::get().to(manual_hello))
|
// .route("/hey", web::get().to(manual_hello))
|
||||||
|
.service(project)
|
||||||
.service(web::scope("/home").service(skills_home))
|
.service(web::scope("/home").service(skills_home))
|
||||||
})
|
})
|
||||||
.bind(("127.0.0.1", 8080))?
|
.bind(("127.0.0.1", 8080))?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user