Add macros for chip, add tasks for creating job and skill

This commit is contained in:
2024-11-04 03:26:12 +01:00
parent 49d86dec00
commit feeaecac85
14 changed files with 140 additions and 1844 deletions

1
Cargo.lock generated
View File

@@ -1673,6 +1673,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"serial_test", "serial_test",
"tera",
"tokio", "tokio",
"tower 0.5.1", "tower 0.5.1",
"tower-http", "tower-http",

View File

@@ -44,6 +44,7 @@ unic-langid = "0.9.4"
axum-range = "0.4.0" axum-range = "0.4.0"
axum-extra = { version = "0.9.4", features = ["multipart", "typed-header", "cookie"] } axum-extra = { version = "0.9.4", features = ["multipart", "typed-header", "cookie"] }
bytes = "1.8.0" bytes = "1.8.0"
tera = "1.20.0"
# /view engine # /view engine
[[bin]] [[bin]]

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,5 @@
{% extends "website/base.html" %} {% block content %} {% import "website/macros/chip.html" as chip %} {% extends "website/base.html"
%} {% block content %}
<span class="m-8">🌟</span> <span class="m-8">🌟</span>
<div <div
class="flex flex-col items-center justify-center gap-2 p-4 bg-white rounded-lg" class="flex flex-col items-center justify-center gap-2 p-4 bg-white rounded-lg"
@@ -26,56 +27,18 @@
<div <div
class="flex flex-wrap items-center justify-center gap-4 m-4 md:m-0 md:w-1/2" class="flex flex-wrap items-center justify-center gap-4 m-4 md:m-0 md:w-1/2"
> >
<p {{ chip::chip(text="Programming 💻")}} {{ chip::chip(text="Filmmaking 🎥")}}
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]" {{ chip::chip(text="Gaming 🕹️")}} {{ chip::chip(text="Playing guitar 🎸")}}
>
Programming 💻
</p>
<p
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]"
>
Filmmaking 🎥
</p>
<p
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]"
>
Gaming 🕹️
</p>
<p
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]"
>
Playing guitar 🎸
</p>
</div> </div>
<h1 class="mt-6 text-3xl font-bold">Interests 🌌📚</h1> <h1 class="mt-6 text-3xl font-bold">Interests 🌌📚</h1>
<div <div
class="flex flex-wrap items-center justify-center gap-4 m-4 md:m-0 md:w-1/2" class="flex flex-wrap items-center justify-center gap-4 m-4 md:m-0 md:w-1/2"
> >
<p {{ chip::chip(text="Computer Science 💾")}}
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]" {{ chip::chip(text="Sci-Fi Books📚")}}
> {{ chip::chip(text="Astronomy 🔭")}}
Computer Science 💾 {{ chip::chip(text="Sports 🏅") }}
</p> {{ chip::chip(text="History 🏰")}}
<p
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]"
>
Sci-Fi Books 📚
</p>
<p
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]"
>
Astronomy 🔭
</p>
<p
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]"
>
Sports 🏅
</p>
<p
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]"
>
History 🏰
</p>
</div> </div>
<h1 class="mt-6 text-3xl font-bold">FAQ ❓</h1> <h1 class="mt-6 text-3xl font-bold">FAQ ❓</h1>
<div class="flex flex-col gap-2 m-4"> <div class="flex flex-col gap-2 m-4">

View File

@@ -1,10 +0,0 @@
<div class="flex flex-col gap-2 p-4 text-black bg-gray-100 rounded-lg">
<h4 class="text-2xl">
<span class="fas fa-user-circle"></span> {{ job.position }}
</h4>
<h5 class="text-xl font-light">
<span class="fas fa-building"></span> {{ job.company }}
</h5>
<p class="font-bold"><span class="fas fa-microchip"></span> Technologies</p>
<div class="flex flex-wrap gap-2"></div>
</div>

View File

@@ -1,4 +1,5 @@
{% extends "website/base.html" %} {% block content %} {% import "website/macros/chip.html" as chip %} {% extends "website/base.html"
%} {% block content %}
<div class="w-full mt-8"></div> <div class="w-full mt-8"></div>
<h3 class="mt-4 mb-2 text-5xl font-bold tracking-tight">Who am I? 🤔</h3> <h3 class="mt-4 mb-2 text-5xl font-bold tracking-tight">Who am I? 🤔</h3>
<section <section
@@ -11,17 +12,11 @@
💾. 💾.
</section> </section>
<h3 class="mt-4 mb-2 text-5xl font-bold tracking-tight">Skills 🛠️</h3> <h3 class="mt-4 mb-2 text-5xl font-bold tracking-tight">Skills 🛠️</h3>
{% for skill in skills %} {% for skill in skills %} {{ chip::chip(text=skill.name) }} {%endfor%}
<p
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]"
>
{{ skill.name }}
</p>
{%endfor%}
<section class="flex flex-wrap justify-center w-1/2 gap-4"></section> <section class="flex flex-wrap justify-center w-1/2 gap-4"></section>
<h3 class="mt-4 mb-2 text-5xl font-bold tracking-tight">Experience 📈</h3> <h3 class="mt-4 mb-2 text-5xl font-bold tracking-tight">Experience 📈</h3>
{% for job in jobs %} {% for job in jobs %}
<div class="bg-gray-100 rounded-lg p-4 text-black flex flex-col gap-2"> <div class="flex flex-col gap-2 p-4 text-black bg-gray-100 rounded-lg">
<h4 class="text-2xl"> <h4 class="text-2xl">
<span class="fas fa-user-circle"></span> {{ job.position }} <span class="fas fa-user-circle"></span> {{ job.position }}
</h4> </h4>
@@ -40,13 +35,8 @@
</h6> </h6>
{% endif %} {% endif %}
<p class="font-bold"><span class="fas fa-microchip"></span> Technologies</p> <p class="font-bold"><span class="fas fa-microchip"></span> Technologies</p>
{% for technology in job.technologies %} {% for technology in job.technologies %} {{ chip::chip(text=technology.name)
<p }} {% endfor %}
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]"
>
{{ technology }}
</p>
{% endfor %}
</div> </div>
{%endfor%} {%endfor%}
<section class="flex flex-col flex-wrap justify-center gap-4 m-4"></section> <section class="flex flex-col flex-wrap justify-center gap-4 m-4"></section>

View File

@@ -0,0 +1,7 @@
{% macro chip(text) %}
<p
class="text-base text-center rounded-2xl font-semibold tracking-tight text-black shadow-lg bg-yellow-400 p-2 min-w-[4rem] max-w-[12rem]"
>
{{ text }}
</p>
{% endmacro chip %}

View File

@@ -0,0 +1,6 @@
{% extends "website/base.html" %} {% block content %}
<span class="m-8"></span>
<div class="flex flex-col w-full gap-4 m-4">
<h1 class="text-5xl font-bold text-center">My projects</h1>
</div>
{% endblock content %}

View File

@@ -70,6 +70,8 @@ impl Hooks for App {
fn register_tasks(tasks: &mut Tasks) { fn register_tasks(tasks: &mut Tasks) {
tasks.register(tasks::seed::SeedData); tasks.register(tasks::seed::SeedData);
tasks.register(tasks::create_user::CreateUserData); tasks.register(tasks::create_user::CreateUserData);
tasks.register(tasks::create_job::CreateJobData);
tasks.register(tasks::create_skill::CreateSkillData);
} }
async fn truncate(db: &DatabaseConnection) -> Result<()> { async fn truncate(db: &DatabaseConnection) -> Result<()> {

View File

@@ -31,10 +31,19 @@ pub async fn render_about(ViewEngine(v): ViewEngine<TeraView>) -> Result<impl In
views::website::about(v).await views::website::about(v).await
} }
pub async fn render_projects(
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<impl IntoResponse> {
views::website::projects(v, &ctx).await
}
pub fn routes() -> Routes { pub fn routes() -> Routes {
Routes::new() Routes::new()
.add("/", get(render_index)) .add("/", get(render_index))
.add("/upload", get(render_upload)) .add("/upload", get(render_upload))
.add("/login", get(render_login)) .add("/login", get(render_login))
.add("/projects", get(render_projects))
.add("/projets/:project_name", get(render_projects))
.add("/about", get(render_about)) .add("/about", get(render_about))
} }

55
src/tasks/create_job.rs Normal file
View File

@@ -0,0 +1,55 @@
use loco_rs::prelude::*;
use crate::models::_entities::jobs::ActiveModel;
pub struct CreateJobData;
#[async_trait]
impl Task for CreateJobData {
fn task(&self) -> TaskInfo {
TaskInfo {
name: "create_job".to_string(),
detail: "Task for creating a new job".to_string(),
}
}
async fn run(&self, app_context: &AppContext, vars: &task::Vars) -> Result<()> {
let company = vars.cli_arg("company")?;
let position = vars.cli_arg("position")?;
let start_date = vars.cli_arg("start_date")?;
let end_date = vars.cli_arg("end_date")?;
let technologies = vars.cli_arg("technologies")?;
let still_working = vars.cli_arg("still_working")?;
let start_date = start_date.parse::<Date>();
let end_date = end_date.parse::<Date>();
let still_working = still_working.parse::<bool>();
let mut item = ActiveModel {
..Default::default()
};
item.company = Set(company.to_string());
item.position = Set(position.to_string());
if let Ok(start_date) = start_date {
item.start_date = Set(start_date);
}
if let Ok(end_date) = end_date {
item.end_date = Set(Some(end_date));
}
item.technologies = Set(technologies.to_string());
if let Ok(still_working) = still_working {
item.still_working = Set(still_working);
}
let item = item.insert(&app_context.db).await?;
tracing::info!(
job_id = item.id,
job_position = &item.position,
"Job created successfully",
);
Ok(())
}
}

35
src/tasks/create_skill.rs Normal file
View File

@@ -0,0 +1,35 @@
use loco_rs::prelude::*;
use crate::models::_entities::skills::ActiveModel;
pub struct CreateSkillData;
#[async_trait]
impl Task for CreateSkillData {
fn task(&self) -> TaskInfo {
TaskInfo {
name: "create_skill".to_string(),
detail: "Task for creating a new skill".to_string(),
}
}
async fn run(&self, app_context: &AppContext, vars: &task::Vars) -> Result<()> {
let name = vars.cli_arg("name")?;
let mut item = ActiveModel {
..Default::default()
};
item.name = Set(name.to_string());
let item = item.insert(&app_context.db).await?;
tracing::info!(
skill_id = item.id,
skill_name = &item.name,
"Skill created successfully",
);
Ok(())
}
}

View File

@@ -1,2 +1,4 @@
pub mod create_job;
pub mod create_skill;
pub mod create_user; pub mod create_user;
pub mod seed; pub mod seed;

View File

@@ -13,6 +13,12 @@ pub async fn index(v: impl ViewRenderer, ctx: &AppContext) -> Result<impl IntoRe
) )
} }
pub async fn projects(v: impl ViewRenderer, ctx: &AppContext) -> Result<impl IntoResponse> {
// let projects = services::projects::get_all_projects(ctx).await?;
format::render().view(&v, "website/projects.html", data!({"projects": {}}))
}
pub async fn about(v: impl ViewRenderer) -> Result<impl IntoResponse> { pub async fn about(v: impl ViewRenderer) -> Result<impl IntoResponse> {
let age = services::website::get_current_age(); let age = services::website::get_current_age();