-
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.
Merge pull request #33 from bsandmann/dev
code clean up
- Loading branch information
Showing
60 changed files
with
519 additions
and
1,184 deletions.
There are no files selected for viewing
42 changes: 20 additions & 22 deletions
42
Blocktrust.CredentialWorkflow.Core/Commands/DIDComm/DeletePeerDID/DeletePeerDIDHandler.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 |
---|---|---|
@@ -1,35 +1,33 @@ | ||
using Blocktrust.CredentialWorkflow.Core.Entities.DIDComm; | ||
using FluentResults; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.DeletePeerDID | ||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.DeletePeerDID; | ||
|
||
public class DeletePeerDIDHandler : IRequestHandler<DeletePeerDIDRequest, Result> | ||
{ | ||
public class DeletePeerDIDHandler : IRequestHandler<DeletePeerDIDRequest, Result> | ||
{ | ||
private readonly DataContext _context; | ||
private readonly DataContext _context; | ||
|
||
public DeletePeerDIDHandler(DataContext context) | ||
{ | ||
_context = context; | ||
} | ||
public DeletePeerDIDHandler(DataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Result> Handle(DeletePeerDIDRequest request, CancellationToken cancellationToken) | ||
{ | ||
_context.ChangeTracker.Clear(); | ||
public async Task<Result> Handle(DeletePeerDIDRequest request, CancellationToken cancellationToken) | ||
{ | ||
_context.ChangeTracker.Clear(); | ||
|
||
var peerDIDEntity = await _context.PeerDIDEntities | ||
.FirstOrDefaultAsync(p => p.PeerDIDEntityId == request.PeerDIDEntityId, cancellationToken); | ||
var peerDIDEntity = await _context.PeerDIDEntities | ||
.FirstOrDefaultAsync(p => p.PeerDIDEntityId == request.PeerDIDEntityId, cancellationToken); | ||
|
||
if (peerDIDEntity is null) | ||
{ | ||
return Result.Fail("The PeerDID does not exist in the database. It cannot be deleted."); | ||
} | ||
if (peerDIDEntity is null) | ||
{ | ||
return Result.Fail("The PeerDID does not exist in the database. It cannot be deleted."); | ||
} | ||
|
||
_context.PeerDIDEntities.Remove(peerDIDEntity); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
_context.PeerDIDEntities.Remove(peerDIDEntity); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
|
||
return Result.Ok(); | ||
} | ||
return Result.Ok(); | ||
} | ||
} |
15 changes: 7 additions & 8 deletions
15
Blocktrust.CredentialWorkflow.Core/Commands/DIDComm/DeletePeerDID/DeletePeerDIDRequest.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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
using FluentResults; | ||
using MediatR; | ||
|
||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.DeletePeerDID | ||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.DeletePeerDID; | ||
|
||
public class DeletePeerDIDRequest : IRequest<Result> | ||
{ | ||
public class DeletePeerDIDRequest : IRequest<Result> | ||
public DeletePeerDIDRequest(Guid peerDIDEntityId) | ||
{ | ||
public DeletePeerDIDRequest(Guid peerDIDEntityId) | ||
{ | ||
PeerDIDEntityId = peerDIDEntityId; | ||
} | ||
|
||
public Guid PeerDIDEntityId { get; } | ||
PeerDIDEntityId = peerDIDEntityId; | ||
} | ||
|
||
public Guid PeerDIDEntityId { get; } | ||
} |
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
4 changes: 2 additions & 2 deletions
4
...st.CredentialWorkflow.Core/Commands/DIDComm/GetPeerDIDSecrets/GetPeerDIDSecretsRequest.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
45 changes: 21 additions & 24 deletions
45
Blocktrust.CredentialWorkflow.Core/Commands/DIDComm/GetPeerDIDs/GetPeerDIDsHandler.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 |
---|---|---|
@@ -1,37 +1,34 @@ | ||
using Blocktrust.CredentialWorkflow.Core.Entities.DIDComm; | ||
using FluentResults; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.GetPeerDIDs | ||
{ | ||
using Domain.PeerDID; | ||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.GetPeerDIDs; | ||
|
||
public class GetPeerDIDsHandler : IRequestHandler<GetPeerDIDsRequest, Result<List<PeerDIDModel>>> | ||
{ | ||
private readonly DataContext _context; | ||
using Domain.PeerDID; | ||
|
||
public GetPeerDIDsHandler(DataContext context) | ||
{ | ||
_context = context; | ||
} | ||
public class GetPeerDIDsHandler : IRequestHandler<GetPeerDIDsRequest, Result<List<PeerDIDModel>>> | ||
{ | ||
private readonly DataContext _context; | ||
|
||
public async Task<Result<List<PeerDIDModel>>> Handle(GetPeerDIDsRequest request, CancellationToken cancellationToken) | ||
{ | ||
_context.ChangeTracker.Clear(); | ||
public GetPeerDIDsHandler(DataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
var peerDIDEntities = await _context.PeerDIDEntities | ||
.Where(p => p.TenantEntityId == request.TenantId) | ||
.ToListAsync(cancellationToken); | ||
public async Task<Result<List<PeerDIDModel>>> Handle(GetPeerDIDsRequest request, CancellationToken cancellationToken) | ||
{ | ||
_context.ChangeTracker.Clear(); | ||
|
||
// If none found, we can return an empty list as a success | ||
if (peerDIDEntities is null || peerDIDEntities.Count == 0) | ||
{ | ||
return Result.Ok(new List<PeerDIDModel>()); | ||
} | ||
var peerDIDEntities = await _context.PeerDIDEntities | ||
.Where(p => p.TenantEntityId == request.TenantId) | ||
.ToListAsync(cancellationToken); | ||
|
||
var peerDIDs = peerDIDEntities.Select(p => p.ToModel()).ToList(); | ||
return Result.Ok(peerDIDs); | ||
if (peerDIDEntities is null || peerDIDEntities.Count == 0) | ||
{ | ||
return Result.Ok(new List<PeerDIDModel>()); | ||
} | ||
|
||
var peerDIDs = peerDIDEntities.Select(p => p.ToModel()).ToList(); | ||
return Result.Ok(peerDIDs); | ||
} | ||
} |
19 changes: 9 additions & 10 deletions
19
Blocktrust.CredentialWorkflow.Core/Commands/DIDComm/GetPeerDIDs/GetPeerDIDsRequest.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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
using FluentResults; | ||
using MediatR; | ||
|
||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.GetPeerDIDs | ||
{ | ||
using Domain.PeerDID; | ||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.GetPeerDIDs; | ||
|
||
public class GetPeerDIDsRequest : IRequest<Result<List<PeerDIDModel>>> | ||
{ | ||
public GetPeerDIDsRequest(Guid tenantId) | ||
{ | ||
TenantId = tenantId; | ||
} | ||
using Domain.PeerDID; | ||
|
||
public Guid TenantId { get; } | ||
public class GetPeerDIDsRequest : IRequest<Result<List<PeerDIDModel>>> | ||
{ | ||
public GetPeerDIDsRequest(Guid tenantId) | ||
{ | ||
TenantId = tenantId; | ||
} | ||
|
||
public Guid TenantId { get; } | ||
} |
40 changes: 19 additions & 21 deletions
40
Blocktrust.CredentialWorkflow.Core/Commands/DIDComm/GetPeerDidById/GetPeerDidByIdHandler.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 |
---|---|---|
@@ -1,34 +1,32 @@ | ||
using Blocktrust.CredentialWorkflow.Core.Entities.DIDComm; | ||
using FluentResults; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.GetPeerDidById | ||
{ | ||
using Domain.PeerDID; | ||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.GetPeerDidById; | ||
|
||
public class GetPeerDidByIdHandler : IRequestHandler<GetPeerDidByIdRequest, Result<PeerDIDModel>> | ||
{ | ||
private readonly DataContext _context; | ||
using Domain.PeerDID; | ||
|
||
public GetPeerDidByIdHandler(DataContext context) | ||
{ | ||
_context = context; | ||
} | ||
public class GetPeerDidByIdHandler : IRequestHandler<GetPeerDidByIdRequest, Result<PeerDIDModel>> | ||
{ | ||
private readonly DataContext _context; | ||
|
||
public async Task<Result<PeerDIDModel>> Handle(GetPeerDidByIdRequest request, CancellationToken cancellationToken) | ||
{ | ||
_context.ChangeTracker.Clear(); | ||
public GetPeerDidByIdHandler(DataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
var peerDIDEntity = await _context.PeerDIDEntities | ||
.FirstOrDefaultAsync(p => p.PeerDIDEntityId == request.PeerDidEntityId, cancellationToken); | ||
public async Task<Result<PeerDIDModel>> Handle(GetPeerDidByIdRequest request, CancellationToken cancellationToken) | ||
{ | ||
_context.ChangeTracker.Clear(); | ||
|
||
if (peerDIDEntity is null) | ||
{ | ||
return Result.Fail($"PeerDID with ID '{request.PeerDidEntityId}' not found."); | ||
} | ||
var peerDIDEntity = await _context.PeerDIDEntities | ||
.FirstOrDefaultAsync(p => p.PeerDIDEntityId == request.PeerDidEntityId, cancellationToken); | ||
|
||
return Result.Ok(peerDIDEntity.ToModel()); | ||
if (peerDIDEntity is null) | ||
{ | ||
return Result.Fail($"PeerDID with ID '{request.PeerDidEntityId}' not found."); | ||
} | ||
|
||
return Result.Ok(peerDIDEntity.ToModel()); | ||
} | ||
} |
17 changes: 8 additions & 9 deletions
17
Blocktrust.CredentialWorkflow.Core/Commands/DIDComm/GetPeerDidById/GetPeerDidByIdRequest.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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
using FluentResults; | ||
using MediatR; | ||
|
||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.GetPeerDidById | ||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.GetPeerDidById; | ||
|
||
using Domain.PeerDID; | ||
|
||
public class GetPeerDidByIdRequest : IRequest<Result<PeerDIDModel>> | ||
{ | ||
using Domain.PeerDID; | ||
public Guid PeerDidEntityId { get; } | ||
|
||
public class GetPeerDidByIdRequest : IRequest<Result<PeerDIDModel>> | ||
public GetPeerDidByIdRequest(Guid peerDidEntityId) | ||
{ | ||
public Guid PeerDidEntityId { get; } | ||
|
||
public GetPeerDidByIdRequest(Guid peerDidEntityId) | ||
{ | ||
PeerDidEntityId = peerDidEntityId; | ||
} | ||
PeerDidEntityId = peerDidEntityId; | ||
} | ||
} |
79 changes: 39 additions & 40 deletions
79
Blocktrust.CredentialWorkflow.Core/Commands/DIDComm/SavePeerDID/SavePeerDIDHandler.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 |
---|---|---|
@@ -1,50 +1,49 @@ | ||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.SavePeerDID | ||
namespace Blocktrust.CredentialWorkflow.Core.Commands.DIDComm.SavePeerDID; | ||
|
||
using Blocktrust.CredentialWorkflow.Core.Entities.DIDComm; | ||
using Domain.PeerDID; | ||
using FluentResults; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
public class SavePeerDIDHandler : IRequestHandler<SavePeerDIDRequest, Result<PeerDIDModel>> | ||
{ | ||
using Blocktrust.CredentialWorkflow.Core.Entities.DIDComm; | ||
using Domain.PeerDID; | ||
using FluentResults; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
private readonly DataContext _context; | ||
|
||
public class SavePeerDIDHandler : IRequestHandler<SavePeerDIDRequest, Result<PeerDIDModel>> | ||
public SavePeerDIDHandler(DataContext context) | ||
{ | ||
private readonly DataContext _context; | ||
_context = context; | ||
} | ||
|
||
public SavePeerDIDHandler(DataContext context) | ||
public async Task<Result<PeerDIDModel>> Handle(SavePeerDIDRequest request, CancellationToken cancellationToken) | ||
{ | ||
_context.ChangeTracker.Clear(); | ||
_context.ChangeTracker.AutoDetectChangesEnabled = false; | ||
|
||
// Validate tenant | ||
var tenant = await _context.TenantEntities | ||
.FirstOrDefaultAsync(t => t.TenantEntityId == request.TenantId, cancellationToken); | ||
|
||
if (tenant is null) | ||
{ | ||
_context = context; | ||
return Result.Fail("The tenant does not exist in the database. The PeerDID cannot be created."); | ||
} | ||
|
||
public async Task<Result<PeerDIDModel>> Handle(SavePeerDIDRequest request, CancellationToken cancellationToken) | ||
// Create the new PeerDIDEntity | ||
var peerDIDEntity = new PeerDIDEntity | ||
{ | ||
_context.ChangeTracker.Clear(); | ||
_context.ChangeTracker.AutoDetectChangesEnabled = false; | ||
|
||
// Validate tenant | ||
var tenant = await _context.TenantEntities | ||
.FirstOrDefaultAsync(t => t.TenantEntityId == request.TenantId, cancellationToken); | ||
|
||
if (tenant is null) | ||
{ | ||
return Result.Fail("The tenant does not exist in the database. The PeerDID cannot be created."); | ||
} | ||
|
||
// Create the new PeerDIDEntity | ||
var peerDIDEntity = new PeerDIDEntity | ||
{ | ||
PeerDIDEntityId = Guid.NewGuid(), | ||
Name = request.Name, | ||
PeerDID = request.PeerDID, | ||
TenantEntityId = tenant.TenantEntityId, | ||
CreatedUtc = DateTime.UtcNow | ||
}; | ||
|
||
// Insert and save | ||
await _context.PeerDIDEntities.AddAsync(peerDIDEntity, cancellationToken); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
|
||
// Return the domain model | ||
return Result.Ok(peerDIDEntity.ToModel()); | ||
} | ||
PeerDIDEntityId = Guid.NewGuid(), | ||
Name = request.Name, | ||
PeerDID = request.PeerDID, | ||
TenantEntityId = tenant.TenantEntityId, | ||
CreatedUtc = DateTime.UtcNow | ||
}; | ||
|
||
// Insert and save | ||
await _context.PeerDIDEntities.AddAsync(peerDIDEntity, cancellationToken); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
|
||
// Return the domain model | ||
return Result.Ok(peerDIDEntity.ToModel()); | ||
} | ||
} |
Oops, something went wrong.