62 lines
1.7 KiB
Rust
62 lines
1.7 KiB
Rust
use mysql::{params, prelude::Queryable};
|
|
|
|
use crate::{
|
|
database::db::Db,
|
|
entity::job::{Job, JobLog},
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
pub struct JobRepo {
|
|
db: Db,
|
|
}
|
|
|
|
impl JobRepo {
|
|
pub fn new(db: Db) -> Self {
|
|
Self { db }
|
|
}
|
|
|
|
pub fn find_by_id(&mut self, job_id: &usize) -> Result<Vec<Job>, mysql::Error> {
|
|
let mut connection: mysql::PooledConn = self.db.get_connection()?;
|
|
let stat = connection
|
|
.prep(
|
|
"SELECT
|
|
jm.file_name, jm.description
|
|
FROM jobs j
|
|
JOIN global_data.job_modules jm ON jm.job_module_id = j.job_module_id
|
|
WHERE
|
|
j.job_id = :job_id
|
|
",
|
|
)
|
|
.unwrap();
|
|
|
|
connection.exec_map(
|
|
stat,
|
|
params! {"job_id" => job_id},
|
|
|(file_name, description)| Job {
|
|
file_name,
|
|
description,
|
|
},
|
|
)
|
|
}
|
|
|
|
pub fn find_log(&mut self, job_id: &usize) -> Result<Vec<JobLog>, mysql::Error> {
|
|
let mut connection: mysql::PooledConn = self.db.get_connection()?;
|
|
let stat = connection
|
|
.prep(
|
|
"
|
|
SELECT jea.content, jea.upd_ts
|
|
FROM jobs j
|
|
JOIN job_events je on j.job_id = je.job_id AND je.m_id = j.m_id
|
|
JOIN job_event_attachments jea ON je.job_event_id = jea.job_event_id
|
|
WHERE
|
|
j.job_id = :job_id
|
|
",
|
|
)
|
|
.unwrap();
|
|
|
|
connection.exec_map(stat, params! {"job_id" => job_id}, |(content, upd_ts)| {
|
|
JobLog { content, upd_ts }
|
|
})
|
|
}
|
|
}
|