Skip to content

Commit

Permalink
Update Ardalis.ApiEndpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
markusrt committed Jan 20, 2024
1 parent 1b5d7e8 commit 7d60638
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 40 deletions.
5 changes: 3 additions & 2 deletions NRZMyk.Server/Controllers/Account/AssignOrganization.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -13,7 +14,7 @@
namespace NRZMyk.Server.Controllers.Account
{
[Authorize(Roles = nameof(Role.Admin))]
public class AssignOrganization : BaseAsyncEndpoint<List<RemoteAccount>, int>
public class AssignOrganization : EndpointBaseAsync.WithRequest<List<RemoteAccount>>.WithActionResult<int>
{
private readonly IAsyncRepository<RemoteAccount> _accountRepository;
private readonly ILogger<AssignOrganization> _logger;
Expand All @@ -30,7 +31,7 @@ public AssignOrganization(IAsyncRepository<RemoteAccount> accountRepository, ILo
OperationId = "account.assign-organization",
Tags = new[] { "AccountEndpoints" })
]
public override async Task<ActionResult<int>> HandleAsync(List<RemoteAccount> accountsToUpdate)
public override async Task<ActionResult<int>> HandleAsync(List<RemoteAccount> accountsToUpdate, CancellationToken cancellationToken = new())
{
var updateCount = 0;
foreach (var accountToUpdate in accountsToUpdate)
Expand Down
7 changes: 4 additions & 3 deletions NRZMyk.Server/Controllers/Account/Connect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -13,7 +14,7 @@
namespace NRZMyk.Server.Controllers.Account
{
[Authorize]
public class Connect : BaseAsyncEndpoint<ConnectedAccount>
public class Connect : EndpointBaseAsync.WithoutRequest.WithActionResult<ConnectedAccount>
{
private readonly IAsyncRepository<RemoteAccount> _accountRepository;
private readonly IMapper _mapper;
Expand All @@ -32,7 +33,7 @@ public Connect(IAsyncRepository<RemoteAccount> accountRepository, IMapper mapper
OperationId = "account.connect",
Tags = new[] { "AccountEndpoints" })
]
public override async Task<ActionResult<ConnectedAccount>> HandleAsync()
public override async Task<ActionResult<ConnectedAccount>> HandleAsync(CancellationToken cancellationToken = new())
{
var connectingAccount = _mapper.Map<RemoteAccount>(User);
var storedAccount = await _accountRepository.FirstOrDefaultAsync(
Expand Down
5 changes: 3 additions & 2 deletions NRZMyk.Server/Controllers/Account/ListOrganizations.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -11,7 +12,7 @@
namespace NRZMyk.Server.Controllers.Account
{
[Authorize(Roles = nameof(Role.SuperUser))]
public class List : BaseAsyncEndpoint<List<RemoteAccount>>
public class List : EndpointBaseAsync.WithoutRequest.WithActionResult<List<RemoteAccount>>
{
private readonly IAsyncRepository<Organization> _organizationRepository;

Expand All @@ -26,7 +27,7 @@ public List(IAsyncRepository<Organization> organizationRepository)
OperationId = "organization.list",
Tags = new[] { "AccountEndpoints" })
]
public override async Task<ActionResult<List<RemoteAccount>>> HandleAsync()
public override async Task<ActionResult<List<RemoteAccount>>> HandleAsync(CancellationToken cancellationToken = new())
{
var items = await _organizationRepository.ListAllAsync().ConfigureAwait(false);
return Ok(items);
Expand Down
5 changes: 3 additions & 2 deletions NRZMyk.Server/Controllers/Account/ListUsers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -12,7 +13,7 @@
namespace NRZMyk.Server.Controllers.Account
{
[Authorize(Roles = nameof(Role.Admin))]
public class ListUsers : BaseAsyncEndpoint<List<RemoteAccount>>
public class ListUsers : EndpointBaseAsync.WithoutRequest.WithActionResult<List<RemoteAccount>>
{
private readonly IAsyncRepository<RemoteAccount> _accountRepository;
private readonly IUserService _userService;
Expand All @@ -29,7 +30,7 @@ public ListUsers(IAsyncRepository<RemoteAccount> accountRepository, IUserService
OperationId = "account.list",
Tags = new[] { "AccountEndpoints" })
]
public override async Task<ActionResult<List<RemoteAccount>>> HandleAsync()
public override async Task<ActionResult<List<RemoteAccount>>> HandleAsync(CancellationToken cancellationToken = new())
{
var items = await _accountRepository.ListAllAsync().ConfigureAwait(false);
await _userService.GetRolesViaGraphApi(items);
Expand Down
5 changes: 3 additions & 2 deletions NRZMyk.Server/Controllers/ClinicalBreakpoints/Create.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using AutoMapper;
Expand All @@ -12,7 +13,7 @@
namespace NRZMyk.Server.Controllers.ClinicalBreakpoints
{
[Authorize(Roles=nameof(Role.Admin))]
public class Create : BaseAsyncEndpoint<CreateClinicalBreakpointRequest, ClinicalBreakpoint>
public class Create : EndpointBaseAsync.WithRequest<CreateClinicalBreakpointRequest>.WithActionResult<ClinicalBreakpoint>
{
private readonly IAsyncRepository<ClinicalBreakpoint> _clinicalBreakpointRepository;
private readonly IMapper _mapper;
Expand All @@ -29,7 +30,7 @@ public Create(IAsyncRepository<ClinicalBreakpoint> clinicalBreakpointRepository,
OperationId = "clinical-breakpoints.create",
Tags = new[] { "SharedEndpoints" })
]
public override async Task<ActionResult<ClinicalBreakpoint>> HandleAsync(CreateClinicalBreakpointRequest request)
public override async Task<ActionResult<ClinicalBreakpoint>> HandleAsync(CreateClinicalBreakpointRequest request, CancellationToken cancellationToken = new())
{
var newEntry = _mapper.Map<ClinicalBreakpoint>(request);
return await _clinicalBreakpointRepository.AddAsync(newEntry).ConfigureAwait(false);
Expand Down
6 changes: 4 additions & 2 deletions NRZMyk.Server/Controllers/ClinicalBreakpoints/List.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NRZMyk.Services.Data.Entities;
using NRZMyk.Services.Interfaces;
using NRZMyk.Services.Models;
using NRZMyk.Services.Services;
using NRZMyk.Services.Specifications;
using Swashbuckle.AspNetCore.Annotations;

namespace NRZMyk.Server.Controllers.ClinicalBreakpoints
{
[Authorize]
public class List : BaseAsyncEndpoint<ListClinicalBreakpointsRequest, List<ClinicalBreakpoint>>
public class List : EndpointBaseAsync.WithRequest<ListClinicalBreakpointsRequest>.WithActionResult<List<ClinicalBreakpoint>>
{
private readonly IAsyncRepository<ClinicalBreakpoint> _clinicalBreakpointRepository;

Expand All @@ -27,7 +29,7 @@ public List(IAsyncRepository<ClinicalBreakpoint> clinicalBreakpointRepository)
OperationId = "clinical-breakpoints.list",
Tags = new[] { "SharedEndpoints" })
]
public override async Task<ActionResult<List<ClinicalBreakpoint>>> HandleAsync([FromQuery]ListClinicalBreakpointsRequest request)
public override async Task<ActionResult<List<ClinicalBreakpoint>>> HandleAsync([FromQuery]ListClinicalBreakpointsRequest request, CancellationToken cancellationToken = new())
{
var filter = new ClinicalBreakpointFilterSpecification(request.Species);
var items = await _clinicalBreakpointRepository.ListAsync(filter).ConfigureAwait(false);
Expand Down
5 changes: 3 additions & 2 deletions NRZMyk.Server/Controllers/SentinelEntries/Create.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using AutoMapper;
Expand All @@ -20,7 +21,7 @@
namespace NRZMyk.Server.Controllers.SentinelEntries
{
[Authorize(Roles = nameof(Role.User), Policy = Policies.AssignedToOrganization)]
public class Create : BaseAsyncEndpoint<SentinelEntryRequest, SentinelEntry>
public class Create : EndpointBaseAsync.WithRequest<SentinelEntryRequest>.WithActionResult<SentinelEntry>
{
private readonly ISentinelEntryRepository _sentinelEntryRepository;
private readonly IMapper _mapper;
Expand All @@ -39,7 +40,7 @@ public Create(ISentinelEntryRepository sentinelEntryRepository, IMapper mapper)
OperationId = "catalog-entries.create",
Tags = new[] { "SentinelEndpoints" })
]
public override async Task<ActionResult<SentinelEntry>> HandleAsync(SentinelEntryRequest request )
public override async Task<ActionResult<SentinelEntry>> HandleAsync(SentinelEntryRequest request, CancellationToken cancellationToken = new())
{
var newEntry = _mapper.Map<SentinelEntry>(request);

Expand Down
7 changes: 4 additions & 3 deletions NRZMyk.Server/Controllers/SentinelEntries/CryoArchive.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -13,7 +14,7 @@
namespace NRZMyk.Server.Controllers.SentinelEntries
{
[Authorize(Roles = nameof(Role.SuperUser))]
public class CryoArchive : BaseAsyncEndpoint<CryoArchiveRequest, SentinelEntry>
public class CryoArchive : EndpointBaseAsync.WithRequest<CryoArchiveRequest>.WithActionResult<SentinelEntry>
{
private readonly IAsyncRepository<SentinelEntry> _sentinelEntryRepository;
private readonly IMapper _mapper;
Expand All @@ -31,7 +32,7 @@ public CryoArchive(IAsyncRepository<SentinelEntry> sentinelEntryRepository,
OperationId = "sentinel-entries.cryo-archive",
Tags = new[] { "SentinelEndpoints" })
]
public override async Task<ActionResult<SentinelEntry>> HandleAsync(CryoArchiveRequest request)
public override async Task<ActionResult<SentinelEntry>> HandleAsync(CryoArchiveRequest request, CancellationToken cancellationToken = new())
{
var existingItem = await _sentinelEntryRepository.FirstOrDefaultAsync(
new SentinelEntryIncludingTestsSpecification(request.Id));
Expand Down
5 changes: 3 additions & 2 deletions NRZMyk.Server/Controllers/SentinelEntries/Delete.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -15,7 +16,7 @@
namespace NRZMyk.Server.Controllers.SentinelEntries
{
[Authorize(Roles = nameof(Role.User), Policy = Policies.AssignedToOrganization)]
public class Delete : BaseAsyncEndpoint<int, int>
public class Delete : EndpointBaseAsync.WithRequest<int>.WithActionResult<int>
{
private readonly IAsyncRepository<SentinelEntry> _sentinelEntryRepository;
private readonly IAsyncRepository<AntimicrobialSensitivityTest> _sensitivityTestRepository;
Expand All @@ -33,7 +34,7 @@ public Delete(IAsyncRepository<SentinelEntry> sentinelEntryRepository,
OperationId = "sentinel-entries.DeleteById",
Tags = new[] { "SentinelEndpoints" })
]
public override async Task<ActionResult<int>> HandleAsync([FromRoute] int sentinelEntryId)
public override async Task<ActionResult<int>> HandleAsync([FromRoute] int sentinelEntryId, CancellationToken cancellationToken = new())
{
var sentinelEntry = (await _sentinelEntryRepository.FirstOrDefaultAsync(
new SentinelEntryIncludingTestsSpecification(sentinelEntryId)));
Expand Down
7 changes: 4 additions & 3 deletions NRZMyk.Server/Controllers/SentinelEntries/GetById.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -16,7 +17,7 @@
namespace NRZMyk.Server.Controllers.SentinelEntries
{
[Authorize(Roles = nameof(Role.User), Policy = Policies.AssignedToOrganization)]
public class GetById : BaseAsyncEndpoint<int, SentinelEntryResponse>
public class GetById : EndpointBaseAsync.WithRequest<int>.WithActionResult<SentinelEntryResponse>
{
private readonly IAsyncRepository<SentinelEntry> _sentinelEntryRepository;
private readonly IMapper _mapper;
Expand All @@ -33,7 +34,7 @@ public GetById(IAsyncRepository<SentinelEntry> sentinelEntryRepository, IMapper
OperationId = "sentinel-entries.GetById",
Tags = new[] { "SentinelEndpoints" })
]
public override async Task<ActionResult<SentinelEntryResponse>> HandleAsync([FromRoute] int sentinelEntryId)
public override async Task<ActionResult<SentinelEntryResponse>> HandleAsync([FromRoute] int sentinelEntryId, CancellationToken cancellationToken = new())
{
var sentinelEntry = (await _sentinelEntryRepository.FirstOrDefaultAsync(
new SentinelEntryIncludingTestsSpecification(sentinelEntryId)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using Ardalis.Specification;
Expand All @@ -13,7 +14,7 @@
namespace NRZMyk.Server.Controllers.SentinelEntries
{
[Authorize(Roles = nameof(Role.SuperUser))]
public class ListByOrganization : BaseAsyncEndpoint<int, List<SentinelEntry>>
public class ListByOrganization : EndpointBaseAsync.WithRequest<int>.WithActionResult<List<SentinelEntry>>
{
private readonly IAsyncRepository<SentinelEntry> _sentinelEntryRepository;

Expand All @@ -28,7 +29,7 @@ public ListByOrganization(IAsyncRepository<SentinelEntry> sentinelEntryRepositor
OperationId = "sentinel-entries.ListByOrganization",
Tags = new[] { "SentinelEndpoints" })
]
public override async Task<ActionResult<List<SentinelEntry>>> HandleAsync([FromRoute] int organizationId)
public override async Task<ActionResult<List<SentinelEntry>>> HandleAsync([FromRoute] int organizationId, CancellationToken cancellationToken = new())
{
var filter = organizationId == -1
? (ISpecification<SentinelEntry>) new AllSentinelEntriesFilterSpecification()
Expand Down
5 changes: 3 additions & 2 deletions NRZMyk.Server/Controllers/SentinelEntries/ListPaged.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -14,7 +15,7 @@
namespace NRZMyk.Server.Controllers.SentinelEntries
{
[Authorize(Roles = nameof(Role.User), Policy = Policies.AssignedToOrganization)]
public class ListPaged : BaseAsyncEndpoint<ListPagedSentinelEntryRequest, ListPagedSentinelEntryResponse>
public class ListPaged : EndpointBaseAsync.WithRequest<ListPagedSentinelEntryRequest>.WithActionResult<ListPagedSentinelEntryResponse>
{
private readonly IAsyncRepository<SentinelEntry> _sentinelEntryRepository;

Expand All @@ -29,7 +30,7 @@ public ListPaged(IAsyncRepository<SentinelEntry> sentinelEntryRepository)
OperationId = "sentinel-entries.ListPaged",
Tags = new[] { "SentinelEndpoints" })
]
public override async Task<ActionResult<ListPagedSentinelEntryResponse>> HandleAsync([FromQuery]ListPagedSentinelEntryRequest request)
public override async Task<ActionResult<ListPagedSentinelEntryResponse>> HandleAsync([FromQuery]ListPagedSentinelEntryRequest request, CancellationToken cancellationToken = new())
{
var organizationId = User.Claims.OrganizationId();
var response = new ListPagedSentinelEntryResponse();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -13,7 +14,7 @@
namespace NRZMyk.Server.Controllers.SentinelEntries
{
[Authorize(Roles = nameof(Role.User))]
public class OtherHospitalDepartment : BaseAsyncEndpoint<List<string>>
public class OtherHospitalDepartment : EndpointBaseAsync.WithoutRequest.WithActionResult<List<string>>
{
private readonly ISentinelEntryRepository _sentinelEntryRepository;

Expand All @@ -28,7 +29,7 @@ public OtherHospitalDepartment(ISentinelEntryRepository sentinelEntryRepository)
OperationId = "sentinel-entries.OtherHospitalDepartment",
Tags = new[] { "SentinelEndpoints" })
]
public override async Task<ActionResult<List<string>>> HandleAsync()
public override async Task<ActionResult<List<string>>> HandleAsync(CancellationToken cancellationToken = new())
{
var otherMaterials = await _sentinelEntryRepository.Other(s => s.OtherHospitalDepartment).ConfigureAwait(false);
return Ok(otherMaterials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -19,7 +20,7 @@
namespace NRZMyk.Server.Controllers.SentinelEntries
{
[Authorize(Roles = nameof(Role.User), Policy = Policies.AssignedToOrganization)]
public class OtherLaboratoryNumbers : BaseAsyncEndpoint<List<string>>
public class OtherLaboratoryNumbers : EndpointBaseAsync.WithoutRequest.WithActionResult<List<string>>
{
private readonly ISentinelEntryRepository _sentinelEntryRepository;

Expand All @@ -34,7 +35,7 @@ public OtherLaboratoryNumbers(ISentinelEntryRepository sentinelEntryRepository)
OperationId = "sentinel-entries.OtherLaboratoryNumbers",
Tags = new[] { "SentinelEndpoints" })
]
public override async Task<ActionResult<List<string>>> HandleAsync()
public override async Task<ActionResult<List<string>>> HandleAsync(CancellationToken cancellationToken = new())
{
var organizationId = User.Claims.OrganizationId();
var entriesForOrganization = await _sentinelEntryRepository.ListAsync(new SentinelEntryFilterSpecification(organizationId)).ConfigureAwait(false);
Expand Down
5 changes: 3 additions & 2 deletions NRZMyk.Server/Controllers/SentinelEntries/OtherMaterials.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -13,7 +14,7 @@
namespace NRZMyk.Server.Controllers.SentinelEntries
{
[Authorize(Roles = nameof(Role.User))]
public class OtherMaterials : BaseAsyncEndpoint<List<string>>
public class OtherMaterials : EndpointBaseAsync.WithoutRequest.WithActionResult<List<string>>
{
private readonly ISentinelEntryRepository _sentinelEntryRepository;

Expand All @@ -28,7 +29,7 @@ public OtherMaterials(ISentinelEntryRepository sentinelEntryRepository)
OperationId = "sentinel-entries.OtherMaterials",
Tags = new[] { "SentinelEndpoints" })
]
public override async Task<ActionResult<List<string>>> HandleAsync()
public override async Task<ActionResult<List<string>>> HandleAsync(CancellationToken cancellationToken = new())
{
var otherMaterials = await _sentinelEntryRepository.Other(s => s.OtherMaterial).ConfigureAwait(false);
return Ok(otherMaterials);
Expand Down
Loading

0 comments on commit 7d60638

Please sign in to comment.