-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basically finish the design of budget aggregate
- Loading branch information
1 parent
9c3023d
commit a3b025e
Showing
12 changed files
with
115 additions
and
12 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 was deleted.
Oops, something went wrong.
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
39 changes: 39 additions & 0 deletions
39
src/Backend/Budget.Domain/BudgetAggregate/BudgetEntity/Budget.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,39 @@ | ||
using Budget.Domain.BudgetAggregate.BudgetEntity.Events; | ||
using Budget.Domain.BudgetAggregate.SubBudgetEntity; | ||
using Primitives.Entity; | ||
using Shared.Primitives; | ||
|
||
namespace Budget.Domain.BudgetAggregate.BudgetEntity; | ||
|
||
public class Budget : EntityBase<BudgetId>, IAggregateRoot<Budget> | ||
{ | ||
private Budget(DateTime startDate, DateTime endDate, decimal amount, string description) : base(new BudgetId(1)) | ||
{ | ||
StartDate = startDate; | ||
EndDate = endDate; | ||
Amount = amount; | ||
Description = description; | ||
SubBudgets = new List<SubBudget>(); | ||
} | ||
|
||
public DateTime StartDate { get; private set; } | ||
public DateTime EndDate { get; private set; } | ||
public decimal Amount { get; private set; } | ||
public string Description { get; private set; } | ||
private List<SubBudget> SubBudgets { get; set; } | ||
|
||
|
||
public static Budget CreateBudget(DateTime startDate, DateTime endDate, decimal amount, string description) | ||
{ | ||
var budget= new Budget(startDate, endDate, amount, description); | ||
budget.AddDomainEvent(new BudgetCreatedDomainEvent(budget.Id)); | ||
return budget; | ||
} | ||
|
||
public void AddSubBudget(string tag, decimal amount) | ||
{ | ||
var subBudget = SubBudget.CreateSubBudget(tag, amount); | ||
SubBudgets.Add(subBudget); | ||
subBudget.AddDomainEvent(new SubBudgetAddedDomainEvent(subBudget.Id)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Backend/Budget.Domain/BudgetAggregate/BudgetEntity/BudgetId.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,9 @@ | ||
namespace Budget.Domain.BudgetAggregate.BudgetEntity; | ||
|
||
public readonly record struct BudgetId(long Value) | ||
{ | ||
public override string ToString() | ||
{ | ||
return Value.ToString(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Backend/Budget.Domain/BudgetAggregate/BudgetEntity/Events/BudgetCreatedDomainEvent.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,8 @@ | ||
using Shared.Primitives.DomainEvent; | ||
|
||
namespace Budget.Domain.BudgetAggregate.BudgetEntity.Events; | ||
|
||
public class BudgetCreatedDomainEvent(BudgetId budgetId):IDomainEvent | ||
{ | ||
public BudgetId BudgetId { get; } = budgetId; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Backend/Budget.Domain/BudgetAggregate/BudgetEntity/Events/SubBudgetAddedDomainEvent.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,9 @@ | ||
using Budget.Domain.BudgetAggregate.SubBudgetEntity; | ||
using Shared.Primitives.DomainEvent; | ||
|
||
namespace Budget.Domain.BudgetAggregate.BudgetEntity.Events; | ||
|
||
public class SubBudgetAddedDomainEvent(SubBudgetId subBudgetId) : IDomainEvent | ||
{ | ||
public SubBudgetId SubBudgetId { get; } = subBudgetId; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Backend/Budget.Domain/BudgetAggregate/IBudgetRepository.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,6 @@ | ||
namespace Budget.Domain.BudgetAggregate; | ||
|
||
public interface IBudgetRepository | ||
{ | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...ckend/Budget.Domain/BudgetAggregate/SubBudgetEntity/Events/SubBudgetCreatedDomainEvent.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,8 @@ | ||
using Shared.Primitives.DomainEvent; | ||
|
||
namespace Budget.Domain.BudgetAggregate.SubBudgetEntity.Events; | ||
|
||
public class SubBudgetCreatedDomainEvent(SubBudgetId subBudgetId) : IDomainEvent | ||
{ | ||
public SubBudgetId SubBudgetId { get; } = subBudgetId; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Backend/Budget.Domain/BudgetAggregate/SubBudgetEntity/SubBudget.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,22 @@ | ||
using Budget.Domain.BudgetAggregate.SubBudgetEntity.Events; | ||
using Primitives.Entity; | ||
|
||
namespace Budget.Domain.BudgetAggregate.SubBudgetEntity; | ||
|
||
public class SubBudget : EntityBase<SubBudgetId> | ||
{ | ||
private SubBudget(string tag, decimal amount) : base(new SubBudgetId(1)) | ||
{ | ||
Tag = tag; | ||
Amount = amount; | ||
} | ||
public static SubBudget CreateSubBudget(string tag, decimal amount) | ||
{ | ||
var subBudget= new SubBudget(tag, amount); | ||
subBudget.AddDomainEvent(new SubBudgetCreatedDomainEvent(subBudget.Id)); | ||
return subBudget; | ||
} | ||
|
||
public string Tag { get; private set; } | ||
public decimal Amount { get; private set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Backend/Budget.Domain/BudgetAggregate/SubBudgetEntity/SubBudgetId.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,6 @@ | ||
namespace Budget.Domain.BudgetAggregate.SubBudgetEntity; | ||
|
||
public readonly record struct SubBudgetId(long Value) | ||
{ | ||
public override string ToString() => Value.ToString(); | ||
} |
This file was deleted.
Oops, something went wrong.