Skip to content

Commit

Permalink
Ticket #30 : Fix UTS + support timer + support repetition rule
Browse files Browse the repository at this point in the history
  • Loading branch information
thabart committed Sep 14, 2020
1 parent c9c0417 commit 2392e49
Show file tree
Hide file tree
Showing 99 changed files with 1,969 additions and 4,174 deletions.
154 changes: 24 additions & 130 deletions src/CaseManagement.CMMN.AspNetCore/Apis/CaseFilesController.cs
Original file line number Diff line number Diff line change
@@ -1,91 +1,45 @@
using CaseManagement.CMMN.AspNetCore.Extensions;
using CaseManagement.CMMN.CaseFile;
using CaseManagement.CMMN.CaseFile.Commands;
using CaseManagement.CMMN.CaseFile.Exceptions;
using CaseManagement.CMMN.Infrastructures;
using CaseManagement.CMMN.CaseFile.Queries;
using CaseManagement.CMMN.Common.Exceptions;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CaseManagement.CMMN.AspNetCore.Apis
{
[Route(CMMNConstants.RouteNames.CaseFiles)]
public class CaseFilesController : Controller
{
private readonly ICaseFileService _caseFileService;
private readonly IMediator _mediator;

public CaseFilesController(ICaseFileService caseFileService)
public CaseFilesController(IMediator mediator)
{
_caseFileService = caseFileService;
_mediator = mediator;
}

[HttpGet("count")]
[Authorize("get_statistic")]
public async Task<IActionResult> Count()
public async Task<IActionResult> Count(CancellationToken token)
{
var result = await _caseFileService.Count();
var result = await _mediator.Send(new CountCaseFileQuery(), token);
return new OkObjectResult(result);
}

[HttpPost("me")]
[Authorize("me_add_casefile")]
public async Task<IActionResult> AddMe([FromBody] AddCaseFileCommand parameter)
{
try
{
parameter.Owner = this.GetNameIdentifier();
var result = await _caseFileService.Add(parameter);
return new ContentResult
{
StatusCode = (int)HttpStatusCode.Created,
Content = result.ToString()
};
}
catch (AggregateValidationException ex)
{
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
}
}

[HttpPost]
[Authorize("add_casefile")]
public async Task<IActionResult> Add([FromBody] AddCaseFileCommand parameter)
public async Task<IActionResult> Add([FromBody] AddCaseFileCommand parameter, CancellationToken token)
{
try
{
var result = await _caseFileService.Add(parameter);
return new ContentResult
{
StatusCode = (int)HttpStatusCode.Created,
Content = result.ToString()
};
}
catch (AggregateValidationException ex)
{
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
}
}

[HttpPut("me/{id}")]
[Authorize("me_update_casefile")]
public async Task<IActionResult> UpdateMe(string id, [FromBody] UpdateCaseFileCommand parameter)
{
try
{
parameter.Id = id;
parameter.Performer = this.GetNameIdentifier();
await _caseFileService.UpdateMe(parameter);
return new OkResult();
}
catch (UnknownCaseFileException)
{
return new NotFoundResult();
}
catch (UnauthorizedCaseFileException)
{
return new UnauthorizedResult();
var result = await _mediator.Send(parameter, token);
return new CreatedResult(string.Empty, result);
}
catch (AggregateValidationException ex)
{
Expand All @@ -95,50 +49,18 @@ public async Task<IActionResult> UpdateMe(string id, [FromBody] UpdateCaseFileCo

[HttpPut("{id}")]
[Authorize("update_casefile")]
public async Task<IActionResult> Update(string id, [FromBody] UpdateCaseFileCommand parameter)
public async Task<IActionResult> Update(string id, [FromBody] UpdateCaseFileCommand parameter, CancellationToken token)
{
try
{
parameter.Id = id;
await _caseFileService.Update(parameter);
await _mediator.Send(parameter, token);
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("me/{id}/publish")]
[Authorize("me_publish_casefile")]
public async Task<IActionResult> PublishMe(string id)
{
try
{
var cmd = new PublishCaseFileCommand
{
Id = id,
Performer = this.GetNameIdentifier()
};
var result = await _caseFileService.PublishMe(cmd);
return new OkObjectResult(result);
}
catch (UnknownCaseFileException)
{
return new NotFoundResult();
}
catch (UnauthorizedCaseFileException)
{
return new UnauthorizedResult();
}
catch (AggregateValidationException ex)
{
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
Expand All @@ -147,76 +69,48 @@ public async Task<IActionResult> PublishMe(string id)

[HttpGet("{id}/publish")]
[Authorize("publish_casefile")]
public async Task<IActionResult> Publish(string id)
public async Task<IActionResult> Publish(string id, CancellationToken token)
{
try
{
var cmd = new PublishCaseFileCommand
{
Id = id
};
var result = await _caseFileService.Publish(cmd);
var result = await _mediator.Send(cmd, token);
return new OkObjectResult(result);
}
catch (UnknownCaseFileException)
{
return new NotFoundResult();
}
catch (UnauthorizedCaseFileException)
{
return new UnauthorizedResult();
}
catch (AggregateValidationException ex)
{
return this.ToError(ex.Errors, HttpStatusCode.BadRequest, Request);
}
}

[HttpGet("search")]
[HttpPost("search")]
[Authorize("get_casefile")]
public async Task<IActionResult> Search()
public async Task<IActionResult> Search([FromBody] SearchCaseFileQuery query, CancellationToken token)
{
var query = HttpContext.Request.Query.ToEnumerable();
var result = await _caseFileService.Search(query);
var result = await _mediator.Send(query, token);
return new OkObjectResult(result);
}

[HttpGet("me/{id}")]
[Authorize("me_get_casefile")]
public async Task<IActionResult> GetMe(string id)
{
try
{
var result = await _caseFileService.GetMe(id, this.GetNameIdentifier());
return new OkObjectResult(result);
}
catch(UnknownCaseFileException)
{
return new NotFoundResult();
}
catch(UnauthorizedCaseFileException)
{
return new UnauthorizedResult();
}
}

[HttpGet("{id}")]
[Authorize("get_casefile")]
public async Task<IActionResult> Get(string id)
public async Task<IActionResult> Get(string id, CancellationToken token)
{
try
{
var result = await _caseFileService.Get(id);
var result = await _mediator.Send(new GetCaseFileQuery { Id = id }, token);
return new OkObjectResult(result);
}
catch (UnknownCaseFileException)
{
return new NotFoundResult();
}
catch (UnauthorizedCaseFileException)
{
return new UnauthorizedResult();
}
}
}
}
Loading

0 comments on commit 2392e49

Please sign in to comment.