-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/mark operations #81
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.