workyard_application/actions/create/
contract.rs1use serde::Serialize;
2use trine::{Cancellation, NativePath};
3use workyard_core::{OperationKind, Problem, Task};
4
5use crate::contracts::ProblemOutcome;
6pub use crate::contracts::{OperationReport, ParticipantOutcome};
7
8pub(crate) struct ExistingTaskPreview {
9 pub workspace: Option<NativePath>,
10 pub cancellation: Cancellation,
11}
12
13#[derive(Serialize)]
15pub struct CreateOutcome {
16 #[serde(skip)]
17 pub(crate) explicit_workspace: Option<NativePath>,
18 #[serde(skip)]
19 pub(crate) checkout_hint: Option<String>,
20 #[serde(skip)]
21 pub(crate) starting_branch_example: Option<String>,
22 #[serde(skip)]
23 pub(crate) existing_task: Option<ExistingTaskPreview>,
24 #[serde(skip_serializing_if = "Option::is_none")]
26 pub registration_problem: Option<ProblemOutcome>,
27 pub operation: OperationReport,
29 pub lifecycle: Option<&'static str>,
31 pub task: String,
33 pub tasks_root: Option<NativePath>,
35 pub state_dir: Option<NativePath>,
37 pub record: Option<NativePath>,
39 pub participants: Vec<ParticipantOutcome>,
41 #[serde(skip_serializing_if = "Option::is_none")]
43 pub problem: Option<ProblemOutcome>,
44}
45
46impl CreateOutcome {
47 pub fn rejected(task: String, problem: Problem) -> Self {
49 Self {
50 checkout_hint: None,
51 starting_branch_example: None,
52 existing_task: None,
53 registration_problem: None,
54 operation: OperationReport::rejected(OperationKind::Create, &problem),
55 explicit_workspace: None,
56 lifecycle: None,
57 task,
58 tasks_root: None,
59 state_dir: None,
60 record: None,
61 participants: Vec::new(),
62 problem: Some(problem.into()),
63 }
64 }
65
66 pub fn from_task(task: Task, record: std::path::PathBuf) -> Self {
68 Self {
69 checkout_hint: None,
70 starting_branch_example: None,
71 existing_task: None,
72 registration_problem: None,
73 operation: task.operation.into(),
74 explicit_workspace: None,
75 lifecycle: Some(task.lifecycle.as_str()),
76 task: task.name,
77 tasks_root: Some(NativePath::new(task.root).expect("validated root path")),
78 state_dir: Some(NativePath::new(task.state_dir).expect("validated state path")),
79 record: Some(NativePath::new(record).expect("validated filesystem path")),
80 participants: task.participants.into_iter().map(Into::into).collect(),
81 problem: task.problem.map(Into::into),
82 }
83 }
84}