From 3db3f2e129f1367ba23fc89282d5a67d48d33963 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Sun, 19 Nov 2023 16:23:53 +0100 Subject: [PATCH] Backend: Deleted skills db, added languages, planguages and softwares depending on info_id. Routing for skills now require an id. Frontend: Added subsections and reworked processdata.js --- backend/db/_languages.sql | 15 ++++ backend/db/_programming_languages.sql | 16 ++++ backend/db/{project.sql => _project.sql} | 4 +- backend/db/_softwares.sql | 15 ++++ backend/db/a_skills.sql | 13 ---- backend/src/db.rs | 27 +++++-- backend/src/main.rs | 74 ++++++++++-------- frontend/src/lib/components/subsection.svelte | 13 ++++ frontend/src/lib/css/section.css | 16 ++++ frontend/src/lib/js/processdata.js | 5 +- frontend/src/routes/+page.js | 75 ++++++++++--------- frontend/src/routes/+page.svelte | 9 ++- 12 files changed, 190 insertions(+), 92 deletions(-) create mode 100644 backend/db/_languages.sql create mode 100644 backend/db/_programming_languages.sql rename backend/db/{project.sql => _project.sql} (67%) create mode 100644 backend/db/_softwares.sql delete mode 100644 backend/db/a_skills.sql create mode 100644 frontend/src/lib/components/subsection.svelte diff --git a/backend/db/_languages.sql b/backend/db/_languages.sql new file mode 100644 index 0000000..9ae719e --- /dev/null +++ b/backend/db/_languages.sql @@ -0,0 +1,15 @@ +-- public.languages definition + +-- Drop table + +-- DROP TABLE public.languages; + +CREATE TABLE public.languages ( + id serial4 NOT NULL, + info_id int4 NOT NULL DEFAULT nextval('languages_skills_id_seq'::regclass), + lang text NOT NULL, + icon_alpha varchar(3) NOT NULL, + "level" text NOT NULL, + CONSTRAINT languages_pkey PRIMARY KEY (id), + CONSTRAINT languages_fk FOREIGN KEY (info_id) REFERENCES public.info(id) +); \ No newline at end of file diff --git a/backend/db/_programming_languages.sql b/backend/db/_programming_languages.sql new file mode 100644 index 0000000..06584b2 --- /dev/null +++ b/backend/db/_programming_languages.sql @@ -0,0 +1,16 @@ +-- public.programming_languages definition + +-- Drop table + +-- DROP TABLE public.programming_languages; + +CREATE TABLE public.programming_languages ( + id serial4 NOT NULL, + info_id int4 NOT NULL DEFAULT nextval('programming_languages_skills_id_seq'::regclass), + lang text NOT NULL, + icon text NOT NULL, + type_icon text NOT NULL, + color varchar(7) NULL, + CONSTRAINT programming_languages_pkey PRIMARY KEY (id), + CONSTRAINT programming_languages_fk FOREIGN KEY (info_id) REFERENCES public.info(id) +); \ No newline at end of file diff --git a/backend/db/project.sql b/backend/db/_project.sql similarity index 67% rename from backend/db/project.sql rename to backend/db/_project.sql index 3ddd218..907bc1a 100644 --- a/backend/db/project.sql +++ b/backend/db/_project.sql @@ -10,9 +10,9 @@ CREATE TABLE public.project ( title text NULL, description text NULL, github_link text NULL, - id_skills serial4 NOT NULL, + info_id int4 NOT NULL DEFAULT nextval('project_id_skills_seq'::regclass), picture_name text NULL, type_project text NULL, CONSTRAINT project_pkey PRIMARY KEY (id), - CONSTRAINT project_fk FOREIGN KEY (id_skills) REFERENCES public.skills(id) + CONSTRAINT project_fk FOREIGN KEY (info_id) REFERENCES public.info(id) ); \ No newline at end of file diff --git a/backend/db/_softwares.sql b/backend/db/_softwares.sql new file mode 100644 index 0000000..208522b --- /dev/null +++ b/backend/db/_softwares.sql @@ -0,0 +1,15 @@ +-- public.softwares definition + +-- Drop table + +-- DROP TABLE public.softwares; + +CREATE TABLE public.softwares ( + id serial4 NOT NULL, + info_id int4 NOT NULL DEFAULT nextval('softwares_skills_id_seq'::regclass), + software text NOT NULL, + icon text NOT NULL, + type_icon text NOT NULL, + color varchar(7) NULL, + CONSTRAINT softwares_pkey PRIMARY KEY (id) +); \ No newline at end of file diff --git a/backend/db/a_skills.sql b/backend/db/a_skills.sql deleted file mode 100644 index e82819f..0000000 --- a/backend/db/a_skills.sql +++ /dev/null @@ -1,13 +0,0 @@ --- public.skills definition - --- Drop table - --- DROP TABLE public.skills; - -CREATE TABLE public.skills ( - id serial4 NOT NULL, - programming_lang text NULL, - software text NULL, - languages text NULL, - CONSTRAINT skills_pkey PRIMARY KEY (id) -); \ No newline at end of file diff --git a/backend/src/db.rs b/backend/src/db.rs index 42f75f6..a4a0b36 100644 --- a/backend/src/db.rs +++ b/backend/src/db.rs @@ -38,20 +38,33 @@ pub struct Experience { #[derive(Deserialize, Serialize)] pub struct Project { - pub id: i64, pub date_done: Option, pub title: Option, pub description: Option, pub github_link: Option, - pub id_skills: i64, pub picture_name: Option, pub type_project: Option } #[derive(Deserialize, Serialize)] -pub struct Skills { - pub id: i64, - pub programming_lang: Option, - pub software: Option, - pub languages: Option, +pub struct ProgrammingLanguages { + pub lang: String, + pub icon: String, + pub type_icon: String, + pub color: Option +} + +#[derive(Deserialize, Serialize)] +pub struct Softwares { + pub software: String, + pub icon: String, + pub type_icon: String, + pub color: Option +} + +#[derive(Deserialize, Serialize)] +pub struct Languages { + pub lang: String, + pub icon_alpha: String, + pub level: String } \ No newline at end of file diff --git a/backend/src/main.rs b/backend/src/main.rs index 887a879..55e5d35 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -10,7 +10,7 @@ use std::net::SocketAddr; use tower_http::cors::CorsLayer; mod db; -use db::{Education, Experience, Info, Project, Skills}; +use db::{Education, Experience, Info, Languages, Project, ProgrammingLanguages, Softwares}; #[tokio::main] async fn main() -> Result<()> { @@ -27,7 +27,7 @@ async fn main() -> Result<()> { .route("/info", get(info)) .route("/education", get(education)) .route("/experience", get(experience)) - .route("/skills", get(skills)) + .route("/skills/:id", get(skills)) .with_state(pool) .layer(CorsLayer::very_permissive()); @@ -38,6 +38,12 @@ async fn main() -> Result<()> { .await?) } +macro_rules! gather_data { + ($data_type:ty, $sql_cmd:expr, $pool:expr) => { + sqlx::query_as!($data_type, $sql_cmd).fetch_all($pool).await + }; +} + async fn info(State(pool): State) -> Result>> { let datas = sqlx::query_as!( Info, @@ -49,43 +55,51 @@ async fn info(State(pool): State) -> Result>> { } async fn education(State(pool): State) -> Result>> { - let datas = sqlx::query_as!( - Education, - "SELECT * FROM public.education" - ) - .fetch_all(&pool) - .await?; + let datas = sqlx::query_as!(Education, "SELECT * FROM public.education") + .fetch_all(&pool) + .await?; Ok(Json(datas)) } async fn experience(State(pool): State) -> Result>> { - let datas = sqlx::query_as!( - Experience, - "SELECT * FROM public.experience" - ) - .fetch_all(&pool) - .await?; + let datas = sqlx::query_as!(Experience, "SELECT * FROM public.experience") + .fetch_all(&pool) + .await?; Ok(Json(datas)) } -async fn skills(State(pool): State) -> Result, Vec)>> { - // Gathering skills - let skills = sqlx::query_as!( - Skills, - "SELECT * FROM public.skills" - ) - .fetch_all(&pool) - .await - .unwrap(); - - // Gathering Projects - let projects = sqlx::query_as!( +async fn skills(State(pool): State, Path(id): Path) -> Result,Vec,Vec,Vec)>> { + let project = sqlx::query_as!( Project, - "SELECT * FROM public.project ORDER BY date_done DESC" + "SELECT date_done, title, description, github_link, picture_name, type_project FROM public.project WHERE project.info_id = $1 ORDER BY date_done DESC", + id ) .fetch_all(&pool) - .await - .unwrap(); + .await?; + + let programming_languages = sqlx::query_as!( + ProgrammingLanguages, + "SELECT lang, icon, type_icon, color FROM public.programming_languages WHERE programming_languages.info_id = $1", + id + ) + .fetch_all(&pool) + .await?; - Ok(Json((projects,skills))) + let softwares = sqlx::query_as!( + Softwares, + "SELECT software, icon, type_icon, color FROM public.softwares WHERE softwares.info_id = $1", + id + ) + .fetch_all(&pool) + .await?; + + let languages = sqlx::query_as!( + Languages, + "SELECT lang, icon_alpha, level FROM public.languages WHERE languages.info_id = $1", + id + ) + .fetch_all(&pool) + .await?; + + Ok(Json((project,programming_languages,softwares,languages))) } diff --git a/frontend/src/lib/components/subsection.svelte b/frontend/src/lib/components/subsection.svelte new file mode 100644 index 0000000..cd7b62a --- /dev/null +++ b/frontend/src/lib/components/subsection.svelte @@ -0,0 +1,13 @@ + + +
+ +

{title}

+
diff --git a/frontend/src/lib/css/section.css b/frontend/src/lib/css/section.css index 3846ef0..9257d6a 100644 --- a/frontend/src/lib/css/section.css +++ b/frontend/src/lib/css/section.css @@ -8,7 +8,23 @@ filter: drop-shadow(0px 6px 4px rgba(0, 0, 0, 0.15)); } +.subsection-container { + margin-left: 3rem; + margin-bottom: 0.5rem; + display: flex; + flex-direction: row; + align-items: center; + color: var(--color-subtitle); + filter: drop-shadow(0px 6px 4px rgba(0, 0, 0, 0.15)); +} + .section-h1 { margin-left: 2rem; font-size: 2.5rem; +} + +.section-h2 { + margin-left: 1rem; + font-size: 1.5rem; + color: var(--color-subtitle); } \ No newline at end of file diff --git a/frontend/src/lib/js/processdata.js b/frontend/src/lib/js/processdata.js index 55e22f5..3d9d307 100644 --- a/frontend/src/lib/js/processdata.js +++ b/frontend/src/lib/js/processdata.js @@ -11,10 +11,9 @@ export function processData(data) { const info = data.info[0]; const experiences = arrangeById(data.experience); const education = arrangeById(data.education); - const skills = data.skills[1]; - const projects = data.skills[0]; + const skills = data.skills; - return {info, experiences, education, skills, projects}; + return {info, experiences, education, skills}; } else { return null; // Indicates an error } diff --git a/frontend/src/routes/+page.js b/frontend/src/routes/+page.js index 0da0fad..8d1d650 100644 --- a/frontend/src/routes/+page.js +++ b/frontend/src/routes/+page.js @@ -1,42 +1,45 @@ export async function load(context) { - async function fetchData(data) { - try { - const resTemp = await context.fetch(`http://0.0.0.0:8000/${data}`); - if(resTemp.ok == false) { - return { - status: resTemp.status, - } - } - return { - status: 0, - data: await resTemp.json(), - } - } catch(error) { - return { - status: 500, - } + async function fetchData(data) { + try { + const resTemp = await context.fetch(`http://0.0.0.0:8000/${data}`); + if (resTemp.ok == false) { + return { + status: resTemp.status, } + } + return { + status: 0, data: await resTemp.json(), + } + } catch (error) { + return { + status: 500, + } } + } - const infos = []; - const dataToGather = ["info", "education", "experience", "skills"]; - for (const url of dataToGather) { - const res = await fetchData(url); - if(res.status == 0) - { - infos.push(res.data); - } else { - return { - status: res.status - } - } + const infos = []; + const dataToGather = ['info', 'education', 'experience', 'skills/1']; + for (const url of dataToGather) { + const res = await fetchData(url); + if (res.status == 0) { + infos.push(res.data); + } else { + return { + status: res.status + } } - - return { - status: 0, - info: infos[0], - education: infos[1], - experience: infos[2], - skills: infos[3] - }; + } + + return { + status: 0, + info: infos[0], + education: infos[1], + experience: infos[2], + skills: { + project: infos[3][0], + programming_languages: infos[3][1], + softwares: infos[3][2], + languages: infos[3][3], + }, + }; } diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index c9dfb8a..fc9f3d2 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -13,10 +13,14 @@ mdiEmailOutline, mdiPhone, mdiStar, + mdiXml, + mdiApplication, + mdiEarth } from "@mdi/js"; // Main import Section from "$lib/components/section.svelte"; + import SubSection from "$lib/components/subsection.svelte"; import Education from "$lib/components/education.svelte"; import Experience from "$lib/components/experience.svelte"; import Projects from "$lib/components/projects.svelte" @@ -105,10 +109,13 @@ />
+ + + {:else}