-
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
12 changed files
with
3,254 additions
and
11 deletions.
There are no files selected for viewing
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
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
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,72 @@ | ||
using BDMS.Authentication; | ||
using BDMS.Models; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace BDMS.Controllers; | ||
|
||
[ApiController] | ||
[Route("api/v{version:apiVersion}/[controller]")] | ||
public class InstrumentationController : BdmsControllerBase<Instrumentation> | ||
{ | ||
private readonly BdmsContext context; | ||
|
||
public InstrumentationController(BdmsContext context, ILogger<Instrumentation> logger) | ||
: base(context, logger) | ||
{ | ||
this.context = context; | ||
} | ||
|
||
/// <summary> | ||
/// Asynchronously gets the <see cref="Instrumentation"/>s, optionally filtered by <paramref name="completionId"/>. | ||
/// </summary> | ||
/// <param name="completionId">The id of the completion containing the <see cref="Instrumentation"/> to get.</param> | ||
[HttpGet] | ||
[Authorize(Policy = PolicyNames.Viewer)] | ||
public async Task<IEnumerable<Instrumentation>> GetAsync([FromQuery] int? completionId = null) | ||
{ | ||
var instrumentations = context.Instrumentations.AsNoTracking(); | ||
if (completionId != null) | ||
{ | ||
instrumentations = instrumentations.Where(i => i.CompletionId == completionId); | ||
} | ||
|
||
return await instrumentations.ToListAsync().ConfigureAwait(false); | ||
} | ||
|
||
/// <summary> | ||
/// Asynchronously gets the <see cref="Instrumentation"/> with the specified <paramref name="id"/>. | ||
/// </summary> | ||
[HttpGet("{id}")] | ||
[Authorize(Policy = PolicyNames.Viewer)] | ||
public async Task<ActionResult<Instrumentation>> GetByIdAsync(int id) | ||
{ | ||
var instrumentation = await context.Instrumentations | ||
.AsNoTracking() | ||
.SingleOrDefaultAsync(i => i.Id == id) | ||
.ConfigureAwait(false); | ||
|
||
if (instrumentation == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(instrumentation); | ||
} | ||
|
||
/// <inheritdoc /> | ||
[Authorize(Policy = PolicyNames.Viewer)] | ||
public override Task<ActionResult<Instrumentation>> CreateAsync(Instrumentation entity) | ||
=> base.CreateAsync(entity); | ||
|
||
/// <inheritdoc /> | ||
[Authorize(Policy = PolicyNames.Viewer)] | ||
public override Task<ActionResult<Instrumentation>> EditAsync(Instrumentation entity) | ||
=> base.EditAsync(entity); | ||
|
||
/// <inheritdoc /> | ||
[Authorize(Policy = PolicyNames.Viewer)] | ||
public override Task<IActionResult> DeleteAsync(int id) | ||
=> base.DeleteAsync(id); | ||
} |
2 changes: 1 addition & 1 deletion
2
src/api/Migrations/20231211140724_AddCompletionTable.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.