-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
486 additions
and
498 deletions.
There are no files selected for viewing
152 changes: 74 additions & 78 deletions
152
Nbic.References/Controllers/ReferenceUsageController.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 |
---|---|---|
@@ -1,110 +1,106 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
|
||
namespace Nbic.References.Controllers | ||
namespace Nbic.References.Controllers; | ||
|
||
using Microsoft.AspNetCore.Authorization; | ||
|
||
[Route("api/[controller]")] | ||
[ApiController] | ||
[SwaggerTag("Read, add or delete ReferencesUsages")] | ||
public class ReferenceUsageController : ControllerBase | ||
{ | ||
using Microsoft.AspNetCore.Authorization; | ||
private readonly IReferenceUsageRepository _referenceUsageRepository; | ||
|
||
using EFCore; | ||
public ReferenceUsageController(IReferenceUsageRepository referenceUsageRepository) | ||
{ | ||
_referenceUsageRepository = referenceUsageRepository; | ||
} | ||
|
||
[Route("api/[controller]")] | ||
[ApiController] | ||
[SwaggerTag("Read, add or delete ReferencesUsages")] | ||
public class ReferenceUsageController : ControllerBase | ||
[HttpGet] | ||
public async Task<List<ReferenceUsage>> GetAll(int offset = 0, int limit = 10) | ||
{ | ||
private readonly IReferenceUsageRepository _referenceUsageRepository; | ||
return await _referenceUsageRepository.GetAll(offset, limit); | ||
} | ||
[HttpGet] | ||
[Route("Reference/{id:guid}")] | ||
public async Task<List<ReferenceUsage>> Get(Guid id) | ||
{ | ||
return await _referenceUsageRepository.GetFromReferenceId(id); | ||
} | ||
|
||
public ReferenceUsageController(IReferenceUsageRepository referenceUsageRepository) | ||
{ | ||
_referenceUsageRepository = referenceUsageRepository; | ||
} | ||
[HttpGet] | ||
[Route("Count")] | ||
public async Task<ActionResult<int>> GetCount() | ||
{ | ||
return await _referenceUsageRepository.CountAsync(); | ||
} | ||
|
||
[HttpGet] | ||
public async Task<List<ReferenceUsage>> GetAll(int offset = 0, int limit = 10) | ||
/// <summary> | ||
/// Delete Usage for Reference | ||
/// </summary> | ||
/// <param name="id">Reference Id</param> | ||
/// <returns></returns> | ||
[Authorize("WriteAccess")] | ||
[HttpDelete("{id:guid}")] | ||
[ProducesResponseType(404)] | ||
public Microsoft.AspNetCore.Mvc.ActionResult DeleteAllUsages(Guid id) | ||
{ | ||
try | ||
{ | ||
return await _referenceUsageRepository.GetAll(offset, limit); | ||
_referenceUsageRepository.DeleteForReference(id); | ||
} | ||
[HttpGet] | ||
[Route("Reference/{id}")] | ||
public async Task<List<ReferenceUsage>> Get(Guid id) | ||
catch (NotFoundException e) | ||
{ | ||
return await _referenceUsageRepository.GetFromReferenceId(id); | ||
return NotFound(e); | ||
} | ||
|
||
return Ok(); | ||
} | ||
|
||
[HttpGet] | ||
[Route("Count")] | ||
public async Task<ActionResult<int>> GetCount() | ||
[Authorize("WriteAccess")] | ||
[HttpDelete("{id:guid},{applicationId:int},{userId:guid}")] | ||
public Microsoft.AspNetCore.Mvc.ActionResult DeleteUsage(Guid id, int applicationId, Guid userId) | ||
{ | ||
try | ||
{ | ||
return await _referenceUsageRepository.CountAsync(); | ||
_referenceUsageRepository.DeleteUsage(id, applicationId,userId); | ||
} | ||
|
||
/// <summary> | ||
/// Delete Usage for Reference | ||
/// </summary> | ||
/// <param name="id">Reference Id</param> | ||
/// <returns></returns> | ||
[Authorize("WriteAccess")] | ||
[HttpDelete("{id}")] | ||
[ProducesResponseType(404)] | ||
public Microsoft.AspNetCore.Mvc.ActionResult DeleteAllUsages(Guid id) | ||
catch (NotFoundException e) | ||
{ | ||
try | ||
{ | ||
_referenceUsageRepository.DeleteForReference(id); | ||
} | ||
catch (NotFoundException e) | ||
{ | ||
return NotFound(e); | ||
} | ||
|
||
return Ok(); | ||
return NotFound(e); | ||
} | ||
|
||
[Authorize("WriteAccess")] | ||
[HttpDelete("{id},{applicationId},{userId}")] | ||
public Microsoft.AspNetCore.Mvc.ActionResult DeleteUsage(Guid id, int applicationId, Guid userId) | ||
{ | ||
try | ||
{ | ||
_referenceUsageRepository.DeleteUsage(id, applicationId,userId); | ||
} | ||
catch (NotFoundException e) | ||
{ | ||
return NotFound(e); | ||
} | ||
|
||
return Ok(); | ||
return Ok(); | ||
|
||
} | ||
} | ||
|
||
[Authorize("WriteAccess")] | ||
[HttpPost] | ||
public async Task<ActionResult<ReferenceUsage>> Post([FromBody] ReferenceUsage value) | ||
[Authorize("WriteAccess")] | ||
[HttpPost] | ||
public async Task<ActionResult<ReferenceUsage>> Post([FromBody] ReferenceUsage value) | ||
{ | ||
if (value == null) | ||
{ | ||
if (value == null) | ||
{ | ||
return BadRequest("No data posted"); | ||
} | ||
return BadRequest("No data posted"); | ||
} | ||
|
||
await _referenceUsageRepository.Add(value); | ||
await _referenceUsageRepository.Add(value); | ||
|
||
return value; | ||
} | ||
return value; | ||
} | ||
|
||
[Authorize("WriteAccess")] | ||
[HttpPost("bulk")] | ||
public async Task<ActionResult<bool>> Post(ReferenceUsage[] value) | ||
[Authorize("WriteAccess")] | ||
[HttpPost("bulk")] | ||
public async Task<ActionResult<bool>> Post(ReferenceUsage[] value) | ||
{ | ||
if (value == null) | ||
{ | ||
if (value == null) | ||
{ | ||
return BadRequest("No data posted"); | ||
} | ||
|
||
return await _referenceUsageRepository.AddRange(value); | ||
return BadRequest("No data posted"); | ||
} | ||
|
||
return await _referenceUsageRepository.AddRange(value); | ||
} | ||
} |
Oops, something went wrong.