Skip to content

Commit

Permalink
Ticket #23 : Can add a case file definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Habart authored and thabart committed Feb 2, 2020
1 parent 6155735 commit 6ec35a3
Show file tree
Hide file tree
Showing 301 changed files with 10,856 additions and 5,964 deletions.
Binary file modified Architecture.pptx
Binary file not shown.
7 changes: 7 additions & 0 deletions CaseManagement.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseManagement.CMMN.AspNetC
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseManagement.Performance", "src\CaseManagement.Performance\CaseManagement.Performance.csproj", "{8EC2090C-1BF1-4557-B62E-EB088699ED8A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaseManagement.Identity", "src\CaseManagement.Identity\CaseManagement.Identity.csproj", "{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -91,6 +93,10 @@ Global
{8EC2090C-1BF1-4557-B62E-EB088699ED8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EC2090C-1BF1-4557-B62E-EB088699ED8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EC2090C-1BF1-4557-B62E-EB088699ED8A}.Release|Any CPU.Build.0 = Release|Any CPU
{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -108,6 +114,7 @@ Global
{11F22F1F-2F25-4F13-9F2F-195AFC99B584} = {CD2E7CFE-4E9C-4308-A0D3-41CD5AD90FD8}
{A33A6BDF-FD00-4EFE-BA3F-A73BC63CB321} = {CD2E7CFE-4E9C-4308-A0D3-41CD5AD90FD8}
{8EC2090C-1BF1-4557-B62E-EB088699ED8A} = {D16A3E6D-32B6-44CF-9941-A9BDB9DFC6A7}
{93F12F7C-8657-4725-B6A8-A7AEDCEEC8CE} = {4A5D2E88-20E8-4A3F-8527-A4934BC0E11F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D2CFBF2E-D493-42F7-B339-01A3070C2B5E}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CaseManagement.CMMN.Persistence;
using CaseManagement.CMMN.Persistence.Parameters;
using CaseManagement.CMMN.Persistence.Responses;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
Expand All @@ -24,6 +25,7 @@ public CaseDefinitionsController(ICaseDefinitionQueryRepository queryRepository)
}

[HttpGet("count")]
[Authorize("get_statistic")]
public async Task<IActionResult> Count()
{
var result = await _queryRepository.Count();
Expand All @@ -34,6 +36,7 @@ public async Task<IActionResult> Count()
}

[HttpGet("{id}")]
[Authorize("get_casedefinition")]
public async Task<IActionResult> Get(string id)
{
var result = await _queryRepository.FindById(id);
Expand All @@ -46,6 +49,7 @@ public async Task<IActionResult> Get(string id)
}

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

[HttpGet("search")]
[Authorize("get_casedefinition")]
public async Task<IActionResult> Search()
{
var query = HttpContext.Request.Query.ToEnumerable();
Expand Down
124 changes: 96 additions & 28 deletions src/CaseManagement.CMMN.AspNetCore/Apis/CaseFilesController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
using CaseManagement.CMMN.AspNetCore.Extensions;
using CaseManagement.CMMN.CaseFile.CommandHandlers;
using CaseManagement.CMMN.CaseFile.Commands;
using CaseManagement.CMMN.CaseFile.Exceptions;
using CaseManagement.CMMN.Domains.CaseFile;
using CaseManagement.CMMN.Extensions;
using CaseManagement.CMMN.Infrastructures;
using CaseManagement.CMMN.Persistence;
using CaseManagement.CMMN.Persistence.Parameters;
using CaseManagement.CMMN.Persistence.Responses;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;

namespace CaseManagement.CMMN.AspNetCore.Apis
Expand All @@ -17,13 +23,20 @@ namespace CaseManagement.CMMN.AspNetCore.Apis
public class CaseFilesController : Controller
{
private readonly ICaseFileQueryRepository _queryRepository;
private readonly IUploadCaseFilesCommandHandler _uploadCaseFilesCommandHandler;
private readonly IAddCaseFileCommandHandler _addCaseFileCommandHandler;
private readonly IUpdateCaseFileCommandHandler _updateCaseFileCommandHandler;

public CaseFilesController(ICaseFileQueryRepository queryRepository)
public CaseFilesController(ICaseFileQueryRepository queryRepository, IUploadCaseFilesCommandHandler uploadCaseFilesCommandHandler, IAddCaseFileCommandHandler addCaseFileCommandHandler, IUpdateCaseFileCommandHandler updateCaseFileCommandHandler)
{
_queryRepository = queryRepository;
_uploadCaseFilesCommandHandler = uploadCaseFilesCommandHandler;
_addCaseFileCommandHandler = addCaseFileCommandHandler;
_updateCaseFileCommandHandler = updateCaseFileCommandHandler;
}

[HttpGet("count")]
[Authorize("get_statistic")]
public async Task<IActionResult> Count()
{
var result = await _queryRepository.Count();
Expand All @@ -34,6 +47,78 @@ public async Task<IActionResult> Count()
});
}

[HttpPost]
[Authorize("add_casefile")]
public async Task<IActionResult> Create([FromBody] AddCaseFileCommand parameter)
{
try
{
parameter.NameIdentifier = this.GetNameIdentifier();
var result = await _addCaseFileCommandHandler.Handle(parameter);
var jObj = new JObject
{
{ "id", result }
};
return new ContentResult
{
StatusCode = (int)HttpStatusCode.Created,
Content = jObj.ToString()
};
}
catch (AggregateValidationException ex)
{
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
}
}

[HttpPost("upload")]
[Authorize("add_casefile")]
public async Task<IActionResult> Upload([FromBody] UploadCaseFilesCommand parameter)
{
try
{
parameter.NameIdentifier = this.GetNameIdentifier();
var result = await _uploadCaseFilesCommandHandler.Handle(parameter);
var jObj = new JObject
{
{ "ids", new JArray(result) }
};
return new ContentResult
{
StatusCode = (int)HttpStatusCode.Created,
Content = jObj.ToString()
};
}
catch (AggregateValidationException ex)
{
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
}
}

[HttpPut("{id}")]
public async Task<IActionResult> Update(string id, [FromBody] UpdateCaseFileCommand parameter)
{
try
{
parameter.Id = id;
parameter.NameIdentifier = this.GetNameIdentifier();
await _updateCaseFileCommandHandler.Handle(parameter);
return new OkResult();
}
catch(UnknownCaseFileException)
{
return new NotFoundResult();
}
catch(UnauthorizedCaseFileException)
{
return new UnauthorizedResult();
}
catch (AggregateValidationException ex)
{
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
}
}

[HttpGet("search")]
public async Task<IActionResult> Search()
{
Expand Down Expand Up @@ -61,14 +146,7 @@ private static JObject ToDto(FindResponse<CaseFileDefinitionAggregate> resp)
{ "start_index", resp.StartIndex },
{ "total_length", resp.TotalLength },
{ "count", resp.Count },
{ "content", new JArray(resp.Content.Select(r => new JObject
{
{ "id", r.Id },
{ "name", r.Name },
{ "description", r.Description },
{ "payload", r.Payload },
{ "create_datetime", r.CreateDateTime }
})) }
{ "content", new JArray(resp.Content.Select(r => ToDto(r))) }
};
}

Expand All @@ -80,35 +158,25 @@ private static JObject ToDto(CaseFileDefinitionAggregate resp)
{ "name", resp.Name },
{ "description", resp.Description },
{ "payload", resp.Payload },
{ "create_datetime", resp.CreateDateTime }
{ "create_datetime", resp.CreateDateTime },
{ "update_datetime", resp.UpdateDateTime }
};
}

private static FindCaseDefinitionFilesParameter ExtractFindParameter(IEnumerable<KeyValuePair<string, string>> query)
{
int startIndex;
int count;
string orderBy;
FindOrders findOrder;
string owner;
string text;
var parameter = new FindCaseDefinitionFilesParameter();
if (query.TryGet("start_index", out startIndex))
{
parameter.StartIndex = startIndex;
}

if (query.TryGet("count", out count))
{
parameter.Count = count;
}

if (query.TryGet("order_by", out orderBy))
parameter.ExtractFindParameter(query);
if (query.TryGet("owner", out owner))
{
parameter.OrderBy = orderBy;
parameter.Owner = owner;
}

if (query.TryGet("order", out findOrder))
if (query.TryGet("text", out text))
{
parameter.Order = findOrder;
parameter.Text = text;
}

return parameter;
Expand Down
Loading

0 comments on commit 6ec35a3

Please sign in to comment.