2021-04-16 15:20:25 +02:00
|
|
|
use derive_db_execute::Execute;
|
|
|
|
use diesel::prelude::*;
|
2021-04-25 11:31:52 +02:00
|
|
|
use jirs_data::{DescriptionString, EndsAt, Epic, EpicId, ProjectId, StartsAt};
|
2021-04-16 15:20:25 +02:00
|
|
|
|
|
|
|
use crate::{db_create, db_delete, db_load, db_update};
|
2020-12-24 16:24:04 +01:00
|
|
|
|
2021-01-19 21:57:48 +01:00
|
|
|
#[derive(Execute)]
|
|
|
|
#[db_exec(schema = "epics", result = "Epic", find = "epics.find(msg.epic_id)")]
|
|
|
|
pub struct FindEpic {
|
|
|
|
pub epic_id: EpicId,
|
|
|
|
}
|
|
|
|
|
2020-12-24 16:24:04 +01:00
|
|
|
db_load! {
|
|
|
|
LoadEpics,
|
|
|
|
msg => epics => epics.distinct_on(id).filter(project_id.eq(msg.project_id)),
|
|
|
|
Epic,
|
2021-01-19 21:57:48 +01:00
|
|
|
project_id => ProjectId
|
2020-12-24 16:24:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
db_create! {
|
|
|
|
CreateEpic,
|
|
|
|
msg => epics => diesel::insert_into(epics).values((
|
|
|
|
name.eq(msg.name.as_str()),
|
|
|
|
user_id.eq(msg.user_id),
|
|
|
|
project_id.eq(msg.project_id),
|
2021-01-19 21:57:48 +01:00
|
|
|
msg.description.map(|d| description.eq(d)),
|
|
|
|
msg.description_html.map(|d| description_html.eq(d)),
|
2020-12-24 16:24:04 +01:00
|
|
|
)),
|
|
|
|
Epic,
|
|
|
|
user_id => i32,
|
|
|
|
project_id => i32,
|
2021-01-19 21:57:48 +01:00
|
|
|
name => String,
|
|
|
|
description => Option<DescriptionString>,
|
|
|
|
description_html => Option<DescriptionString>
|
2020-12-24 16:24:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
db_update! {
|
2021-04-25 11:31:52 +02:00
|
|
|
UpdateEpicName,
|
2020-12-24 16:24:04 +01:00
|
|
|
msg => epics => diesel::update(
|
|
|
|
epics
|
|
|
|
.filter(project_id.eq(msg.project_id))
|
|
|
|
.find(msg.epic_id),
|
|
|
|
).set(name.eq(msg.name)),
|
|
|
|
Epic,
|
|
|
|
epic_id => i32,
|
|
|
|
project_id => i32,
|
|
|
|
name => String
|
|
|
|
}
|
|
|
|
|
2021-04-25 11:31:52 +02:00
|
|
|
db_update! {
|
|
|
|
UpdateEpicStartsAt,
|
|
|
|
msg => epics => diesel::update(
|
|
|
|
epics
|
|
|
|
.filter(project_id.eq(msg.project_id))
|
|
|
|
.find(msg.epic_id),
|
|
|
|
).set(starts_at.eq(msg.starts_at)),
|
|
|
|
Epic,
|
|
|
|
epic_id => i32,
|
|
|
|
project_id => i32,
|
|
|
|
starts_at => Option<StartsAt>
|
|
|
|
}
|
|
|
|
|
|
|
|
db_update! {
|
|
|
|
UpdateEpicEndsAt,
|
|
|
|
msg => epics => diesel::update(
|
|
|
|
epics
|
|
|
|
.filter(project_id.eq(msg.project_id))
|
|
|
|
.find(msg.epic_id),
|
|
|
|
).set(ends_at.eq(msg.ends_at)),
|
|
|
|
Epic,
|
|
|
|
epic_id => i32,
|
|
|
|
project_id => i32,
|
|
|
|
ends_at => Option<EndsAt>
|
|
|
|
}
|
|
|
|
|
2020-12-24 16:24:04 +01:00
|
|
|
db_delete! {
|
|
|
|
DeleteEpic,
|
|
|
|
msg => epics => diesel::delete(
|
|
|
|
epics.filter(user_id.eq(msg.user_id)).find(msg.epic_id)
|
|
|
|
),
|
|
|
|
Epic,
|
|
|
|
user_id => i32,
|
|
|
|
epic_id => i32
|
|
|
|
}
|