-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Mark operations * Add status text + tests * more test * Comment out mark action ok untill bodyMessage is implemented --------- Co-authored-by: Hammerbeck <[email protected]>
- Loading branch information
Showing
9 changed files
with
182 additions
and
9 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
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
45 changes: 45 additions & 0 deletions
45
...Application/UpdateCorrespondenceStatusCommand/UpdateCorrespondenceStatusCommandHandler.cs
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,45 @@ | ||
using Altinn.Correspondence.Core.Models; | ||
using Altinn.Correspondence.Core.Models.Enums; | ||
using Altinn.Correspondence.Core.Repositories; | ||
using OneOf; | ||
|
||
namespace Altinn.Correspondence.Application.UpdateCorrespondenceStatusCommand; | ||
|
||
public class UpdateCorrespondenceStatusCommandHandler : IHandler<UpdateCorrespondenceStatusCommandRequest, Guid> | ||
{ | ||
private readonly ICorrespondenceRepository _correspondenceRepository; | ||
private readonly ICorrespondenceStatusRepository _correspondenceStatusRepository; | ||
public UpdateCorrespondenceStatusCommandHandler(ICorrespondenceRepository correspondenceRepository, ICorrespondenceStatusRepository correspondenceStatusRepository) | ||
{ | ||
_correspondenceRepository = correspondenceRepository; | ||
_correspondenceStatusRepository = correspondenceStatusRepository; | ||
} | ||
|
||
public async Task<OneOf<Guid, Error>> Process(UpdateCorrespondenceStatusCommandRequest request, CancellationToken cancellationToken) | ||
{ | ||
var correspondence = await _correspondenceRepository.GetCorrespondenceById(request.CorrespondenceId, false, cancellationToken); | ||
if (correspondence == null) | ||
{ | ||
return Errors.CorrespondenceNotFound; | ||
} | ||
|
||
var currentStatus = await _correspondenceStatusRepository.GetLatestStatusByCorrespondenceId(request.CorrespondenceId, cancellationToken); | ||
if ((request.Status == CorrespondenceStatus.Confirmed || request.Status == CorrespondenceStatus.Read) && currentStatus?.Status != CorrespondenceStatus.Published) | ||
{ | ||
return Errors.CorrespondenceNotPublished; | ||
} | ||
if (currentStatus?.Status == request.Status) | ||
{ | ||
return request.CorrespondenceId; | ||
} | ||
|
||
await _correspondenceStatusRepository.AddCorrespondenceStatus(new CorrespondenceStatusEntity | ||
{ | ||
CorrespondenceId = request.CorrespondenceId, | ||
Status = request.Status, | ||
StatusChanged = DateTime.UtcNow, | ||
StatusText = request.Status.ToString(), | ||
}, cancellationToken); | ||
return request.CorrespondenceId; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...Application/UpdateCorrespondenceStatusCommand/UpdateCorrespondenceStatusCommandRequest.cs
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,9 @@ | ||
using Altinn.Correspondence.Core.Models.Enums; | ||
|
||
namespace Altinn.Correspondence.Application.UpdateCorrespondenceStatusCommand; | ||
|
||
public class UpdateCorrespondenceStatusCommandRequest | ||
{ | ||
public Guid CorrespondenceId { get; set; } | ||
public CorrespondenceStatus Status { get; set; } | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Altinn.Correspondence.Core/Repositories/ICorrespondenceStatusRepository.cs
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,10 @@ | ||
using Altinn.Correspondence.Core.Models; | ||
|
||
namespace Altinn.Correspondence.Core.Repositories | ||
{ | ||
public interface ICorrespondenceStatusRepository | ||
{ | ||
Task<Guid> AddCorrespondenceStatus(CorrespondenceStatusEntity Correspondence, CancellationToken cancellationToken); | ||
Task<CorrespondenceStatusEntity?> GetLatestStatusByCorrespondenceId(Guid CorrespondenceId, CancellationToken cancellationToken); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/Altinn.Correspondence.Persistence/Repositories/CorrespondenceStatusRepository.cs
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,28 @@ | ||
using Altinn.Correspondence.Core.Models; | ||
using Altinn.Correspondence.Core.Repositories; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Altinn.Correspondence.Persistence.Repositories | ||
{ | ||
public class CorrespondenceStatusRepository(ApplicationDbContext context) : ICorrespondenceStatusRepository | ||
{ | ||
private readonly ApplicationDbContext _context = context; | ||
|
||
public async Task<Guid> AddCorrespondenceStatus(CorrespondenceStatusEntity status, CancellationToken cancellationToken) | ||
{ | ||
await _context.CorrespondenceStatuses.AddAsync(status, cancellationToken); | ||
await _context.SaveChangesAsync(); | ||
return status.Id; | ||
} | ||
|
||
public async Task<CorrespondenceStatusEntity?> GetLatestStatusByCorrespondenceId(Guid CorrespondenceId, CancellationToken cancellationToken) | ||
{ | ||
var status = await _context.CorrespondenceStatuses | ||
.Where(s => s.CorrespondenceId == CorrespondenceId) | ||
.OrderByDescending(s => s.StatusChanged) | ||
.FirstOrDefaultAsync(cancellationToken); | ||
|
||
return status; | ||
} | ||
} | ||
} |