1- using CaseManagement . CMMN . CaseInstance . Commands ;
2- using CaseManagement . CMMN . CaseInstance . Handlers ;
1+ using CaseManagement . CMMN . CaseInstance . CommandHandlers ;
2+ using CaseManagement . CMMN . CaseInstance . Commands ;
3+ using CaseManagement . CMMN . Domains ;
4+ using CaseManagement . Workflow . Domains ;
5+ using CaseManagement . Workflow . Persistence ;
36using Microsoft . AspNetCore . Mvc ;
47using Newtonsoft . Json . Linq ;
8+ using System ;
9+ using System . Linq ;
510using System . Net ;
611using System . Threading . Tasks ;
712
@@ -12,10 +17,15 @@ public class CaseInstancesController : Controller
1217 {
1318 private readonly ICreateCaseInstanceCommandHandler _createCaseInstanceCommandHandler ;
1419 private readonly ILaunchCaseInstanceCommandHandler _launchCaseInstanceCommandHandler ;
20+ private readonly IConfirmFormCommandHandler _confirmFormCommandHandler ;
21+ private readonly IProcessFlowInstanceQueryRepository _processFlowInstanceQueryRepository ;
1522
16- public CaseInstancesController ( ICreateCaseInstanceCommandHandler createCaseInstanceCommandHandler , ILaunchCaseInstanceCommandHandler launchCaseInstanceCommandHandler )
23+ public CaseInstancesController ( ICreateCaseInstanceCommandHandler createCaseInstanceCommandHandler , ILaunchCaseInstanceCommandHandler launchCaseInstanceCommandHandler , IConfirmFormCommandHandler confirmFormCommandHandler , IProcessFlowInstanceQueryRepository processFlowInstanceQueryRepository )
1724 {
1825 _createCaseInstanceCommandHandler = createCaseInstanceCommandHandler ;
26+ _launchCaseInstanceCommandHandler = launchCaseInstanceCommandHandler ;
27+ _confirmFormCommandHandler = confirmFormCommandHandler ;
28+ _processFlowInstanceQueryRepository = processFlowInstanceQueryRepository ;
1929 }
2030
2131 [ HttpPost ]
@@ -36,13 +46,54 @@ public async Task<IActionResult> Create([FromBody] CreateCaseInstanceCommand cre
3646 public async Task < IActionResult > Launch ( string id )
3747 {
3848 await _launchCaseInstanceCommandHandler . Handle ( new LaunchCaseInstanceCommand { CaseInstanceId = id } ) ;
39- return null ;
49+ return new OkResult ( ) ;
50+ }
51+
52+ [ HttpPost ( "{id}/confirm/{elt}" ) ]
53+ public async Task < IActionResult > ConfirmForm ( string id , string elt , [ FromBody ] ConfirmFormCommand confirmForm )
54+ {
55+ await _confirmFormCommandHandler . Handle ( new ConfirmFormCommand { CaseInstanceId = id , CaseElementInstanceId = elt } ) ;
56+ return new OkResult ( ) ;
4057 }
4158
4259 [ HttpGet ( "{id}" ) ]
4360 public async Task < IActionResult > Get ( string id )
4461 {
45- return null ;
62+ var flowInstance = await _processFlowInstanceQueryRepository . FindFlowInstanceById ( id ) ;
63+ if ( flowInstance == null )
64+ {
65+ return new NotFoundResult ( ) ;
66+ }
67+
68+ return new OkObjectResult ( ToDto ( flowInstance ) ) ;
69+ }
70+
71+ private static JObject ToDto ( ProcessFlowInstance flowInstance )
72+ {
73+ var result = new JObject
74+ {
75+ { "id" , flowInstance . Id } ,
76+ { "create_datetime" , flowInstance . CreateDateTime } ,
77+ { "status" , Enum . GetName ( typeof ( ProcessFlowInstanceStatus ) , flowInstance . Status ) . ToLowerInvariant ( ) }
78+ } ;
79+ var planItems = new JArray ( ) ;
80+ foreach ( var planItem in flowInstance . Elements . Where ( e => e is CMMNPlanItem ) . Cast < CMMNPlanItem > ( ) )
81+ {
82+ planItems . Add ( ToDto ( planItem ) ) ;
83+ }
84+
85+ result . Add ( "items" , planItems ) ;
86+ return result ;
87+ }
88+
89+ private static JObject ToDto ( CMMNPlanItem planItem )
90+ {
91+ return new JObject
92+ {
93+ { "id" , planItem . Id } ,
94+ { "name" , planItem . Name } ,
95+ { "status" , Enum . GetName ( typeof ( ProcessFlowInstanceElementStatus ) , planItem . Status ) . ToLowerInvariant ( ) }
96+ } ;
4697 }
4798 }
48- }
99+ }
0 commit comments