Skip to content

Commit

Permalink
feat: basically finish the design of budget aggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
osmanthuspeace committed Jul 21, 2024
1 parent 9c3023d commit a3b025e
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/Backend/Asset.Domain/Asset.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Folder Include="AssetAggregate\AssetEntity\" />
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions src/Backend/Asset.Domain/Class1.cs

This file was deleted.

4 changes: 4 additions & 0 deletions src/Backend/Budget.Domain/Budget.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Shared\Primitives\Primitives.csproj" />
</ItemGroup>

</Project>
39 changes: 39 additions & 0 deletions src/Backend/Budget.Domain/BudgetAggregate/BudgetEntity/Budget.cs
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));
}
}
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();
}
}
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;
}
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Budget.Domain.BudgetAggregate;

public interface IBudgetRepository
{

}
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;
}
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; }
}
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();
}
6 changes: 0 additions & 6 deletions src/Backend/Budget.Domain/Class1.cs

This file was deleted.

0 comments on commit a3b025e

Please sign in to comment.