-
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.
Builder uses Summary Mapper with template method
- Loading branch information
Showing
11 changed files
with
168 additions
and
68 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/Domain/AggregatesModel/ReportAggregate/CreateReportHandlers/CreateDailyReportHandler.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
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
2 changes: 1 addition & 1 deletion
2
src/Domain/AggregatesModel/ReportAggregate/CreateReportHandlers/CreateReportHandler.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
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
2 changes: 1 addition & 1 deletion
2
src/Domain/AggregatesModel/ReportAggregate/CreateReportHandlers/ICreateReportHandler.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
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
35 changes: 35 additions & 0 deletions
35
...Domain/AggregatesModel/ReportAggregate/ReportBuilder/SummaryMappers/DailySummaryMapper.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,35 @@ | ||
using Domain.AggregatesModel.TransactionAggregate; | ||
using Domain.Extensions; | ||
using Domain.ValueObjects; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Domain.AggregatesModel.ReportAggregate.ReportBuilder.SummaryMappers; | ||
public class DailySummaryMapper : SummaryMapper | ||
{ | ||
protected override DateOnly GetStartDate(DateOnly date) | ||
{ | ||
return date; | ||
} | ||
protected override DateOnly NextDate(DateOnly currentDate) | ||
{ | ||
return currentDate.AddDays(1); | ||
} | ||
|
||
protected override decimal GetTotalAmount(DateOnly currentDate, IEnumerable<Transaction> transactions) | ||
{ | ||
return transactions.Where(t => | ||
t.OperationDate.IsDate(currentDate)) | ||
.Sum(o => o.RealAmount); | ||
} | ||
|
||
protected override Summary CreateSummary(DateOnly currentDate, decimal amount) | ||
{ | ||
return new Summary(amount, | ||
DateRange.Create(currentDate, currentDate) | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...main/AggregatesModel/ReportAggregate/ReportBuilder/SummaryMappers/MonthlySummaryMapper.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,40 @@ | ||
using Domain.AggregatesModel.TransactionAggregate; | ||
using Domain.Extensions; | ||
using Domain.ValueObjects; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Domain.AggregatesModel.ReportAggregate.ReportBuilder.SummaryMappers; | ||
public class MonthlySummaryMapper : SummaryMapper | ||
{ | ||
protected override DateOnly GetStartDate(DateOnly date) | ||
{ | ||
return date.GetStartOfMonth(); | ||
} | ||
protected override DateOnly NextDate(DateOnly currentDate) | ||
{ | ||
return currentDate.AddMonths(1); | ||
} | ||
|
||
protected override decimal GetTotalAmount(DateOnly currentDate, IEnumerable<Transaction> transactions) | ||
{ | ||
var startOfMonthDateTime = currentDate.GetStartOfMonth().ToDateTime(TimeOnly.MinValue); | ||
var endOfMonthDateTime = currentDate.GetEndOfMonth().ToDateTime(TimeOnly.MaxValue); | ||
|
||
return transactions.Where(t => | ||
t.OperationDate.Date >= startOfMonthDateTime && | ||
t.OperationDate.Date <= endOfMonthDateTime) | ||
.Sum(o => o.RealAmount); | ||
} | ||
|
||
protected override Summary CreateSummary(DateOnly currentDate, decimal amount) | ||
{ | ||
return new Summary(amount, | ||
DateRange.Create(currentDate.GetStartOfMonth(), | ||
currentDate.GetEndOfMonth()) | ||
); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Domain/AggregatesModel/ReportAggregate/ReportBuilder/SummaryMappers/SummaryMapper.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 Domain.AggregatesModel.TransactionAggregate; | ||
using Domain.Extensions; | ||
using Domain.ValueObjects; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Domain.AggregatesModel.ReportAggregate.ReportBuilder.SummaryMappers; | ||
public abstract class SummaryMapper | ||
{ | ||
public IEnumerable<Summary> MapToSummaries(IEnumerable<Transaction> transactions) | ||
{ | ||
var summaries = new List<Summary>(); | ||
|
||
var dateRange = transactions.GetDateRange(); | ||
|
||
var currentDate = GetStartDate(dateRange.Start); | ||
|
||
while (currentDate <= dateRange.End) | ||
{ | ||
decimal totalAmount = GetTotalAmount(currentDate, transactions); | ||
|
||
var summary = CreateSummary(currentDate, totalAmount); | ||
|
||
summaries.Add(summary); | ||
|
||
currentDate = NextDate(currentDate); | ||
} | ||
|
||
return summaries; | ||
} | ||
|
||
protected abstract DateOnly GetStartDate(DateOnly date); | ||
protected abstract DateOnly NextDate(DateOnly currentDate); | ||
protected abstract decimal GetTotalAmount(DateOnly currentDate, IEnumerable<Transaction> transactions); | ||
protected abstract Summary CreateSummary(DateOnly currentDate, decimal amount); | ||
} |
40 changes: 40 additions & 0 deletions
40
...omain/AggregatesModel/ReportAggregate/ReportBuilder/SummaryMappers/WeeklySummaryMapper.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,40 @@ | ||
using Domain.AggregatesModel.TransactionAggregate; | ||
using Domain.Extensions; | ||
using Domain.ValueObjects; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Domain.AggregatesModel.ReportAggregate.ReportBuilder.SummaryMappers; | ||
public class WeeklySummaryMapper : SummaryMapper | ||
{ | ||
protected override DateOnly GetStartDate(DateOnly date) | ||
{ | ||
return date.GetStartOfWeek(); | ||
} | ||
protected override DateOnly NextDate(DateOnly currentDate) | ||
{ | ||
return currentDate.AddDays(7); | ||
} | ||
|
||
protected override decimal GetTotalAmount(DateOnly currentDate, IEnumerable<Transaction> transactions) | ||
{ | ||
var startOfWeekDateTime = currentDate.GetStartOfWeek().ToDateTime(TimeOnly.MinValue); | ||
var endOfWeekDateTime = currentDate.GetEndOfWeek().ToDateTime(TimeOnly.MaxValue); | ||
|
||
return transactions.Where(t => | ||
t.OperationDate.Date >= startOfWeekDateTime && | ||
t.OperationDate.Date <= endOfWeekDateTime) | ||
.Sum(o => o.RealAmount); | ||
} | ||
|
||
protected override Summary CreateSummary(DateOnly currentDate, decimal amount) | ||
{ | ||
return new Summary(amount, | ||
DateRange.Create(currentDate.GetStartOfWeek(), | ||
currentDate.GetEndOfWeek()) | ||
); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Domain/AggregatesModel/ReportAggregate/ReportMakerFacade.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