bitque/crates/database-actor/src/issue_assignees.rs

60 lines
1.5 KiB
Rust
Raw Normal View History

2021-04-16 15:20:25 +02:00
use diesel::prelude::*;
2023-03-31 23:25:20 +02:00
use diesel::dsl::not;
use bitque_data::{IssueAssignee, IssueId, UserId};
2021-04-16 15:20:25 +02:00
use crate::{db_create, db_delete, db_load, db_load_field};
db_create! {
AsignMultiple,
msg => issue_assignees => {
use crate::models::CreateIssueAssigneeForm;
let AsignMultiple { user_ids, issue_id: i_id } = msg;
diesel::insert_into(issue_assignees)
.values(user_ids.into_iter().map(|u_id| {
CreateIssueAssigneeForm {
user_id: u_id,
issue_id: i_id
}
}).collect::<Vec<CreateIssueAssigneeForm>>())
},
IssueAssignee,
user_ids => Vec<UserId>,
issue_id => IssueId
}
db_load! {
LoadAssignees,
msg => issue_assignees => issue_assignees
.distinct_on(id)
.filter(issue_id.eq(msg.issue_id)),
IssueAssignee,
issue_id => IssueId
}
db_load_field! {
LoadAssigneesIds,
UserId,
msg => issue_assignees => issue_assignees
.select(user_id)
.filter(issue_id.eq(msg.issue_id)),
IssueAssignee,
issue_id => IssueId
}
db_delete! {
DeleteIssueAssignees,
msg => issue_assignees => diesel::delete(issue_assignees.filter(issue_id.eq(msg.issue_id))),
IssueAssignee,
issue_id => IssueId
}
db_delete! {
DropIssueAssignees,
msg => issue_assignees => diesel::delete(issue_assignees)
.filter(not(user_id.eq_any(msg.user_ids)).and(issue_id.eq(msg.issue_id))),
IssueAssignee,
issue_id => IssueId,
user_ids => Vec<UserId>
}