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

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;