11using CaseManagement . CMMN . AspNetCore . Extensions ;
2+ using CaseManagement . CMMN . CaseFile . CommandHandlers ;
3+ using CaseManagement . CMMN . CaseFile . Commands ;
4+ using CaseManagement . CMMN . CaseFile . Exceptions ;
25using CaseManagement . CMMN . Domains . CaseFile ;
36using CaseManagement . CMMN . Extensions ;
7+ using CaseManagement . CMMN . Infrastructures ;
48using CaseManagement . CMMN . Persistence ;
59using CaseManagement . CMMN . Persistence . Parameters ;
610using CaseManagement . CMMN . Persistence . Responses ;
11+ using Microsoft . AspNetCore . Authorization ;
712using Microsoft . AspNetCore . Http ;
813using Microsoft . AspNetCore . Mvc ;
914using Newtonsoft . Json . Linq ;
1015using System . Collections . Generic ;
1116using System . Linq ;
17+ using System . Net ;
1218using System . Threading . Tasks ;
1319
1420namespace CaseManagement . CMMN . AspNetCore . Apis
@@ -17,13 +23,20 @@ namespace CaseManagement.CMMN.AspNetCore.Apis
1723 public class CaseFilesController : Controller
1824 {
1925 private readonly ICaseFileQueryRepository _queryRepository ;
26+ private readonly IUploadCaseFilesCommandHandler _uploadCaseFilesCommandHandler ;
27+ private readonly IAddCaseFileCommandHandler _addCaseFileCommandHandler ;
28+ private readonly IUpdateCaseFileCommandHandler _updateCaseFileCommandHandler ;
2029
21- public CaseFilesController ( ICaseFileQueryRepository queryRepository )
30+ public CaseFilesController ( ICaseFileQueryRepository queryRepository , IUploadCaseFilesCommandHandler uploadCaseFilesCommandHandler , IAddCaseFileCommandHandler addCaseFileCommandHandler , IUpdateCaseFileCommandHandler updateCaseFileCommandHandler )
2231 {
2332 _queryRepository = queryRepository ;
33+ _uploadCaseFilesCommandHandler = uploadCaseFilesCommandHandler ;
34+ _addCaseFileCommandHandler = addCaseFileCommandHandler ;
35+ _updateCaseFileCommandHandler = updateCaseFileCommandHandler ;
2436 }
2537
2638 [ HttpGet ( "count" ) ]
39+ [ Authorize ( "get_statistic" ) ]
2740 public async Task < IActionResult > Count ( )
2841 {
2942 var result = await _queryRepository . Count ( ) ;
@@ -34,6 +47,78 @@ public async Task<IActionResult> Count()
3447 } ) ;
3548 }
3649
50+ [ HttpPost ]
51+ [ Authorize ( "add_casefile" ) ]
52+ public async Task < IActionResult > Create ( [ FromBody ] AddCaseFileCommand parameter )
53+ {
54+ try
55+ {
56+ parameter . NameIdentifier = this . GetNameIdentifier ( ) ;
57+ var result = await _addCaseFileCommandHandler . Handle ( parameter ) ;
58+ var jObj = new JObject
59+ {
60+ { "id" , result }
61+ } ;
62+ return new ContentResult
63+ {
64+ StatusCode = ( int ) HttpStatusCode . Created ,
65+ Content = jObj . ToString ( )
66+ } ;
67+ }
68+ catch ( AggregateValidationException ex )
69+ {
70+ return this . ToError ( ex . Errors , HttpStatusCode . BadRequest , Request ) ;
71+ }
72+ }
73+
74+ [ HttpPost ( "upload" ) ]
75+ [ Authorize ( "add_casefile" ) ]
76+ public async Task < IActionResult > Upload ( [ FromBody ] UploadCaseFilesCommand parameter )
77+ {
78+ try
79+ {
80+ parameter . NameIdentifier = this . GetNameIdentifier ( ) ;
81+ var result = await _uploadCaseFilesCommandHandler . Handle ( parameter ) ;
82+ var jObj = new JObject
83+ {
84+ { "ids" , new JArray ( result ) }
85+ } ;
86+ return new ContentResult
87+ {
88+ StatusCode = ( int ) HttpStatusCode . Created ,
89+ Content = jObj . ToString ( )
90+ } ;
91+ }
92+ catch ( AggregateValidationException ex )
93+ {
94+ return this . ToError ( ex . Errors , HttpStatusCode . BadRequest , Request ) ;
95+ }
96+ }
97+
98+ [ HttpPut ( "{id}" ) ]
99+ public async Task < IActionResult > Update ( string id , [ FromBody ] UpdateCaseFileCommand parameter )
100+ {
101+ try
102+ {
103+ parameter . Id = id ;
104+ parameter . NameIdentifier = this . GetNameIdentifier ( ) ;
105+ await _updateCaseFileCommandHandler . Handle ( parameter ) ;
106+ return new OkResult ( ) ;
107+ }
108+ catch ( UnknownCaseFileException )
109+ {
110+ return new NotFoundResult ( ) ;
111+ }
112+ catch ( UnauthorizedCaseFileException )
113+ {
114+ return new UnauthorizedResult ( ) ;
115+ }
116+ catch ( AggregateValidationException ex )
117+ {
118+ return this . ToError ( ex . Errors , HttpStatusCode . BadRequest , Request ) ;
119+ }
120+ }
121+
37122 [ HttpGet ( "search" ) ]
38123 public async Task < IActionResult > Search ( )
39124 {
@@ -61,14 +146,7 @@ private static JObject ToDto(FindResponse<CaseFileDefinitionAggregate> resp)
61146 { "start_index" , resp . StartIndex } ,
62147 { "total_length" , resp . TotalLength } ,
63148 { "count" , resp . Count } ,
64- { "content" , new JArray ( resp . Content . Select ( r => new JObject
65- {
66- { "id" , r . Id } ,
67- { "name" , r . Name } ,
68- { "description" , r . Description } ,
69- { "payload" , r . Payload } ,
70- { "create_datetime" , r . CreateDateTime }
71- } ) ) }
149+ { "content" , new JArray ( resp . Content . Select ( r => ToDto ( r ) ) ) }
72150 } ;
73151 }
74152
@@ -80,35 +158,25 @@ private static JObject ToDto(CaseFileDefinitionAggregate resp)
80158 { "name" , resp . Name } ,
81159 { "description" , resp . Description } ,
82160 { "payload" , resp . Payload } ,
83- { "create_datetime" , resp . CreateDateTime }
161+ { "create_datetime" , resp . CreateDateTime } ,
162+ { "update_datetime" , resp . UpdateDateTime }
84163 } ;
85164 }
86165
87166 private static FindCaseDefinitionFilesParameter ExtractFindParameter ( IEnumerable < KeyValuePair < string , string > > query )
88167 {
89- int startIndex ;
90- int count ;
91- string orderBy ;
92- FindOrders findOrder ;
168+ string owner ;
169+ string text ;
93170 var parameter = new FindCaseDefinitionFilesParameter ( ) ;
94- if ( query . TryGet ( "start_index" , out startIndex ) )
95- {
96- parameter . StartIndex = startIndex ;
97- }
98-
99- if ( query . TryGet ( "count" , out count ) )
100- {
101- parameter . Count = count ;
102- }
103-
104- if ( query . TryGet ( "order_by" , out orderBy ) )
171+ parameter . ExtractFindParameter ( query ) ;
172+ if ( query . TryGet ( "owner" , out owner ) )
105173 {
106- parameter . OrderBy = orderBy ;
174+ parameter . Owner = owner ;
107175 }
108176
109- if ( query . TryGet ( "order " , out findOrder ) )
177+ if ( query . TryGet ( "text " , out text ) )
110178 {
111- parameter . Order = findOrder ;
179+ parameter . Text = text ;
112180 }
113181
114182 return parameter ;
0 commit comments