Skip to content

Commit 6ec35a3

Browse files
Thierry Habarthabarthierry-hue
authored andcommitted
Ticket #23 : Can add a case file definition
1 parent 6155735 commit 6ec35a3

301 files changed

Lines changed: 10856 additions & 5964 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Architecture.pptx

1.18 KB
Binary file not shown.

CaseManagement.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseManagement.CMMN.AspNetC
3737
EndProject
3838
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseManagement.Performance", "src\CaseManagement.Performance\CaseManagement.Performance.csproj", "{8EC2090C-1BF1-4557-B62E-EB088699ED8A}"
3939
EndProject
40+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseManagement.Identity", "src\CaseManagement.Identity\CaseManagement.Identity.csproj", "{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE}"
41+
EndProject
4042
Global
4143
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4244
Debug|Any CPU = Debug|Any CPU
@@ -91,6 +93,10 @@ Global
9193
{8EC2090C-1BF1-4557-B62E-EB088699ED8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
9294
{8EC2090C-1BF1-4557-B62E-EB088699ED8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
9395
{8EC2090C-1BF1-4557-B62E-EB088699ED8A}.Release|Any CPU.Build.0 = Release|Any CPU
96+
{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
97+
{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
98+
{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
99+
{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE}.Release|Any CPU.Build.0 = Release|Any CPU
94100
EndGlobalSection
95101
GlobalSection(SolutionProperties) = preSolution
96102
HideSolutionNode = FALSE
@@ -108,6 +114,7 @@ Global
108114
{11F22F1F-2F25-4F13-9F2F-195AFC99B584} = {CD2E7CFE-4E9C-4308-A0D3-41CD5AD90FD8}
109115
{A33A6BDF-FD00-4EFE-BA3F-A73BC63CB321} = {CD2E7CFE-4E9C-4308-A0D3-41CD5AD90FD8}
110116
{8EC2090C-1BF1-4557-B62E-EB088699ED8A} = {D16A3E6D-32B6-44CF-9941-A9BDB9DFC6A7}
117+
{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE} = {4A5D2E88-20E8-4A3F-8527-A4934BC0E11F}
111118
EndGlobalSection
112119
GlobalSection(ExtensibilityGlobals) = postSolution
113120
SolutionGuid = {D2CFBF2E-D493-42F7-B339-01A3070C2B5E}

src/CaseManagement.CMMN.AspNetCore/Apis/CaseDefinitionsController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using CaseManagement.CMMN.Persistence;
55
using CaseManagement.CMMN.Persistence.Parameters;
66
using CaseManagement.CMMN.Persistence.Responses;
7+
using Microsoft.AspNetCore.Authorization;
78
using Microsoft.AspNetCore.Http;
89
using Microsoft.AspNetCore.Mvc;
910
using Newtonsoft.Json.Linq;
@@ -24,6 +25,7 @@ public CaseDefinitionsController(ICaseDefinitionQueryRepository queryRepository)
2425
}
2526

2627
[HttpGet("count")]
28+
[Authorize("get_statistic")]
2729
public async Task<IActionResult> Count()
2830
{
2931
var result = await _queryRepository.Count();
@@ -34,6 +36,7 @@ public async Task<IActionResult> Count()
3436
}
3537

3638
[HttpGet("{id}")]
39+
[Authorize("get_casedefinition")]
3740
public async Task<IActionResult> Get(string id)
3841
{
3942
var result = await _queryRepository.FindById(id);
@@ -46,6 +49,7 @@ public async Task<IActionResult> Get(string id)
4649
}
4750

4851
[HttpGet("{id}/history")]
52+
[Authorize("get_casedefinition")]
4953
public async Task<IActionResult> GetHistory(string id)
5054
{
5155
var result = await _queryRepository.FindHistoryById(id);
@@ -62,6 +66,7 @@ public async Task<IActionResult> GetHistory(string id)
6266
}
6367

6468
[HttpGet("search")]
69+
[Authorize("get_casedefinition")]
6570
public async Task<IActionResult> Search()
6671
{
6772
var query = HttpContext.Request.Query.ToEnumerable();

src/CaseManagement.CMMN.AspNetCore/Apis/CaseFilesController.cs

Lines changed: 96 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
using CaseManagement.CMMN.AspNetCore.Extensions;
2+
using CaseManagement.CMMN.CaseFile.CommandHandlers;
3+
using CaseManagement.CMMN.CaseFile.Commands;
4+
using CaseManagement.CMMN.CaseFile.Exceptions;
25
using CaseManagement.CMMN.Domains.CaseFile;
36
using CaseManagement.CMMN.Extensions;
7+
using CaseManagement.CMMN.Infrastructures;
48
using CaseManagement.CMMN.Persistence;
59
using CaseManagement.CMMN.Persistence.Parameters;
610
using CaseManagement.CMMN.Persistence.Responses;
11+
using Microsoft.AspNetCore.Authorization;
712
using Microsoft.AspNetCore.Http;
813
using Microsoft.AspNetCore.Mvc;
914
using Newtonsoft.Json.Linq;
1015
using System.Collections.Generic;
1116
using System.Linq;
17+
using System.Net;
1218
using System.Threading.Tasks;
1319

1420
namespace 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

Comments
 (0)