Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up AgreementController #559

Merged
merged 11 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading