-
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.
feat(squadron): find a squadron by its code
- Loading branch information
1 parent
4e4ba75
commit 5881cce
Showing
8 changed files
with
101 additions
and
0 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
14 changes: 14 additions & 0 deletions
14
src/Squadron/Application/SearchByCode/SearchSquadronByCodeQuery.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,14 @@ | ||
using Armory.Shared.Domain.Bus.Query; | ||
|
||
namespace Armory.Squadron.Application.SearchByCode | ||
{ | ||
public class SearchSquadronByCodeQuery : Query | ||
{ | ||
public string Code { get; } | ||
|
||
public SearchSquadronByCodeQuery(string code) | ||
{ | ||
Code = code; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Squadron/Application/SearchByCode/SearchSquadronByCodeQueryHandler.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,21 @@ | ||
using System.Threading.Tasks; | ||
using Armory.Shared.Domain.Bus.Query; | ||
|
||
namespace Armory.Squadron.Application.SearchByCode | ||
{ | ||
public class SearchSquadronByCodeQueryHandler : IQueryHandler<SearchSquadronByCodeQuery, SquadronResponse> | ||
{ | ||
private readonly SquadronByCodeSearcher _searcher; | ||
|
||
|
||
public SearchSquadronByCodeQueryHandler(SquadronByCodeSearcher searcher) | ||
{ | ||
_searcher = searcher; | ||
} | ||
|
||
public async Task<SquadronResponse> Handle(SearchSquadronByCodeQuery query) | ||
{ | ||
return await _searcher.Search(query.Code); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Squadron/Application/SearchByCode/SquadronByCodeSearcher.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,21 @@ | ||
using System.Threading.Tasks; | ||
using Armory.Squadron.Domain; | ||
|
||
namespace Armory.Squadron.Application.SearchByCode | ||
{ | ||
public class SquadronByCodeSearcher | ||
{ | ||
private readonly ISquadronRepository _repository; | ||
|
||
public SquadronByCodeSearcher(ISquadronRepository repository) | ||
{ | ||
_repository = repository; | ||
} | ||
|
||
public async Task<SquadronResponse> Search(string code) | ||
{ | ||
var squadron = await _repository.Find(code); | ||
return squadron == null ? null : SquadronResponse.FromAggregate(squadron); | ||
} | ||
} | ||
} |
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,21 @@ | ||
namespace Armory.Squadron.Application | ||
{ | ||
public class SquadronResponse | ||
{ | ||
public string Code { get; } | ||
public string Name { get; } | ||
public string ArmoryUserId { get; } | ||
|
||
public SquadronResponse(string code, string name, string armoryUserId) | ||
{ | ||
Code = code; | ||
Name = name; | ||
ArmoryUserId = armoryUserId; | ||
} | ||
|
||
public static SquadronResponse FromAggregate(Domain.Squadron squadron) | ||
{ | ||
return new SquadronResponse(squadron.Code, squadron.Name, squadron.ArmoryUserId); | ||
} | ||
} | ||
} |
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