diff --git a/backend/Api/Agreements/AgreementController.cs b/backend/Api/Agreements/AgreementController.cs index 3b74dd9e..e9211da0 100644 --- a/backend/Api/Agreements/AgreementController.cs +++ b/backend/Api/Agreements/AgreementController.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Memory; -namespace Api.Projects; +namespace Api.Agreements; [Authorize] [Route("/v0/{orgUrlKey}/agreements")] @@ -36,9 +36,9 @@ public async Task> GetAgreement([FromRoute] str AgreementId: agreement.Id, EngagementId: agreement.EngagementId, CustomerId: agreement.CustomerId, - StartDate: agreement.StartDate, - EndDate: agreement.EndDate, - NextPriceAdjustmentDate: agreement.NextPriceAdjustmentDate, + StartDate: agreement.StartDate is null ? null : new DateTimeOffset((DateTime)agreement.StartDate, TimeSpan.Zero), + EndDate: new DateTimeOffset(agreement.EndDate, TimeSpan.Zero) , + NextPriceAdjustmentDate: agreement.NextPriceAdjustmentDate is null ? null : new DateTimeOffset((DateTime)agreement.NextPriceAdjustmentDate, TimeSpan.Zero), PriceAdjustmentIndex: agreement.PriceAdjustmentIndex, Notes: agreement.Notes, Options: agreement.Options, @@ -46,7 +46,7 @@ public async Task> GetAgreement([FromRoute] str Files: agreement.Files.Select(f => new FileReferenceReadModel( FileName: f.FileName, BlobName: f.BlobName, - UploadedOn: f.UploadedOn, + UploadedOn: new DateTimeOffset(f.UploadedOn, TimeSpan.Zero), UploadedBy: f.UploadedBy ?? "Unknown" )).ToList() ); @@ -63,7 +63,7 @@ public async Task>> GetAgreementsByEngagem var agreements = await agreementsRepository.GetAgreementsByEngagementId(engagementId, ct); - if (agreements is null || !agreements.Any()) return NotFound(); + if (agreements.Count == 0) return NotFound(); var responseModels = agreements.Select(agreement => new AgreementReadModel( AgreementId: agreement.Id, @@ -89,7 +89,7 @@ public async Task>> GetAgreementsByEngagem } [HttpGet] - [Route("get/customer/{customerId}")] + [Route("get/customer/{customerId:int}")] public async Task>> GetAgreementsByCustomer([FromRoute] string orgUrlKey, [FromRoute] int customerId, CancellationToken ct) { @@ -98,7 +98,7 @@ public async Task>> GetAgreementsByCustome var agreements = await agreementsRepository.GetAgreementsByCustomerId(customerId, ct); - if (agreements is null || !agreements.Any()) return NotFound(); + if (agreements.Count == 0) return NotFound(); var responseModels = agreements.Select(agreement => new AgreementReadModel( AgreementId: agreement.Id, @@ -146,7 +146,7 @@ public async Task> Post([FromRoute] string orgU Customer? customer = null; if (body.CustomerId != null) { - customer = await context.Customer.FindAsync(body.CustomerId.Value); + customer = await context.Customer.FindAsync([body.CustomerId.Value], ct); if (customer == null) return BadRequest("Customer not found"); } @@ -154,7 +154,7 @@ public async Task> Post([FromRoute] string orgU Engagement? engagement = null; if (body.EngagementId != null) { - engagement = await context.Project.FindAsync(body.EngagementId.Value); + engagement = await context.Project.FindAsync([body.EngagementId.Value], ct); if (engagement is null) return BadRequest("Engagement not found"); } @@ -232,10 +232,9 @@ public async Task> Put([FromRoute] string orgUr if (agreement is null) return NotFound("Agreement not found"); - Customer? customer = null; if (body.CustomerId is not null) { - customer = await context.Customer.FindAsync(body.CustomerId); + var customer = await context.Customer.FindAsync([body.CustomerId], cancellationToken: ct); if (customer is null) return BadRequest("Customer not found"); @@ -248,10 +247,9 @@ public async Task> Put([FromRoute] string orgUr agreement.Customer = null; } - Engagement? engagement = null; if (body.EngagementId is not null) { - engagement = await context.Project.FindAsync(body.EngagementId); + var engagement = await context.Project.FindAsync([body.EngagementId], cancellationToken: ct); if (engagement is null) return BadRequest("Engagement not found"); diff --git a/backend/Api/Agreements/AgreementModels.cs b/backend/Api/Agreements/AgreementModels.cs index 96cddf7e..1be54658 100644 --- a/backend/Api/Agreements/AgreementModels.cs +++ b/backend/Api/Agreements/AgreementModels.cs @@ -1,15 +1,17 @@ -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +// ReSharper disable NotAccessedPositionalProperty.Global +// ReSharper disable ClassNeverInstantiated.Global + +namespace Api.Agreements; public record AgreementReadModel( int AgreementId, string? Name, int? CustomerId, int? EngagementId, - DateTime? StartDate, - DateTime EndDate, - DateTime? NextPriceAdjustmentDate, + DateTimeOffset? StartDate, + DateTimeOffset EndDate, + DateTimeOffset? NextPriceAdjustmentDate, string? PriceAdjustmentIndex, string? Notes, string? Options, @@ -19,7 +21,7 @@ List Files public record FileReferenceReadModel( string FileName, string BlobName, - DateTime UploadedOn, + DateTimeOffset UploadedOn, string? UploadedBy ); @@ -43,7 +45,7 @@ public IEnumerable Validate(ValidationContext validationContex { yield return new ValidationResult( "At least one of CustomerId or EngagementId must be provided.", - new[] { nameof(CustomerId), nameof(EngagementId) }); + [nameof(CustomerId), nameof(EngagementId)]); } } } @@ -54,4 +56,4 @@ public record FileReferenceWriteModel( string BlobName, DateTime UploadedOn, string? UploadedBy -); +); \ No newline at end of file