Skip to content

Commit 39f3264

Browse files
feat: update policy created message model
1 parent 41fbb8c commit 39f3264

7 files changed

Lines changed: 30 additions & 10 deletions

File tree

DashboardService.Test/PolicyDocumentBuilder.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class PolicyDocumentBuilder
88
private readonly string policyHolder;
99
private string agentLogin;
1010
private DateTime from;
11+
private DateTime salesDate;
1112
private string number;
1213
private string productCode;
1314
private DateTime to;
@@ -18,6 +19,7 @@ public PolicyDocumentBuilder()
1819
number = Guid.NewGuid().ToString();
1920
from = new DateTime(2020, 1, 1);
2021
to = from.AddYears(1).AddDays(-1);
22+
salesDate = from;
2123
policyHolder = "Jan Test";
2224
productCode = "TRI";
2325
totalPremium = 100M;
@@ -39,6 +41,13 @@ public PolicyDocumentBuilder WithDates(string start, string end)
3941
{
4042
from = DateTime.Parse(start);
4143
to = DateTime.Parse(end);
44+
salesDate = from;
45+
return this;
46+
}
47+
48+
public PolicyDocumentBuilder WithSalesDate(string date)
49+
{
50+
salesDate = DateTime.Parse(date);
4251
return this;
4352
}
4453

@@ -67,6 +76,7 @@ public PolicyDocument Build()
6776
number,
6877
from,
6978
to,
79+
salesDate,
7080
policyHolder,
7181
productCode,
7282
totalPremium,

DashboardService/DataAccess/InMemory/LucenePolicyRepository.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public void Save(PolicyDocument policy)
3838
new StringField("agentLogin", policy.AgentLogin ?? string.Empty, Field.Store.YES),
3939
new StringField("productCode", policy.ProductCode ?? string.Empty, Field.Store.YES),
4040
new StringField("from", policy.From.ToString("o", CultureInfo.InvariantCulture), Field.Store.YES),
41+
new StringField("to", policy.To.ToString("o", CultureInfo.InvariantCulture), Field.Store.YES),
42+
new StringField("salesDate", policy.SalesDate.ToString("o", CultureInfo.InvariantCulture), Field.Store.YES),
43+
new StringField("policyHolder", policy.PolicyHolder ?? string.Empty, Field.Store.YES),
4144
new DoubleField("totalPremium", Convert.ToDouble(policy.TotalPremium), Field.Store.YES)
4245
};
4346

@@ -94,7 +97,7 @@ public SalesTrendsResult GetSalesTrend(SalesTrendsQuery query)
9497
var docs = SearchByFilters(null, query.FilterByProductCode, query.FilterBySalesDateStart, query.FilterBySalesDateEnd);
9598
var periods = docs.GroupBy(d =>
9699
{
97-
var dt = DateTime.Parse(d.Get("from"), null, DateTimeStyles.RoundtripKind);
100+
var dt = DateTime.Parse(d.Get("salesDate"), null, DateTimeStyles.RoundtripKind);
98101
return query.AggregationUnit switch
99102
{
100103
TimeAggregationUnit.Month => new DateTime(dt.Year, dt.Month, 1),
@@ -145,7 +148,7 @@ private IEnumerable<Document> SearchByFilters(string agentLogin, string productC
145148
{
146149
docs = docs.Where(d =>
147150
{
148-
var dt = DateTime.Parse(d.Get("from"), null, DateTimeStyles.RoundtripKind);
151+
var dt = DateTime.Parse(d.Get("salesDate"), null, DateTimeStyles.RoundtripKind);
149152
if (fromDate != default && dt < fromDate) return false;
150153
if (toDate != default && dt > toDate) return false;
151154
return true;
@@ -159,13 +162,14 @@ private static PolicyDocument DocToPolicy(Document doc)
159162
{
160163
var number = doc.Get("number");
161164
var from = DateTime.Parse(doc.Get("from"), null, DateTimeStyles.RoundtripKind);
162-
var to = from.AddYears(1).AddDays(-1);
163-
var insured = doc.Get("insuredName");
165+
var to = DateTime.Parse(doc.Get("to"), null, DateTimeStyles.RoundtripKind);
166+
var salesDate = DateTime.Parse(doc.Get("salesDate"), null, DateTimeStyles.RoundtripKind);
167+
var insured = doc.Get("policyHolder");
164168
var product = doc.Get("productCode");
165169
var premium = Convert.ToDecimal(doc.Get("totalPremium"));
166170
var agent = doc.Get("agentLogin");
167171

168-
return new PolicyDocument(number, from, to, insured, product, premium, agent);
172+
return new PolicyDocument(number, from, to, salesDate, insured, product, premium, agent);
169173
}
170174

171175
public void Dispose()

DashboardService/Domain/PolicyDocument.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ namespace DashboardService.Domain;
44

55
public class PolicyDocument
66
{
7-
public PolicyDocument(string number, DateTime from, DateTime to, string policyHolder, string productCode,
8-
decimal totalPremium, string agentLogin)
7+
public PolicyDocument(string number, DateTime from, DateTime to, DateTime salesDate, string policyHolder,
8+
string productCode, decimal totalPremium, string agentLogin)
99
{
1010
Number = number;
1111
From = from;
1212
To = to;
13+
SalesDate = salesDate;
1314
PolicyHolder = policyHolder;
1415
ProductCode = productCode;
1516
TotalPremium = totalPremium;
@@ -19,6 +20,7 @@ public PolicyDocument(string number, DateTime from, DateTime to, string policyHo
1920
public string Number { get; }
2021
public DateTime From { get; }
2122
public DateTime To { get; }
23+
public DateTime SalesDate { get; }
2224
public string PolicyHolder { get; }
2325
public string ProductCode { get; }
2426
public decimal TotalPremium { get; }

DashboardService/Init/SalesData.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ public async Task SeedData()
3434

3535
for (var index = 0; index < policies; index++)
3636
{
37+
var salesDate = new DateTime(startMonth.Year, startMonth.Month, 1);
3738
var policy = new PolicyDocument
3839
(
3940
Guid.NewGuid().ToString(),
40-
new DateTime(startMonth.Year, startMonth.Month, 1),
41-
new DateTime(startMonth.Year, startMonth.Month, 1).AddYears(1).AddDays(-1),
41+
salesDate,
42+
salesDate.AddYears(1).AddDays(-1),
43+
salesDate,
4244
"Anonymous Mike",
4345
product,
4446
100M,

DashboardService/Listeners/PolicyCreatedHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public Task Handle(PolicyCreated notification, CancellationToken cancellationTok
2222
notification.PolicyNumber,
2323
notification.PolicyFrom,
2424
notification.PolicyTo,
25+
notification.SalesDate,
2526
$"{notification.PolicyHolder.FirstName} {notification.PolicyHolder.LastName}",
2627
notification.ProductCode,
2728
notification.TotalPremium,

PolicyService.Api/Events/PolicyCreated.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class PolicyCreated : INotification
1010
public string ProductCode { get; set; }
1111
public DateTime PolicyFrom { get; set; }
1212
public DateTime PolicyTo { get; set; }
13+
public DateTime SalesDate { get; set; }
1314
public PersonDto PolicyHolder { get; set; }
1415
public decimal TotalPremium { get; set; }
1516
public string AgentLogin { get; set; }

PolicyService/Commands/CreatePolicyHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Linq;
22
using System.Threading;
33
using System.Threading.Tasks;
4-
using FluentValidation;
54
using MediatR;
65
using PolicyService.Api.Commands;
76
using PolicyService.Api.Commands.Dtos;
@@ -64,6 +63,7 @@ private static PolicyCreated PolicyCreated(Policy policy)
6463
PolicyNumber = policy.Number,
6564
PolicyFrom = version.CoverPeriod.ValidFrom,
6665
PolicyTo = version.CoverPeriod.ValidTo,
66+
SalesDate = policy.CreationDate,
6767
ProductCode = policy.ProductCode,
6868
TotalPremium = version.TotalPremiumAmount,
6969
PolicyHolder = new PersonDto

0 commit comments

Comments
 (0)