-
Notifications
You must be signed in to change notification settings - Fork 0
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 #268 from DFE-Digital/consistency-refactor
Consistency refactor
- Loading branch information
Showing
38 changed files
with
155 additions
and
158 deletions.
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
...demies.Academisation.IService/Commands/AdvisoryBoardDecision/IApplicationCreateCommand.cs
This file was deleted.
Oops, something went wrong.
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
15 changes: 0 additions & 15 deletions
15
Dfe.Academies.Academisation.IService/RequestModels/ApplicationCreateRequestModel.cs
This file was deleted.
Oops, something went wrong.
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
46 changes: 9 additions & 37 deletions
46
Dfe.Academies.Academisation.Service/Commands/Application/ApplicationCreateCommand.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,45 +1,17 @@ | ||
using AutoMapper; | ||
using Dfe.Academies.Academisation.Core; | ||
using Dfe.Academies.Academisation.Domain.ApplicationAggregate; | ||
using Dfe.Academies.Academisation.Core; | ||
using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; | ||
using Dfe.Academies.Academisation.IDomain.ApplicationAggregate; | ||
using Dfe.Academies.Academisation.IService.Commands.AdvisoryBoardDecision; | ||
using Dfe.Academies.Academisation.IService.RequestModels; | ||
using Dfe.Academies.Academisation.Service.Mappers.Application; | ||
using MediatR; | ||
|
||
namespace Dfe.Academies.Academisation.Service.Commands.Application; | ||
namespace Dfe.Academies.Academisation.IService.RequestModels; | ||
|
||
public class ApplicationCreateCommand : IApplicationCreateCommand | ||
public class ApplicationCreateCommand : IRequest<CreateResult> | ||
{ | ||
private readonly IApplicationFactory _domainFactory; | ||
private readonly IApplicationRepository _applicationRepository; | ||
private readonly IMapper _mapper; | ||
|
||
public ApplicationCreateCommand(IApplicationFactory domainFactory, IApplicationRepository applicationRepository, IMapper mapper) | ||
public ApplicationCreateCommand(ApplicationType applicationType, ContributorRequestModel contributor) | ||
{ | ||
_domainFactory = domainFactory; | ||
_applicationRepository = applicationRepository; | ||
_mapper = mapper; | ||
ApplicationType = applicationType; | ||
Contributor = contributor; | ||
} | ||
|
||
public async Task<CreateResult> Execute(ApplicationCreateRequestModel applicationCreateRequestModel) | ||
{ | ||
(ApplicationType applicationType, ContributorDetails contributorDetails) = applicationCreateRequestModel.AsDomain(); | ||
var result = _domainFactory.Create(applicationType, contributorDetails); | ||
|
||
if (result is CreateValidationErrorResult domainValidationErrorResult) | ||
{ | ||
return domainValidationErrorResult.MapToPayloadType(); | ||
} | ||
|
||
if (result is not CreateSuccessResult<Domain.ApplicationAggregate.Application> domainSuccessResult) | ||
{ | ||
throw new NotImplementedException("Other CreateResult types not expected"); | ||
} | ||
|
||
await _applicationRepository.Insert(domainSuccessResult.Payload); | ||
await _applicationRepository.UnitOfWork.SaveChangesAsync(); | ||
|
||
return domainSuccessResult.MapToPayloadType(ApplicationServiceModelMapper.MapFromDomain, _mapper); | ||
} | ||
public ApplicationType ApplicationType { get; } | ||
public ContributorRequestModel Contributor { get; } | ||
} |
46 changes: 46 additions & 0 deletions
46
Dfe.Academies.Academisation.Service/Commands/Application/ApplicationCreateCommandHandler.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,46 @@ | ||
using AutoMapper; | ||
using Dfe.Academies.Academisation.Core; | ||
using Dfe.Academies.Academisation.Domain.ApplicationAggregate; | ||
using Dfe.Academies.Academisation.Domain.Core.ApplicationAggregate; | ||
using Dfe.Academies.Academisation.IDomain.ApplicationAggregate; | ||
using Dfe.Academies.Academisation.IService.Commands.AdvisoryBoardDecision; | ||
using Dfe.Academies.Academisation.IService.RequestModels; | ||
using Dfe.Academies.Academisation.Service.Mappers.Application; | ||
using MediatR; | ||
|
||
namespace Dfe.Academies.Academisation.Service.Commands.Application; | ||
|
||
public class ApplicationCreateCommandHandler : IRequestHandler<ApplicationCreateCommand, CreateResult> | ||
{ | ||
private readonly IApplicationFactory _domainFactory; | ||
private readonly IApplicationRepository _applicationRepository; | ||
private readonly IMapper _mapper; | ||
|
||
public ApplicationCreateCommandHandler(IApplicationFactory domainFactory, IApplicationRepository applicationRepository, IMapper mapper) | ||
{ | ||
_domainFactory = domainFactory; | ||
_applicationRepository = applicationRepository; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<CreateResult> Handle(ApplicationCreateCommand applicationCreateRequestModel, CancellationToken cancellationToken) | ||
{ | ||
(ApplicationType applicationType, ContributorDetails contributorDetails) = applicationCreateRequestModel.AsDomain(); | ||
var result = _domainFactory.Create(applicationType, contributorDetails); | ||
|
||
if (result is CreateValidationErrorResult domainValidationErrorResult) | ||
{ | ||
return domainValidationErrorResult.MapToPayloadType(); | ||
} | ||
|
||
if (result is not CreateSuccessResult<Domain.ApplicationAggregate.Application> domainSuccessResult) | ||
{ | ||
throw new NotImplementedException("Other CreateResult types not expected"); | ||
} | ||
|
||
await _applicationRepository.Insert(domainSuccessResult.Payload); | ||
await _applicationRepository.UnitOfWork.SaveChangesAsync(); | ||
|
||
return domainSuccessResult.MapToPayloadType(ApplicationServiceModelMapper.MapFromDomain, _mapper); | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
3 changes: 1 addition & 2 deletions
3
...ds/Application/FormTrustCommandHandler.cs → ...lication/Trust/FormTrustCommandHandler.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
3 changes: 1 addition & 2 deletions
3
...ds/Application/JoinTrustCommandHandler.cs → ...lication/Trust/JoinTrustCommandHandler.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
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
Oops, something went wrong.