-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create RemediatRRedressController #52
Create RemediatRRedressController #52
- Loading branch information
1 parent
7ce5c2c
commit 926cd33
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
src/Headway.WebApi/Controllers/RemediatRRedressController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using Headway.Core.Attributes; | ||
using Headway.Core.Constants; | ||
using Headway.RemediatR.Core.Interface; | ||
using Headway.RemediatR.Core.Model; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using System.Threading.Tasks; | ||
|
||
namespace Headway.WebApi.Controllers | ||
{ | ||
[DynamicApiController] | ||
public class RemediatRRedressController : ApiControllerBase<RemediatRRedressController> | ||
{ | ||
private readonly IRemediatRRepository remediatRRepository; | ||
|
||
public RemediatRRedressController( | ||
IRemediatRRepository repository, | ||
ILogger<RemediatRRedressController> logger) | ||
: base(repository, logger) | ||
{ | ||
this.remediatRRepository = repository; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> Get() | ||
{ | ||
var authorised = await IsAuthorisedAsync(Roles.REMEDIATR_REDRESS_READ) | ||
.ConfigureAwait(false); | ||
|
||
if (!authorised) | ||
{ | ||
return Unauthorized(); | ||
} | ||
|
||
var redresses = await remediatRRepository | ||
.GetRedressesAsync() | ||
.ConfigureAwait(false); | ||
|
||
return Ok(redresses); | ||
} | ||
|
||
[HttpGet("{redressId}")] | ||
public async Task<IActionResult> Get(int redressId) | ||
{ | ||
var authorised = await IsAuthorisedAsync(Roles.REMEDIATR_REDRESS_READ) | ||
.ConfigureAwait(false); | ||
|
||
if (!authorised) | ||
{ | ||
return Unauthorized(); | ||
} | ||
|
||
var redress = await remediatRRepository | ||
.GetRedressAsync(redressId) | ||
.ConfigureAwait(false); | ||
|
||
return Ok(redress); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> Post([FromBody] Redress redress) | ||
{ | ||
var authorised = await IsAuthorisedAsync(Roles.REMEDIATR_REDRESS_WRITE) | ||
.ConfigureAwait(false); | ||
|
||
if (!authorised) | ||
{ | ||
return Unauthorized(); | ||
} | ||
|
||
var savedRedress = await remediatRRepository | ||
.AddRedressAsync(redress) | ||
.ConfigureAwait(false); | ||
|
||
return Ok(savedRedress); | ||
} | ||
|
||
[HttpPut] | ||
public async Task<IActionResult> Put([FromBody] Redress redress) | ||
{ | ||
var authorised = await IsAuthorisedAsync(Roles.REMEDIATR_REDRESS_WRITE) | ||
.ConfigureAwait(false); | ||
|
||
if (!authorised) | ||
{ | ||
return Unauthorized(); | ||
} | ||
|
||
var savedRedress = await remediatRRepository | ||
.UpdateRedressAsync(redress) | ||
.ConfigureAwait(false); | ||
|
||
return Ok(savedRedress); | ||
} | ||
|
||
[HttpDelete("{redressId}")] | ||
public async Task<IActionResult> Delete(int redressId) | ||
{ | ||
var authorised = await IsAuthorisedAsync(Roles.REMEDIATR_REDRESS_WRITE) | ||
.ConfigureAwait(false); | ||
|
||
if (!authorised) | ||
{ | ||
return Unauthorized(); | ||
} | ||
|
||
var result = await remediatRRepository | ||
.DeleteRedressAsync(redressId) | ||
.ConfigureAwait(false); | ||
|
||
return Ok(result); | ||
} | ||
} | ||
} |