From 56f1a37aec832d2a09685db8d19a200a9a7f30f5 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Sun, 11 Feb 2024 15:52:51 +0100 Subject: [PATCH] Backend: Created multiple categories for tags, removed specific ones. Frontend: Adapted to new database, deleted processdata.js which is no longer used. --- backend/db/2_categories.sql | 13 + backend/db/3_skills.sql | 17 ++ backend/db/4_categories_text.sql | 13 + backend/db/{4_skills.sql => 4_info_text.sql} | 6 +- backend/db/5_programming_languages.sql | 14 - backend/db/5_softwares.sql | 14 - backend/db/6_project_tags.sql | 6 +- backend/src/db.rs | 39 +-- backend/src/main.rs | 254 +++++++++++------- frontend/src/lib/components/pill.svelte | 1 + .../src/lib/components/projects-popup.svelte | 2 +- frontend/src/lib/js/processdata.js | 23 -- frontend/src/routes/lang=[lang]/+page.js | 45 +--- frontend/src/routes/lang=[lang]/+page.svelte | 47 ++-- 14 files changed, 246 insertions(+), 248 deletions(-) create mode 100644 backend/db/2_categories.sql create mode 100644 backend/db/3_skills.sql create mode 100644 backend/db/4_categories_text.sql rename backend/db/{4_skills.sql => 4_info_text.sql} (80%) delete mode 100644 backend/db/5_programming_languages.sql delete mode 100644 backend/db/5_softwares.sql delete mode 100644 frontend/src/lib/js/processdata.js diff --git a/backend/db/2_categories.sql b/backend/db/2_categories.sql new file mode 100644 index 0000000..5f78a92 --- /dev/null +++ b/backend/db/2_categories.sql @@ -0,0 +1,13 @@ +-- public.categories definition + +-- Drop table + +-- DROP TABLE public.categories; + +CREATE TABLE public.categories ( + id serial4 NOT NULL, + "name" text NOT NULL, + icon text NOT NULL, + type_icon text NOT NULL, + CONSTRAINT categories_pk PRIMARY KEY (id) +); \ No newline at end of file diff --git a/backend/db/3_skills.sql b/backend/db/3_skills.sql new file mode 100644 index 0000000..7c77d5e --- /dev/null +++ b/backend/db/3_skills.sql @@ -0,0 +1,17 @@ +-- public.skills definition + +-- Drop table + +-- DROP TABLE public.skills; + +CREATE TABLE public.skills ( + id serial4 NOT NULL, + category_id int4 DEFAULT nextval('skills_category_seq'::regclass) NOT NULL, + skill text NULL, + icon text NULL, + type_icon text NULL, + color varchar(7) NULL, + is_shown bool NULL, + CONSTRAINT skills_pk PRIMARY KEY (id), + CONSTRAINT skills_categories_fk FOREIGN KEY (category_id) REFERENCES public.categories(id) +); \ No newline at end of file diff --git a/backend/db/4_categories_text.sql b/backend/db/4_categories_text.sql new file mode 100644 index 0000000..ce7397d --- /dev/null +++ b/backend/db/4_categories_text.sql @@ -0,0 +1,13 @@ +-- public.categories_text definition + +-- Drop table + +-- DROP TABLE public.categories_text; + +CREATE TABLE public.categories_text ( + category_id serial4 NOT NULL, + lang_id serial4 NOT NULL, + "name" text NOT NULL, + CONSTRAINT categories_text_categories_fk FOREIGN KEY (category_id) REFERENCES public.categories(id), + CONSTRAINT categories_text_languages_fk FOREIGN KEY (lang_id) REFERENCES public.languages(id) +); \ No newline at end of file diff --git a/backend/db/4_skills.sql b/backend/db/4_info_text.sql similarity index 80% rename from backend/db/4_skills.sql rename to backend/db/4_info_text.sql index 8a40043..8a7bb33 100644 --- a/backend/db/4_skills.sql +++ b/backend/db/4_info_text.sql @@ -4,11 +4,11 @@ -- DROP TABLE public.skills; -CREATE TABLE public.skills ( +CREATE TABLE public.info_text ( softskills text NULL, interests text NULL, - lang_id serial4 NOT NULL, + lang_id int4 NOT NULL, title text NULL, description text NULL, CONSTRAINT skills_languages_fk FOREIGN KEY (lang_id) REFERENCES public.languages(id) -); \ No newline at end of file +);; \ No newline at end of file diff --git a/backend/db/5_programming_languages.sql b/backend/db/5_programming_languages.sql deleted file mode 100644 index 9d80481..0000000 --- a/backend/db/5_programming_languages.sql +++ /dev/null @@ -1,14 +0,0 @@ --- public.programming_languages definition - --- Drop table - --- DROP TABLE public.programming_languages; - -CREATE TABLE public.programming_languages ( - id serial4 NOT NULL, - lang text NOT NULL, - icon text NOT NULL, - type_icon text NOT NULL, - color varchar(7) NULL, - CONSTRAINT programming_languages_pkey PRIMARY KEY (id) -); \ No newline at end of file diff --git a/backend/db/5_softwares.sql b/backend/db/5_softwares.sql deleted file mode 100644 index 7d0f853..0000000 --- a/backend/db/5_softwares.sql +++ /dev/null @@ -1,14 +0,0 @@ --- public.softwares definition - --- Drop table - --- DROP TABLE public.softwares; - -CREATE TABLE public.softwares ( - id serial4 NOT NULL, - 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/6_project_tags.sql b/backend/db/6_project_tags.sql index 43bfc68..d0af515 100644 --- a/backend/db/6_project_tags.sql +++ b/backend/db/6_project_tags.sql @@ -6,9 +6,7 @@ CREATE TABLE public.project_tags ( project_id int4 NOT NULL, - programming_languages_id int4 NULL, - softwares_id int4 NULL, - CONSTRAINT project_tags_programming_languages_fk FOREIGN KEY (programming_languages_id) REFERENCES public.programming_languages(id), + skills_id int4 NOT NULL, CONSTRAINT project_tags_project_fk FOREIGN KEY (project_id) REFERENCES public.project(id), - CONSTRAINT project_tags_softwares_fk FOREIGN KEY (softwares_id) REFERENCES public.softwares(id) + CONSTRAINT project_tags_skills_fk FOREIGN KEY (skills_id) REFERENCES public.skills(id) ); \ No newline at end of file diff --git a/backend/src/db.rs b/backend/src/db.rs index a3fc6e7..0a20717 100644 --- a/backend/src/db.rs +++ b/backend/src/db.rs @@ -57,19 +57,26 @@ pub struct Project { } #[derive(Deserialize, Serialize)] -pub struct ProgrammingLanguages { - pub lang: Option, +pub struct Categories { + pub id: Option, + pub name: Option +} + +#[derive(Deserialize,Serialize,Clone)] +pub struct CategoriesText { pub icon: Option, pub type_icon: Option, - pub color: Option + pub name: Option } #[derive(Deserialize, Serialize)] -pub struct Softwares { - pub software: Option, +pub struct Skills { + pub id: Option, + pub skill: Option, pub icon: Option, pub type_icon: Option, - pub color: Option + pub color: Option, + pub is_shown: Option } #[derive(Deserialize, Serialize)] @@ -81,24 +88,22 @@ pub struct Languages { } #[derive(Deserialize, Serialize)] -pub struct Tags { - pub lang: Option, - pub icon: Option, - pub type_icon: Option, - pub color: Option -} - -#[derive(Deserialize, Serialize)] -pub struct AllTags { +pub struct AllSkills { pub project_id: Option, - pub lang: Option, + pub skill: Option, pub icon: Option, pub type_icon: Option, - pub color: Option + pub color: Option, + pub is_shown: Option } #[derive(Deserialize, Serialize)] pub struct SimpleProject { pub project_id: Option, pub title: Option +} + +#[derive(Deserialize,Serialize)] +pub struct Id { + pub id: Option } \ No newline at end of file diff --git a/backend/src/main.rs b/backend/src/main.rs index d6776cb..5ede84e 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -11,8 +11,8 @@ use tower_http::cors::CorsLayer; mod db; use db::{ - AllTags, Education, Experience, Info, LangId, Languages, ProgrammingLanguages, Project, - SimpleProject, Softwares, Tags, + AllSkills, Categories, CategoriesText, Education, Experience, Id, Info, LangId, Languages, + Project, SimpleProject, Skills, }; #[tokio::main] @@ -32,17 +32,11 @@ async fn main() -> Result<()> { .route("/education/:lang_id", get(education)) .route("/experience/:lang_id", get(experience)) .route("/project/:lang_id", get(projects)) + .route("/categories/:lang_id", get(categories_text)) .route("/hard_skills", get(hard_skills)) .route("/tags/:project_id", get(tags)) .route("/tags", get(alltags)) - .route( - "/getproject_programming/:programming_id/:lang_id", - get(getproject_programming), - ) - .route( - "/getproject_software/:software_id/:lang_id", - get(getproject_software), - ) + .route("/getproject_programming/:lang_id", get(getproject_skills)) .with_state(pool) .layer(CorsLayer::very_permissive()); @@ -80,10 +74,10 @@ async fn info(Path(lang_id): Path, State(pool): State) -> Json, State(pool): State, -) -> Json<(Vec, Vec, Vec)> { - let programming_languages = sqlx::query_as!( - ProgrammingLanguages, - "SELECT - pl.lang, - pl.icon, - pl.type_icon, - pl.color - FROM public.programming_languages pl - ORDER BY pl.id;" +) -> Json> { + let categories = sqlx::query_as!( + Categories, + "select + c.id, + c.name + from + public.categories c + order by + c.id;" ) .fetch_all(&pool) .await - .unwrap_or(vec![]); + .unwrap(); - let softwares = sqlx::query_as!( - Softwares, - "SELECT - s.software, - s.icon, - s.type_icon, - s.color - FROM public.softwares s - ORDER BY s.id;" - ) - .fetch_all(&pool) - .await - .unwrap_or(vec![]); + let mut categories_text: Vec = Vec::new(); + for c in categories { + let temp_category = sqlx::query_as!( + CategoriesText, + "SELECT + (SELECT icon FROM public.categories where id = $1 LIMIT 1) AS icon, + (SELECT type_icon FROM public.categories where id = $1 LIMIT 1) AS type_icon, + (SELECT name FROM public.categories_text WHERE category_id = $1 and lang_id = $2 LIMIT 1) AS name;" + ,c.id.unwrap(),lang_id + ).fetch_all(&pool) + .await + .unwrap(); + categories_text.push(temp_category[0].clone()); + } + + Json(categories_text) +} + +async fn hard_skills(State(pool): State) -> Json<(Vec, Vec>)> { let languages = sqlx::query_as!( Languages, "SELECT @@ -210,23 +211,66 @@ async fn hard_skills( .fetch_all(&pool) .await .unwrap(); - Json((programming_languages, softwares, languages)) + + let categories = sqlx::query_as!( + Categories, + "select + c.id, + c.name + from + public.categories c + order by + c.id;" + ) + .fetch_all(&pool) + .await + .unwrap(); + + let mut skills: Vec> = Vec::new(); + + for c in categories { + let skill_list = sqlx::query_as!( + Skills, + "select + s.id, + s.skill, + s.icon, + s.type_icon, + s.color, + s.is_shown + from + public.skills s + where + s.category_id = $1 + order by + s.id;", + c.id.unwrap() + ) + .fetch_all(&pool) + .await + .unwrap(); + skills.push(skill_list); + } + + Json((languages, skills)) } -async fn tags(Path(project_id): Path, State(pool): State) -> Json> { +async fn tags(Path(project_id): Path, State(pool): State) -> Json> { let datas = sqlx::query_as!( - Tags, - "SELECT lang, icon, type_icon, color - FROM public.programming_languages pl - JOIN public.project_tags pt ON pl.id = pt.programming_languages_id - WHERE pt.project_id = $1 - - UNION ALL - - SELECT software, icon, type_icon, color - FROM public.softwares s - JOIN public.project_tags pt ON s.id = pt.softwares_id - WHERE pt.project_id = $1;", + Skills, + "select + s.id, + s.skill, + s.icon, + s.type_icon, + s.color, + s.is_shown + from + public.skills s + join public.project_tags pt on + s.id = pt.skills_id + where + pt.project_id = $1", project_id ) .fetch_all(&pool) @@ -235,19 +279,22 @@ async fn tags(Path(project_id): Path, State(pool): State) -> Json) -> Json> { +async fn alltags(State(pool): State) -> Json> { let datas = sqlx::query_as!( - AllTags, - "SELECT project_id, lang, icon, type_icon, color - FROM public.programming_languages pl - JOIN public.project_tags pt ON pl.id = pt.programming_languages_id - - UNION ALL - - SELECT project_id, software, icon, type_icon, color - FROM public.softwares s - JOIN public.project_tags pt ON s.id = pt.softwares_id - ORDER BY project_id;" + AllSkills, + "select + pt.project_id, + s.skill, + s.icon, + s.type_icon, + s.color, + s.is_shown + from + public.skills s + join public.project_tags pt on + s.id = pt.skills_id + order by + pt.project_id;" ) .fetch_all(&pool) .await @@ -255,48 +302,49 @@ async fn alltags(State(pool): State) -> Json> { Json(datas) } -async fn getproject_programming( - Path(ids): Path<(i32,i32)>, +async fn getproject_skills( + Path(lang_id): Path, State(pool): State, -) -> Json> { - let (programming_id, lang_id) = ids; - let datas = sqlx::query_as!( - SimpleProject, - " SELECT - pt.project_id, - pt.title - FROM public.project_text pt - JOIN public.project_tags pta ON (pt.project_id = pta.project_id) AND (pt.lang_id = $1) - WHERE pta.programming_languages_id = $2 - ORDER BY pt.project_id;", - lang_id, - programming_id +) -> Json>> { + let project_ids = sqlx::query_as!( + Id, + "select + s.id + from + public.skills s + order by + s.id;" ) .fetch_all(&pool) .await .unwrap(); - Json(datas) -} -async fn getproject_software( - Path(ids): Path<(i32,i32)>, - State(pool): State, -) -> Json> { - let (software_id, lang_id) = ids; - let datas = sqlx::query_as!( - SimpleProject, - " SELECT - pt.project_id, - pt.title - FROM public.project_text pt - JOIN public.project_tags pta ON (pt.project_id = pta.project_id) AND (pt.lang_id = $1) - WHERE pta.softwares_id = $2 - ORDER BY pt.project_id;", - lang_id, - software_id - ) - .fetch_all(&pool) - .await - .unwrap(); - Json(datas) + let mut project_skills: Vec> = Vec::new(); + + for p in project_ids { + project_skills.push( + sqlx::query_as!( + SimpleProject, + "select + pt.project_id, + pt.title + from + public.project_text pt + join public.project_tags pta on + (pt.project_id = pta.project_id) + and (pt.lang_id = $1) + where + pta.skills_id = $2 + order by + pt.project_id;", + lang_id, + p.id.unwrap(), + ) + .fetch_all(&pool) + .await + .unwrap(), + ); + } + + Json(project_skills) } diff --git a/frontend/src/lib/components/pill.svelte b/frontend/src/lib/components/pill.svelte index 3cf1980..7c8f57e 100644 --- a/frontend/src/lib/components/pill.svelte +++ b/frontend/src/lib/components/pill.svelte @@ -118,6 +118,7 @@ function calculateNotification() { // 19 is arbitrary, based on the pill-notification width (which is around 25.6 px) minus a constant + if (!show_tooltip || tooltip_data.length <= 0) return; pill_notification.style.left = `${ main_pill.offsetLeft + main_pill.clientWidth - 19 }px`; diff --git a/frontend/src/lib/components/projects-popup.svelte b/frontend/src/lib/components/projects-popup.svelte index 783c391..da585e8 100644 --- a/frontend/src/lib/components/projects-popup.svelte +++ b/frontend/src/lib/components/projects-popup.svelte @@ -214,7 +214,7 @@