Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for saving multiple aggregates at once #19

Merged
merged 10 commits into from
May 29, 2024
10 changes: 9 additions & 1 deletion Tacta.EventStore.Test/Domain/AggregateRoots/BacklogItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public sealed class BacklogItem : AggregateRoot<BacklogItemId>

public string Summary { get; private set; }

public List<SubTask> SubTasks { get; private set; } = new List<SubTask>();

private BacklogItem() { }

public BacklogItem(IReadOnlyCollection<IDomainEvent> events) : base(events)
Expand All @@ -30,7 +32,7 @@ public static BacklogItem FromSummary(BacklogItemId id, string summary)
public TaskId AddTask(string title)
{
var task = new SubTask(new TaskId(), title);
AddDomainEvent(new SubTaskAdded(task.Id, task.Title));
Apply(new SubTaskAdded(task.Id, task.Title));

return task.Id;
}
Expand All @@ -40,5 +42,11 @@ public void On(BacklogItemCreated @event)
Id = @event.BacklogItemId;
Summary = @event.Summary;
}

public void On(SubTaskAdded @event)
{
var subTask = new SubTask(@event.TaskId, @event.Title);
SubTasks.Add(subTask);
}
}
}
10 changes: 10 additions & 0 deletions Tacta.EventStore.Test/Domain/DomainEvents/BacklogItemCreated.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json;
using Tacta.EventStore.Domain;
using Tacta.EventStore.Test.Domain.Identities;

Expand All @@ -16,5 +17,14 @@ public BacklogItemCreated(string summary, BacklogItemId backlogItemId) : base(ba
Summary = summary;
BacklogItemId = backlogItemId;
}

[JsonConstructor]
public BacklogItemCreated(Guid id, string aggregateId, DateTime createdAt, BacklogItemId backlogItemId,
string summary)
: base(id, aggregateId, createdAt)
{
BacklogItemId = backlogItemId;
Summary = summary;
}
}
}
14 changes: 12 additions & 2 deletions Tacta.EventStore.Test/Domain/DomainEvents/SubTaskAdded.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Tacta.EventStore.Domain;
using Tacta.EventStore.Test.Domain.Identities;

Expand All @@ -10,10 +12,18 @@ public class SubTaskAdded : DomainEvent

public TaskId TaskId { get; }

public SubTaskAdded(TaskId id, string title) : base(id.ToString())
public SubTaskAdded(TaskId taskId, string title) : base(taskId.ToString())
{
CreatedAt = DateTime.Now;
TaskId = id;
TaskId = taskId;
Title = title;
}

[JsonConstructor]
public SubTaskAdded(Guid id, string aggregateId, DateTime createdAt, TaskId taskId, string title)
: base(id, aggregateId, createdAt)
{
TaskId = taskId;
Title = title;
}
}
Expand Down
10 changes: 6 additions & 4 deletions Tacta.EventStore.Test/Domain/Identities/BacklogItemId.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
using System;
using Newtonsoft.Json;
using Tacta.EventStore.Domain;

namespace Tacta.EventStore.Test.Domain.Identities
{
public class BacklogItemId : EntityId
{
private readonly Guid _id;
public Guid Id { get; }

public BacklogItemId()
{
_id = Guid.NewGuid();
Id = Guid.NewGuid();
}

[JsonConstructor]
public BacklogItemId(Guid id)
{
_id = id;
Id = id;
}

public override string ToString()
{
return _id.ToString();
return Id.ToString();
}
}
}
17 changes: 15 additions & 2 deletions Tacta.EventStore.Test/Domain/Identities/TaskId.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
using Tacta.EventStore.Domain;
using System;
using Tacta.EventStore.Domain;

namespace Tacta.EventStore.Test.Domain.Identities
{
public class TaskId : EntityId
{
private readonly Guid _id;

public TaskId()
{
_id = Guid.NewGuid();
}

public TaskId(Guid id)
{
_id = id;
}

public override string ToString()
{
return "task_id";
return _id.ToString();
}
}
}
1 change: 1 addition & 0 deletions Tacta.EventStore.Test/Projector/ProjectionProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Tacta.EventStore.Domain;
using Tacta.EventStore.Projector;
using Tacta.EventStore.Repository;
using Tacta.EventStore.Repository.Models;
using Tacta.EventStore.Test.Projector.DomainEvents;
using Tacta.EventStore.Test.Projector.Projections;
using Tacta.EventStore.Test.Repository;
Expand Down
Loading
Loading