Skip to content

Commit

Permalink
chore: clean up AgreementController (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
trulshj authored Jan 6, 2025
1 parent 3443fb5 commit 39b4eee
Show file tree
Hide file tree
Showing 35 changed files with 569 additions and 486 deletions.
32 changes: 16 additions & 16 deletions backend/Api/Agreements/AgreementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public class AgreementController(
[HttpGet]
[Route("{agreementId:int}")]
public async Task<ActionResult<AgreementReadModel>> GetAgreement([FromRoute] string orgUrlKey,
[FromRoute] int agreementId, CancellationToken ct)
[FromRoute] int agreementId, CancellationToken cancellationToken)
{
var selectedOrg = await organisationRepository.GetOrganizationByUrlKey(orgUrlKey, ct);
var selectedOrg = await organisationRepository.GetOrganizationByUrlKey(orgUrlKey, cancellationToken);
if (selectedOrg is null) return NotFound(SelectedOrganizationNotFound);

var agreement = await agreementsRepository.GetAgreementById(agreementId, ct);
var agreement = await agreementsRepository.GetAgreementById(agreementId, cancellationToken);

if (agreement is null) return NotFound();

Expand All @@ -54,12 +54,12 @@ public async Task<ActionResult<AgreementReadModel>> GetAgreement([FromRoute] str
[HttpGet]
[Route("engagement/{engagementId:int}")]
public async Task<ActionResult<List<AgreementReadModel>>> GetAgreementsByEngagement([FromRoute] string orgUrlKey,
[FromRoute] int engagementId, CancellationToken ct)
[FromRoute] int engagementId, CancellationToken cancellationToken)
{
var selectedOrg = await organisationRepository.GetOrganizationByUrlKey(orgUrlKey, ct);
var selectedOrg = await organisationRepository.GetOrganizationByUrlKey(orgUrlKey, cancellationToken);
if (selectedOrg is null) return NotFound(SelectedOrganizationNotFound);

var agreements = await agreementsRepository.GetAgreementsByEngagementId(engagementId, ct);
var agreements = await agreementsRepository.GetAgreementsByEngagementId(engagementId, cancellationToken);

var responseModels = agreements.Select(agreement => new AgreementReadModel(
AgreementId: agreement.Id,
Expand All @@ -82,12 +82,12 @@ public async Task<ActionResult<List<AgreementReadModel>>> GetAgreementsByEngagem
[HttpGet]
[Route("customer/{customerId:int}")]
public async Task<ActionResult<List<AgreementReadModel>>> GetAgreementsByCustomer([FromRoute] string orgUrlKey,
[FromRoute] int customerId, CancellationToken ct)
[FromRoute] int customerId, CancellationToken cancellationToken)
{
var selectedOrg = await organisationRepository.GetOrganizationByUrlKey(orgUrlKey, ct);
var selectedOrg = await organisationRepository.GetOrganizationByUrlKey(orgUrlKey, cancellationToken);
if (selectedOrg is null) return NotFound(SelectedOrganizationNotFound);

var agreements = await agreementsRepository.GetAgreementsByCustomerId(customerId, ct);
var agreements = await agreementsRepository.GetAgreementsByCustomerId(customerId, cancellationToken);

var responseModels = agreements.Select(agreement => new AgreementReadModel(
AgreementId: agreement.Id,
Expand Down Expand Up @@ -283,28 +283,28 @@ public async Task<ActionResult<AgreementReadModel>> Put([FromRoute] string orgUr

[HttpDelete]
[Route("{agreementId:int}")]
public async Task<ActionResult> Delete([FromRoute] string orgUrlKey, [FromRoute] int agreementId, CancellationToken ct)
public async Task<ActionResult> Delete([FromRoute] string orgUrlKey, [FromRoute] int agreementId, CancellationToken cancellationToken)
{
var selectedOrg = await organisationRepository.GetOrganizationByUrlKey(orgUrlKey, ct);
var selectedOrg = await organisationRepository.GetOrganizationByUrlKey(orgUrlKey, cancellationToken);
if (selectedOrg is null) return NotFound(SelectedOrganizationNotFound);

var agreement = await agreementsRepository.GetAgreementById(agreementId, ct);
var agreement = await agreementsRepository.GetAgreementById(agreementId, cancellationToken);
if (agreement is null) return NotFound();

await agreementsRepository.DeleteAgreementAsync(agreementId, ct);
await agreementsRepository.DeleteAgreementAsync(agreementId, cancellationToken);
cache.Remove($"consultantCacheKey/{orgUrlKey}");

return Ok("Deleted");
}

[HttpGet]
[Route("priceAdjustmentIndexes")]
public async Task<ActionResult<List<string>>> GetPriceAdjustmentIndexes([FromRoute] string orgUrlKey, CancellationToken ct)
public async Task<ActionResult<List<string>>> GetPriceAdjustmentIndexes([FromRoute] string orgUrlKey, CancellationToken cancellationToken)
{
var selectedOrg = await organisationRepository.GetOrganizationByUrlKey(orgUrlKey, ct);
var selectedOrg = await organisationRepository.GetOrganizationByUrlKey(orgUrlKey, cancellationToken);
if (selectedOrg is null) return NotFound(SelectedOrganizationNotFound);

var priceAdjustmentIndexes = await agreementsRepository.GetPriceAdjustmentIndexesAsync(ct);
var priceAdjustmentIndexes = await agreementsRepository.GetPriceAdjustmentIndexesAsync(cancellationToken);

return Ok(priceAdjustmentIndexes);
}
Expand Down
2 changes: 1 addition & 1 deletion backend/Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<LangVersion>latest</LangVersion>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion backend/Api/Common/ErrorResponseBody.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ReSharper disable NotAccessedPositionalProperty.Global

namespace Api.Common;

public record ErrorResponseBody( string code, string message);
public record ErrorResponseBody(string Code, string Message);
Loading

0 comments on commit 39b4eee

Please sign in to comment.