Skip to content

Commit

Permalink
Updated Notification eventing. Closes #30. Improves on #15.
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Apr 7, 2024
1 parent 23d3cce commit 5a57c5c
Show file tree
Hide file tree
Showing 199 changed files with 4,613 additions and 1,721 deletions.
108 changes: 67 additions & 41 deletions docs/design-principles/0050-domain-driven-design.md

Large diffs are not rendered by default.

Binary file modified docs/images/Persistence-Eventing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/Sources.pptx
Binary file not shown.
Binary file modified docs/images/Subdomains.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 6 additions & 18 deletions src/AncillaryDomain/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,41 @@ public static class EmailDelivery
public static Domain.Events.Shared.Ancillary.EmailDelivery.Created Created(Identifier id,
QueuedMessageId messageId)
{
return new Domain.Events.Shared.Ancillary.EmailDelivery.Created
return new Domain.Events.Shared.Ancillary.EmailDelivery.Created(id)
{
RootId = id,
OccurredUtc = DateTime.UtcNow,
MessageId = messageId
};
}

public static DeliveryAttempted DeliveryAttempted(Identifier id, DateTime when)
{
return new DeliveryAttempted
return new DeliveryAttempted(id)
{
RootId = id,
OccurredUtc = DateTime.UtcNow,
When = when
};
}

public static DeliveryFailed DeliveryFailed(Identifier id, DateTime when)
{
return new DeliveryFailed
return new DeliveryFailed(id)
{
RootId = id,
OccurredUtc = DateTime.UtcNow,
When = when
};
}

public static DeliverySucceeded DeliverySucceeded(Identifier id, DateTime when)
{
return new DeliverySucceeded
return new DeliverySucceeded(id)
{
RootId = id,
OccurredUtc = DateTime.UtcNow,
When = when
};
}

public static EmailDetailsChanged EmailDetailsChanged(Identifier id, string subject, string body,
EmailRecipient to)
{
return new EmailDetailsChanged
return new EmailDetailsChanged(id)
{
RootId = id,
OccurredUtc = DateTime.UtcNow,
Subject = subject,
Body = body,
ToEmailAddress = to.EmailAddress,
Expand All @@ -70,10 +60,8 @@ public static class Audits
public static Created Created(Identifier id, Identifier againstId, Optional<Identifier> organizationId,
string auditCode, Optional<string> messageTemplate, TemplateArguments templateArguments)
{
return new Created
return new Created(id)
{
RootId = id,
OccurredUtc = DateTime.UtcNow,
OrganizationId = organizationId.HasValue
? organizationId.Value.Text
: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class EventStreamChangeEvent
{
public required string Data { get; set; }

public required string EntityType { get; set; }
public required string RootAggregateType { get; set; }

public required string EventType { get; set; }

Expand Down
3 changes: 0 additions & 3 deletions src/Application.Services.Shared/IEndUsersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ namespace Application.Services.Shared;

public interface IEndUsersService
{
Task<Result<Membership, Error>> CreateMembershipForCallerPrivateAsync(ICallerContext caller, string organizationId,
CancellationToken cancellationToken);

Task<Result<Optional<EndUser>, Error>> FindPersonByEmailPrivateAsync(ICallerContext caller, string emailAddress,
CancellationToken cancellationToken);

Expand Down
4 changes: 0 additions & 4 deletions src/Application.Services.Shared/IOrganizationsService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Application.Interfaces;
using Application.Interfaces.Services;
using Application.Resources.Shared;
using Common;

namespace Application.Services.Shared;
Expand All @@ -10,9 +9,6 @@ public interface IOrganizationsService
Task<Result<Error>> ChangeSettingsPrivateAsync(ICallerContext caller, string id, TenantSettings settings,
CancellationToken cancellationToken);

Task<Result<Organization, Error>> CreateOrganizationPrivateAsync(ICallerContext caller, string creatorId,
string name, OrganizationOwnership ownership, CancellationToken cancellationToken);

Task<Result<TenantSettings, Error>> GetSettingsPrivateAsync(ICallerContext caller, string id,
CancellationToken cancellationToken);
}
8 changes: 0 additions & 8 deletions src/Application.Services.Shared/IUserProfilesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ namespace Application.Services.Shared;

public interface IUserProfilesService
{
Task<Result<UserProfile, Error>> CreateMachineProfilePrivateAsync(ICallerContext caller, string machineId,
string name,
string? timezone, string? countryCode, CancellationToken cancellationToken);

Task<Result<UserProfile, Error>> CreatePersonProfilePrivateAsync(ICallerContext caller, string personId,
string emailAddress,
string firstName, string? lastName, string? timezone, string? countryCode, CancellationToken cancellationToken);

Task<Result<Optional<UserProfile>, Error>> FindPersonByEmailAddressPrivateAsync(ICallerContext caller,
string emailAddress, CancellationToken cancellationToken);

Expand Down
3 changes: 1 addition & 2 deletions src/BookingsDomain.UnitTests/TripSpec.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Common;
using Domain.Common.Identity;
using Domain.Common.ValueObjects;
using Domain.Events.Shared.Bookings;
using FluentAssertions;
using Moq;
using UnitTesting.Common;
Expand All @@ -21,7 +20,7 @@ public TripSpec()
var idFactory = new FixedIdentifierFactory("anid");

_trip = Trip.Create(recorder.Object, idFactory, _ => Result.Ok).Value;
_trip.RaiseChangeEvent(TripAdded.Create("arootid".ToId(), "anorganizationid".ToId()));
_trip.RaiseChangeEvent(Events.TripAdded("arootid".ToId(), "anorganizationid".ToId()));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/BookingsDomain/BookingRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public Result<Error> StartTrip(Location from)
return Error.RuleViolation(Resources.BookingRoot_ReservationRequiresCar);
}

var added = RaiseChangeEvent(TripAdded.Create(Id, OrganizationId));
var added = RaiseChangeEvent(BookingsDomain.Events.TripAdded(Id, OrganizationId));
if (!added.IsSuccessful)
{
return added.Error;
Expand Down
39 changes: 19 additions & 20 deletions src/BookingsDomain/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,65 @@ public static class Events
{
public static CarChanged CarChanged(Identifier id, Identifier organizationId, Identifier carId)
{
return new CarChanged
return new CarChanged(id)
{
RootId = id,
OrganizationId = organizationId,
CarId = carId,
OccurredUtc = DateTime.UtcNow
CarId = carId
};
}

public static Created Created(Identifier id, Identifier organizationId)
{
return new Created
return new Created(id)
{
RootId = id,
OrganizationId = organizationId,
OccurredUtc = DateTime.UtcNow
OrganizationId = organizationId
};
}

public static ReservationMade ReservationMade(Identifier id, Identifier organizationId, Identifier borrowerId,
DateTime start, DateTime end)
{
return new ReservationMade
return new ReservationMade(id)
{
RootId = id,
OrganizationId = organizationId,
BorrowerId = borrowerId,
Start = start,
End = end,
OccurredUtc = DateTime.UtcNow
End = end
};
}

public static TripAdded TripAdded(Identifier id, Identifier organizationId)
{
return new TripAdded(id)
{
OrganizationId = organizationId,
TripId = null
};
}

public static TripBegan TripBegan(Identifier id, Identifier organizationId, Identifier tripId,
DateTime beganAt, Location from)
{
return new TripBegan
return new TripBegan(id)
{
RootId = id,
OrganizationId = organizationId,
TripId = tripId,
BeganAt = beganAt,
BeganFrom = from,
OccurredUtc = DateTime.UtcNow
BeganFrom = from
};
}

public static TripEnded TripEnded(Identifier id, Identifier organizationId, Identifier tripId, DateTime beganAt,
Location from, DateTime endedAt, Location to)
{
return new TripEnded
return new TripEnded(id)
{
RootId = id,
OrganizationId = organizationId,
TripId = tripId,
BeganAt = beganAt,
BeganFrom = from,
EndedAt = endedAt,
EndedTo = to,
OccurredUtc = DateTime.UtcNow
EndedTo = to
};
}
}
8 changes: 4 additions & 4 deletions src/CarsApplication.UnitTests/CarsApplicationSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public async Task WhenSearchAllAvailableCarsAsync_ThenReturnsAllAvailableCars()
ManufactureModel = "amodel",
ManufactureYear = 2023,
OrganizationId = "anorganizationid",
Status = "astatus",
Status = CarStatus.Registered,
VehicleOwnerId = "anownerid"
}
}));
Expand All @@ -348,7 +348,7 @@ await _application.SearchAllAvailableCarsAsync(_caller.Object, "anorganizationid
result.Value.Results[0].Owner!.Id.Should().Be("anownerid");
result.Value.Results[0].Plate!.Jurisdiction.Should().Be("ajurisdiction");
result.Value.Results[0].Plate!.Number.Should().Be("aplate");
result.Value.Results[0].Status.Should().Be("astatus");
result.Value.Results[0].Status.Should().Be(CarStatus.Registered.ToString());
}

[Fact]
Expand All @@ -369,7 +369,7 @@ public async Task WhenSearchAllCarsAsync_ThenReturnsAllCars()
ManufactureModel = "amodel",
ManufactureYear = 2023,
OrganizationId = "anorganizationid",
Status = "astatus",
Status = CarStatus.Registered,
VehicleOwnerId = "anownerid"
}
}));
Expand All @@ -388,7 +388,7 @@ public async Task WhenSearchAllCarsAsync_ThenReturnsAllCars()
result.Value.Results[0].Owner!.Id.Should().Be("anownerid");
result.Value.Results[0].Plate!.Jurisdiction.Should().Be("ajurisdiction");
result.Value.Results[0].Plate!.Number.Should().Be("aplate");
result.Value.Results[0].Status.Should().Be("astatus");
result.Value.Results[0].Status.Should().Be(CarStatus.Registered.ToString());
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/CarsApplication/CarsApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public static Car ToCar(this Persistence.ReadModels.Car car)
},
Plate = new CarLicensePlate
{ Jurisdiction = car.LicenseJurisdiction, Number = car.LicenseNumber },
Status = car.Status
Status = car.Status.ToString()
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/CarsApplication/Persistence/ReadModels/Car.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Application.Persistence.Common;
using CarsDomain;
using Common;
using Domain.Shared.Cars;
using QueryAny;

namespace CarsApplication.Persistence.ReadModels;
Expand All @@ -22,7 +23,7 @@ public class Car : ReadModelEntity

public Optional<string> OrganizationId { get; set; }

public Optional<string> Status { get; set; }
public Optional<CarStatus> Status { get; set; }

public Optional<string> VehicleOwnerId { get; set; }
}
4 changes: 2 additions & 2 deletions src/CarsDomain/CarRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected override Result<Error> OnStateChanged(IDomainEvent @event, bool isReco
case Created created:
{
OrganizationId = created.OrganizationId.ToId();
Status = created.Status.ToEnum<CarStatus>();
Status = created.Status;
return Result.Ok;
}

Expand Down Expand Up @@ -143,7 +143,7 @@ protected override Result<Error> OnStateChanged(IDomainEvent @event, bool isReco
}

License = plate.Value;
Status = changed.Status.ToEnum<CarStatus>();
Status = changed.Status;
Recorder.TraceDebug(null, "Car {Id} registration changed to {Jurisdiction}, {Number}", Id,
changed.Jurisdiction, changed.Number);
return Result.Ok;
Expand Down
Loading

0 comments on commit 5a57c5c

Please sign in to comment.