Skip to content

Commit

Permalink
and more
Browse files Browse the repository at this point in the history
  • Loading branch information
steinho committed Mar 25, 2024
1 parent c4ea4a9 commit 178bcc6
Show file tree
Hide file tree
Showing 5 changed files with 486 additions and 498 deletions.
152 changes: 74 additions & 78 deletions Nbic.References/Controllers/ReferenceUsageController.cs
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);
}
}
Loading

0 comments on commit 178bcc6

Please sign in to comment.