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

View File

@@ -70,6 +70,8 @@ impl Hooks for App {
fn register_tasks(tasks: &mut Tasks) {
tasks.register(tasks::seed::SeedData);
tasks.register(tasks::create_user::CreateUserData);
tasks.register(tasks::create_job::CreateJobData);
tasks.register(tasks::create_skill::CreateSkillData);
}
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
}
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 {
Routes::new()
.add("/", get(render_index))
.add("/upload", get(render_upload))
.add("/login", get(render_login))
.add("/projects", get(render_projects))
.add("/projets/:project_name", get(render_projects))
.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 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> {
let age = services::website::get_current_age();