-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
111 changed files
with
4,067 additions
and
100 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
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
65 changes: 65 additions & 0 deletions
65
Source/EventFlow.Examples.Shipping.Queries.InMemory/Cargos/CargoReadModel.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,65 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015 Rasmus Mikkelsen | ||
// https://github.com/rasmus/EventFlow | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software is furnished to do so, | ||
// subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
using System.Collections.Generic; | ||
using EventFlow.Aggregates; | ||
using EventFlow.Examples.Shipping.Domain.Model.CargoModel; | ||
using EventFlow.Examples.Shipping.Domain.Model.CargoModel.Events; | ||
using EventFlow.Examples.Shipping.Domain.Model.CargoModel.ValueObjects; | ||
using EventFlow.Examples.Shipping.Domain.Model.VoyageModel; | ||
using EventFlow.ReadStores; | ||
|
||
namespace EventFlow.Examples.Shipping.Queries.InMemory.Cargos | ||
{ | ||
public class CargoReadModel : IReadModel, | ||
IAmReadModelFor<CargoAggregate, CargoId, CargoItinerarySetEvent>, | ||
IAmReadModelFor<CargoAggregate, CargoId, CargoBookedEvent> | ||
{ | ||
public CargoId Id { get; private set; } | ||
public HashSet<VoyageId> DependentVoyageIds { get; } = new HashSet<VoyageId>(); | ||
public Itinerary Itinerary { get; private set; } | ||
public Route Route { get; private set; } | ||
|
||
public void Apply(IReadModelContext context, IDomainEvent<CargoAggregate, CargoId, CargoBookedEvent> domainEvent) | ||
{ | ||
Id = domainEvent.AggregateIdentity; | ||
Route = domainEvent.AggregateEvent.Route; | ||
} | ||
|
||
public void Apply(IReadModelContext context, IDomainEvent<CargoAggregate, CargoId, CargoItinerarySetEvent> domainEvent) | ||
{ | ||
Itinerary = domainEvent.AggregateEvent.Itinerary; | ||
foreach (var transportLeg in domainEvent.AggregateEvent.Itinerary.TransportLegs) | ||
{ | ||
DependentVoyageIds.Add(transportLeg.VoyageId); | ||
} | ||
} | ||
|
||
public Cargo ToCargo() | ||
{ | ||
return new Cargo( | ||
Id, | ||
Route, | ||
Itinerary); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
....Shipping.Queries.InMemory/Cargos/QueryHandlers/GetCargosDependentOnVoyageQueryHandler.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,53 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015 Rasmus Mikkelsen | ||
// https://github.com/rasmus/EventFlow | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software is furnished to do so, | ||
// subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EventFlow.Examples.Shipping.Domain.Model.CargoModel; | ||
using EventFlow.Examples.Shipping.Domain.Model.CargoModel.Queries; | ||
using EventFlow.Queries; | ||
using EventFlow.ReadStores.InMemory; | ||
|
||
namespace EventFlow.Examples.Shipping.Queries.InMemory.Cargos.QueryHandlers | ||
{ | ||
public class GetCargosDependentOnVoyageQueryHandler : IQueryHandler<GetCargosDependentOnVoyageQuery, IReadOnlyCollection<Cargo>> | ||
{ | ||
private readonly IInMemoryReadStore<CargoReadModel> _readStore; | ||
|
||
public GetCargosDependentOnVoyageQueryHandler( | ||
IInMemoryReadStore<CargoReadModel> readStore) | ||
{ | ||
_readStore = readStore; | ||
} | ||
|
||
public async Task<IReadOnlyCollection<Cargo>> ExecuteQueryAsync(GetCargosDependentOnVoyageQuery query, CancellationToken cancellationToken) | ||
{ | ||
var cargoReadModels = await _readStore.FindAsync( | ||
rm => rm.DependentVoyageIds.Contains(query.VoyageId), | ||
cancellationToken) | ||
.ConfigureAwait(false); | ||
return cargoReadModels.Select(rm => rm.ToCargo()).ToList(); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ventFlow.Examples.Shipping.Queries.InMemory/Cargos/QueryHandlers/GetCargosQueryHandler.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,54 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015 Rasmus Mikkelsen | ||
// https://github.com/rasmus/EventFlow | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software is furnished to do so, | ||
// subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EventFlow.Examples.Shipping.Domain.Model.CargoModel; | ||
using EventFlow.Examples.Shipping.Domain.Model.CargoModel.Queries; | ||
using EventFlow.Queries; | ||
using EventFlow.ReadStores.InMemory; | ||
|
||
namespace EventFlow.Examples.Shipping.Queries.InMemory.Cargos.QueryHandlers | ||
{ | ||
public class GetCargosQueryHandler : IQueryHandler<GetCargosQuery, IReadOnlyCollection<Cargo>> | ||
{ | ||
private readonly IInMemoryReadStore<CargoReadModel> _readStore; | ||
|
||
public GetCargosQueryHandler( | ||
IInMemoryReadStore<CargoReadModel> readStore) | ||
{ | ||
_readStore = readStore; | ||
} | ||
|
||
public async Task<IReadOnlyCollection<Cargo>> ExecuteQueryAsync(GetCargosQuery query, CancellationToken cancellationToken) | ||
{ | ||
var cargoIds = new HashSet<CargoId>(query.CargoIds); | ||
var cargoReadModels = await _readStore.FindAsync( | ||
rm => cargoIds.Contains(rm.Id), | ||
cancellationToken) | ||
.ConfigureAwait(false); | ||
return cargoReadModels.Select(rm => rm.ToCargo()).ToList(); | ||
} | ||
} | ||
} |
Oops, something went wrong.