Backend: Added tags for each project.
This commit is contained in:
parent
44d3af1595
commit
7d829cc22f
3 changed files with 100 additions and 8 deletions
14
backend/db/8_project_tags.sql
Normal file
14
backend/db/8_project_tags.sql
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
-- public.project_tags definition
|
||||||
|
|
||||||
|
-- Drop table
|
||||||
|
|
||||||
|
-- DROP TABLE public.project_tags;
|
||||||
|
|
||||||
|
CREATE TABLE public.project_tags (
|
||||||
|
project_id int4 NOT NULL,
|
||||||
|
programming_languages_id int4 NULL,
|
||||||
|
softwares_id int4 NULL,
|
||||||
|
CONSTRAINT project_tags_project_fk FOREIGN KEY (project_id) REFERENCES public.project(id),
|
||||||
|
CONSTRAINT project_tags_programming_languages_fk FOREIGN KEY (programming_languages_id) REFERENCES public.programming_languages(id),
|
||||||
|
CONSTRAINT project_tags_softwares_fk FOREIGN KEY (softwares_id) REFERENCES public.softwares(id)
|
||||||
|
);
|
|
@ -67,4 +67,21 @@ pub struct Languages {
|
||||||
pub lang: String,
|
pub lang: String,
|
||||||
pub icon_alpha: String,
|
pub icon_alpha: String,
|
||||||
pub level: String
|
pub level: String
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct Tags {
|
||||||
|
pub lang: Option<String>,
|
||||||
|
pub icon: Option<String>,
|
||||||
|
pub type_icon: Option<String>,
|
||||||
|
pub color: Option<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct AllTags {
|
||||||
|
pub project_id: Option<i32>,
|
||||||
|
pub lang: Option<String>,
|
||||||
|
pub icon: Option<String>,
|
||||||
|
pub type_icon: Option<String>,
|
||||||
|
pub color: Option<String>
|
||||||
}
|
}
|
|
@ -10,7 +10,7 @@ use std::net::SocketAddr;
|
||||||
use tower_http::cors::CorsLayer;
|
use tower_http::cors::CorsLayer;
|
||||||
|
|
||||||
mod db;
|
mod db;
|
||||||
use db::{Education, Experience, Info, Languages, Project, ProgrammingLanguages, Softwares};
|
use db::{Education, Experience, Info, Languages, ProgrammingLanguages, Project, Softwares, Tags, AllTags};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
@ -28,6 +28,8 @@ async fn main() -> Result<()> {
|
||||||
.route("/education", get(education))
|
.route("/education", get(education))
|
||||||
.route("/experience", get(experience))
|
.route("/experience", get(experience))
|
||||||
.route("/skills/:id", get(skills))
|
.route("/skills/:id", get(skills))
|
||||||
|
.route("/tags/:info_id/:project_id", get(tags))
|
||||||
|
.route("/tags/:id", get(alltags))
|
||||||
.with_state(pool)
|
.with_state(pool)
|
||||||
.layer(CorsLayer::very_permissive());
|
.layer(CorsLayer::very_permissive());
|
||||||
|
|
||||||
|
@ -44,8 +46,7 @@ macro_rules! _gather_data {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn info(State(pool): State<PgPool>) -> Json<Vec<Info>>
|
async fn info(State(pool): State<PgPool>) -> Json<Vec<Info>> {
|
||||||
{
|
|
||||||
let datas = sqlx::query_as!(
|
let datas = sqlx::query_as!(
|
||||||
Info,
|
Info,
|
||||||
"SELECT id, full_name, phone_number, email, softskills, interests, birth_year FROM public.info"
|
"SELECT id, full_name, phone_number, email, softskills, interests, birth_year FROM public.info"
|
||||||
|
@ -58,18 +59,28 @@ async fn info(State(pool): State<PgPool>) -> Json<Vec<Info>>
|
||||||
async fn education(State(pool): State<PgPool>) -> Json<Vec<Education>> {
|
async fn education(State(pool): State<PgPool>) -> Json<Vec<Education>> {
|
||||||
let datas = sqlx::query_as!(Education, "SELECT * FROM public.education")
|
let datas = sqlx::query_as!(Education, "SELECT * FROM public.education")
|
||||||
.fetch_all(&pool)
|
.fetch_all(&pool)
|
||||||
.await.unwrap_or(vec![]);
|
.await
|
||||||
|
.unwrap_or(vec![]);
|
||||||
Json(datas)
|
Json(datas)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn experience(State(pool): State<PgPool>) -> Json<Vec<Experience>> {
|
async fn experience(State(pool): State<PgPool>) -> Json<Vec<Experience>> {
|
||||||
let datas = sqlx::query_as!(Experience, "SELECT * FROM public.experience")
|
let datas = sqlx::query_as!(Experience, "SELECT * FROM public.experience")
|
||||||
.fetch_all(&pool)
|
.fetch_all(&pool)
|
||||||
.await.unwrap_or(vec![]);
|
.await
|
||||||
|
.unwrap_or(vec![]);
|
||||||
Json(datas)
|
Json(datas)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn skills(Path(id): Path<i32>, State(pool): State<PgPool>) -> Json<(Vec<Project>,Vec<ProgrammingLanguages>,Vec<Softwares>,Vec<Languages>)> {
|
async fn skills(
|
||||||
|
Path(id): Path<i32>,
|
||||||
|
State(pool): State<PgPool>,
|
||||||
|
) -> Json<(
|
||||||
|
Vec<Project>,
|
||||||
|
Vec<ProgrammingLanguages>,
|
||||||
|
Vec<Softwares>,
|
||||||
|
Vec<Languages>,
|
||||||
|
)> {
|
||||||
let project = sqlx::query_as!(
|
let project = sqlx::query_as!(
|
||||||
Project,
|
Project,
|
||||||
"SELECT date_done, title, description, github_link, picture_name, type_project FROM public.project WHERE project.info_id = $1 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",
|
||||||
|
@ -77,7 +88,7 @@ async fn skills(Path(id): Path<i32>, State(pool): State<PgPool>) -> Json<(Vec<Pr
|
||||||
)
|
)
|
||||||
.fetch_all(&pool)
|
.fetch_all(&pool)
|
||||||
.await.unwrap_or(vec![]);
|
.await.unwrap_or(vec![]);
|
||||||
|
|
||||||
let programming_languages = sqlx::query_as!(
|
let programming_languages = sqlx::query_as!(
|
||||||
ProgrammingLanguages,
|
ProgrammingLanguages,
|
||||||
"SELECT lang, icon, type_icon, color FROM public.programming_languages WHERE programming_languages.info_id = $1 ORDER BY programming_languages.id",
|
"SELECT lang, icon, type_icon, color FROM public.programming_languages WHERE programming_languages.info_id = $1 ORDER BY programming_languages.id",
|
||||||
|
@ -102,5 +113,55 @@ async fn skills(Path(id): Path<i32>, State(pool): State<PgPool>) -> Json<(Vec<Pr
|
||||||
.fetch_all(&pool)
|
.fetch_all(&pool)
|
||||||
.await.unwrap_or(vec![]);
|
.await.unwrap_or(vec![]);
|
||||||
|
|
||||||
Json((project,programming_languages,softwares,languages))
|
Json((project, programming_languages, softwares, languages))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn tags(Path(ids): Path<(i32, i32)>, State(pool): State<PgPool>) -> Json<Vec<Tags>> {
|
||||||
|
let (info_id, project_id) = ids;
|
||||||
|
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.info_id = $1 and pt.project_id = $2
|
||||||
|
|
||||||
|
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.info_id = $1 and pt.project_id = $2;
|
||||||
|
|
||||||
|
",
|
||||||
|
info_id,
|
||||||
|
project_id
|
||||||
|
)
|
||||||
|
.fetch_all(&pool)
|
||||||
|
.await
|
||||||
|
.unwrap_or(vec![]);
|
||||||
|
Json(datas)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn alltags(Path(info_id): Path<i32>, State(pool): State<PgPool>) -> Json<Vec<AllTags>> {
|
||||||
|
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
|
||||||
|
WHERE pt.info_id = $1
|
||||||
|
|
||||||
|
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
|
||||||
|
WHERE pt.info_id = $1;
|
||||||
|
|
||||||
|
",
|
||||||
|
info_id
|
||||||
|
)
|
||||||
|
.fetch_all(&pool)
|
||||||
|
.await
|
||||||
|
.unwrap_or(vec![]);
|
||||||
|
Json(datas)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue