diff --git a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindController.cs b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindController.cs index 61d336f0..dc4c03e3 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindController.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindController.cs @@ -47,10 +47,10 @@ public void Dispose() public async Task ExecuteAsync( CancellationToken cancellationToken ) { IFindUseCase interactor = new FindInteractor( DatabaseRepository, Presenter ); - var request = new FindRequest( DeveloperName, ProductName, InstrumentName ); - var response = await interactor.ExecuteAsync( request, cancellationToken ); + var inputValue = new FindInputValue( DeveloperName, ProductName, InstrumentName ); + var inputData = new FindInputData( inputValue ); - Presenter.Complete( response ); + await interactor.HandleAsync( inputData, cancellationToken ); } } } diff --git a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindControllerFactory.cs b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindControllerFactory.cs index 151fa987..0434222b 100644 --- a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindControllerFactory.cs +++ b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindControllerFactory.cs @@ -1,4 +1,5 @@ using KeySwitchManager.Applications.Standalone.Core.Helpers; +using KeySwitchManager.Applications.Standalone.Core.Presenters; using KeySwitchManager.Applications.Standalone.Core.Views.LogView; namespace KeySwitchManager.Applications.Standalone.Core.Controllers.Find diff --git a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindPresenter.cs b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindPresenter.cs deleted file mode 100644 index 906af7c9..00000000 --- a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Controllers/Find/FindPresenter.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Linq; -using System.Text; - -using KeySwitchManager.Applications.Standalone.Core.Views.LogView; -using KeySwitchManager.UseCase.KeySwitches.Find; - -namespace KeySwitchManager.Applications.Standalone.Core.Controllers.Find -{ - public class FindPresenter : IFindPresenter - { - private ILogTextView TextView { get; } - - public FindPresenter( ILogTextView textView ) - { - TextView = textView; - } - - public void Present( T param ) - { - if( param != null ) - { - TextView.Append( param.ToString() ?? string.Empty ); - } - } - - public void Complete( FindResponse response ) - { - var sb = new StringBuilder( 128 ); - - foreach( var k in response.Result.OrderBy( x => x.DeveloperName.Value ) - .ThenBy( x=> x.ProductName.Value) - .ThenBy( x => x.InstrumentName.Value ) ) - { - sb.Clear(); - sb.Append( k ); - TextView.Append( sb.ToString() ); - } - - TextView.Append( "---------------------------------" ); - TextView.Append( $"{response.FoundCount} record(s) found" ); - TextView.Append( "Complete" ); - - TextView.ScrollToEnd(); - } - } -} diff --git a/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Presenters/FindPresenter.cs b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Presenters/FindPresenter.cs new file mode 100644 index 00000000..221d002d --- /dev/null +++ b/KeySwitchManager/Sources/Runtime/Applications/Standalone.Core/Presenters/FindPresenter.cs @@ -0,0 +1,43 @@ +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +using KeySwitchManager.Applications.Standalone.Core.Views.LogView; +using KeySwitchManager.UseCase.KeySwitches.Find; + +namespace KeySwitchManager.Applications.Standalone.Core.Presenters +{ + public sealed class FindPresenter : IFindPresenter + { + private ILogTextView TextView { get; } + + public FindPresenter( ILogTextView textView ) + { + TextView = textView; + } + + public async Task HandleAsync( FindOutputData outputData, CancellationToken cancellationToken = default ) + { + var sb = new StringBuilder( 128 ); + var keySwitches = outputData.Value.Result; + + foreach( var k in keySwitches.OrderBy( x => x.DeveloperName.Value ) + .ThenBy( x => x.ProductName.Value ) + .ThenBy( x => x.InstrumentName.Value ) ) + { + sb.Clear(); + sb.Append( k ); + TextView.Append( sb.ToString() ); + } + + TextView.Append( "---------------------------------" ); + TextView.Append( $"{keySwitches.Count} record(s) found" ); + TextView.Append( "Complete" ); + + TextView.ScrollToEnd(); + + await Task.CompletedTask; + } + } +} diff --git a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/FindInteractor.cs b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/FindInteractor.cs index 51b7e4ff..6e904dfd 100644 --- a/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/FindInteractor.cs +++ b/KeySwitchManager/Sources/Runtime/Interactors/KeySwitches/FindInteractor.cs @@ -1,9 +1,7 @@ -using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using KeySwitchManager.Domain.KeySwitches; -using KeySwitchManager.Domain.KeySwitches.Models; using KeySwitchManager.Domain.KeySwitches.Models.Values; using KeySwitchManager.UseCase.KeySwitches.Find; @@ -11,16 +9,11 @@ namespace KeySwitchManager.Interactors.KeySwitches { - public class FindInteractor : IFindUseCase + public sealed class FindInteractor : IFindUseCase { private IKeySwitchRepository Repository { get; } private IFindPresenter Presenter { get; } - public FindInteractor( - IKeySwitchRepository repository ) : - this( repository, new IFindPresenter.Null() ) - {} - public FindInteractor( IKeySwitchRepository repository, IFindPresenter presenter ) @@ -29,23 +22,26 @@ public FindInteractor( Presenter = presenter; } - public async Task ExecuteAsync( FindRequest request, CancellationToken cancellationToken ) + public async Task HandleAsync( FindInputData inputData, CancellationToken cancellationToken = default ) { - var developerName = request.DeveloperName; - var productName = request.ProductName; - var instrumentName = request.InstrumentName; + var developerName = inputData.Value.DeveloperName; + var productName = inputData.Value.ProductName; + var instrumentName = inputData.Value.InstrumentName; #region By Developer, Product, Instrument if( !StringHelper.IsEmpty( developerName, productName, instrumentName ) ) { var keySwitches = await Repository.FindAsync( - new DeveloperName( request.DeveloperName ), - new ProductName( request.ProductName ), - new InstrumentName( request.InstrumentName ), + new DeveloperName( developerName ), + new ProductName( productName ), + new InstrumentName( instrumentName ), cancellationToken ); - return new FindResponse( keySwitches ); + var output = new FindOutputData( new FindOutputValue( keySwitches ) ); + + await Presenter.HandleAsync( output, cancellationToken ); + return; } #endregion @@ -53,12 +49,15 @@ public async Task ExecuteAsync( FindRequest request, CancellationT if( !StringHelper.IsEmpty( developerName, productName ) ) { var keySwitches = await Repository.FindAsync( - new DeveloperName( request.DeveloperName ), - new ProductName( request.ProductName ), + new DeveloperName( developerName ), + new ProductName( productName ), cancellationToken ); - return new FindResponse( keySwitches ); + var output = new FindOutputData( new FindOutputValue( keySwitches ) ); + + await Presenter.HandleAsync( output, cancellationToken ); + return; } #endregion @@ -66,15 +65,16 @@ public async Task ExecuteAsync( FindRequest request, CancellationT if( !StringHelper.IsEmpty( developerName ) ) { var keySwitches = await Repository.FindAsync( - new DeveloperName( request.DeveloperName ), + new DeveloperName( developerName ), cancellationToken ); - return new FindResponse( keySwitches ); + var output = new FindOutputData( new FindOutputValue( keySwitches ) ); + + await Presenter.HandleAsync( output, cancellationToken ); + return; } #endregion - - return new FindResponse( new List() ); } } } diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindRequest.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindInputData.cs similarity index 63% rename from KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindRequest.cs rename to KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindInputData.cs index f790d09e..92a3b96f 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindRequest.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindInputData.cs @@ -1,12 +1,14 @@ +using KeySwitchManager.UseCase.Commons; + namespace KeySwitchManager.UseCase.KeySwitches.Find { - public class FindRequest + public sealed class FindInputValue { public string DeveloperName { get; } public string ProductName { get; } public string InstrumentName { get; } - public FindRequest( + public FindInputValue( string developerName = "", string productName = "", string instrumentName = "" ) @@ -16,4 +18,9 @@ public FindRequest( InstrumentName = instrumentName; } } -} \ No newline at end of file + + public sealed class FindInputData : InputData + { + public FindInputData( FindInputValue value ) : base( value ) {} + } +} diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindOutputData.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindOutputData.cs new file mode 100644 index 00000000..01f3160c --- /dev/null +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindOutputData.cs @@ -0,0 +1,9 @@ +using KeySwitchManager.UseCase.Commons; + +namespace KeySwitchManager.UseCase.KeySwitches.Find +{ + public sealed class FindOutputData : InputData + { + public FindOutputData( FindOutputValue value ) : base( value ) {} + } +} diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindResponse.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindOutputValue.cs similarity index 75% rename from KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindResponse.cs rename to KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindOutputValue.cs index 88be021e..67482752 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindResponse.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/FindOutputValue.cs @@ -4,15 +4,15 @@ namespace KeySwitchManager.UseCase.KeySwitches.Find { - public class FindResponse + public sealed class FindOutputValue { public IReadOnlyCollection Result { get; } public int FoundCount { get; } - public FindResponse( IReadOnlyCollection result ) + public FindOutputValue( IReadOnlyCollection result ) { Result = result; FoundCount = Result.Count; } } -} \ No newline at end of file +} diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindPresenter.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindPresenter.cs index e23c3790..a067836d 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindPresenter.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindPresenter.cs @@ -2,22 +2,5 @@ namespace KeySwitchManager.UseCase.KeySwitches.Find { - public interface IFindPresenter : IPresenter - { - public class Null : IFindPresenter - {} - - public class Console : IFindPresenter - { - public void Present( T param ) - { - System.Console.WriteLine( param ); - } - - public void Message( string message ) - { - System.Console.WriteLine( message ); - } - } - } -} \ No newline at end of file + public interface IFindPresenter : IOutputPort {} +} diff --git a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindUseCase.cs b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindUseCase.cs index e74aed09..c7eba521 100644 --- a/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindUseCase.cs +++ b/KeySwitchManager/Sources/Runtime/UseCases/KeySwitches/Find/IFindUseCase.cs @@ -1,13 +1,6 @@ -using System.Threading; -using System.Threading.Tasks; +using KeySwitchManager.UseCase.Commons; namespace KeySwitchManager.UseCase.KeySwitches.Find { - public interface IFindUseCase - { - public FindResponse Execute( FindRequest request ) - => ExecuteAsync( request ).GetAwaiter().GetResult(); - - public Task ExecuteAsync( FindRequest request, CancellationToken cancellationToken = default ); - } + public interface IFindUseCase : IInputPort {} }