Skip to content

Commit 3b778b7

Browse files
authored
Merge pull request #10 from KhanbalaRashidov/master
primary constructors
2 parents 4b14c34 + 133712b commit 3b778b7

15 files changed

+44
-83
lines changed

Build/Nuke/Elastic/ElasticSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace MyCompany.ECommerce.Nuke.Elastic;
22

3-
public class ElasticSettings
3+
public record ElasticSettings
44
{
55
public const string Key = "Elastic";
66

Build/Nuke/Postgres/PostgresSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace MyCompany.ECommerce.Nuke.Postgres;
22

3-
public class PostgresSettings
3+
public record PostgresSettings
44
{
55
public const string Key = "Postgres";
66

Sources/Payments/Payments.ProcessModel/Requesting/PaymentRequestFulfilled.cs

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22

33
namespace MyCompany.ECommerce.Payments.Requesting;
44

5-
public class PaymentRequestFulfilled : DomainEvent
5+
public class PaymentRequestFulfilled(Guid requestId, DateTime fulfilledOn) : DomainEvent
66
{
7-
public Guid RequestId { get; }
8-
public DateTime FulfilledOn { get; }
9-
10-
public PaymentRequestFulfilled(Guid requestId, DateTime fulfilledOn)
11-
{
12-
RequestId = requestId;
13-
FulfilledOn = fulfilledOn;
14-
}
7+
public Guid RequestId { get; } = requestId;
8+
public DateTime FulfilledOn { get; } = fulfilledOn;
159
}

Sources/Payments/Payments.ProcessModel/Requesting/RequestPayment.cs

+5-13
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22

33
namespace MyCompany.ECommerce.Payments.Requesting;
44

5-
public readonly struct RequestPayment : Command
5+
public readonly struct RequestPayment(Guid requestId, Guid clientId, decimal amount, string currencyCode) : Command
66
{
7-
public Guid RequestId { get; }
8-
public Guid ClientId { get; }
9-
public decimal Amount { get; }
10-
public string CurrencyCode { get; }
11-
12-
public RequestPayment(Guid requestId, Guid clientId, decimal amount, string currencyCode)
13-
{
14-
RequestId = requestId;
15-
ClientId = clientId;
16-
Amount = amount;
17-
CurrencyCode = currencyCode;
18-
}
7+
public Guid RequestId { get; } = requestId;
8+
public Guid ClientId { get; } = clientId;
9+
public decimal Amount { get; } = amount;
10+
public string CurrencyCode { get; } = currencyCode;
1911
}

Sources/Sales/Sales.Adapters/Database/Sql/Raw/DbOrderItem.cs

+1-11
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,4 @@
33
namespace MyCompany.ECommerce.Sales.Database.Sql.Raw;
44

55
[Table("Sales_RawSql.OrderItems")]
6-
public record DbOrderItem
7-
{
8-
public Guid OrderId { get; init; }
9-
public Guid ProductId { get; init; }
10-
public string AmountUnit { get; init; }
11-
public int AmountValue { get; init; }
12-
public string PriceAgreementType { get; init; }
13-
public DateTime? PriceAgreementExpiresOn { get; init; }
14-
public decimal? Price { get; init; }
15-
public string Currency { get; init; }
16-
}
6+
public record DbOrderItem(Guid OrderId, Guid ProductId, string AmountUnit, int AmountValue, string PriceAgreementType, DateTime? PriceAgreementExpiresOn, decimal? Price, string Currency);

Sources/Sales/Sales.Adapters/Orders/InPLaceOrderEventsOutbox.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44

55
namespace MyCompany.ECommerce.Sales.Orders;
66

7-
public class InPlaceOrderEventsOutbox : InPlaceTransactionalOutbox<OrderEvent>, OrderEventsOutbox
8-
{
9-
[SuppressMessage("ReSharper", "SuggestBaseTypeForParameterInConstructor",
7+
[method: SuppressMessage("ReSharper", "SuggestBaseTypeForParameterInConstructor",
108
Justification = "Required by DI container")]
11-
public InPlaceOrderEventsOutbox(TransactionalOutboxes outboxes, TransactionalOutboxRepository repository,
12-
MessageTypes messageTypes)
13-
: base(outboxes, repository, messageTypes) { }
14-
9+
public class InPlaceOrderEventsOutbox(TransactionalOutboxes outboxes, TransactionalOutboxRepository repository,
10+
MessageTypes messageTypes) : InPlaceTransactionalOutbox<OrderEvent>(outboxes, repository, messageTypes), OrderEventsOutbox
11+
{
1512
protected override string GetPartitionKeyFor(OrderEvent message) => message.OrderId.ToString("N");
1613
}

Sources/Sales/Sales.Adapters/Orders/KafkaOrderEventsOutbox.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55

66
namespace MyCompany.ECommerce.Sales.Orders;
77

8-
public class KafkaOrderEventsOutbox : TransactionalKafkaOutbox<OrderEvent>, OrderEventsOutbox
8+
[method: SuppressMessage("ReSharper", "SuggestBaseTypeForParameter", Justification = "Required by DI container")]
9+
public class KafkaOrderEventsOutbox(TransactionalOutboxes outboxes, TransactionalOutboxRepository repository,
10+
MessageTypes messageTypes) : TransactionalKafkaOutbox<OrderEvent>(outboxes, repository, messageTypes), OrderEventsOutbox
911
{
1012
protected override string Topic => "OrderEvents";
1113

12-
[SuppressMessage("ReSharper", "SuggestBaseTypeForParameter", Justification = "Required by DI container")]
13-
public KafkaOrderEventsOutbox(TransactionalOutboxes outboxes, TransactionalOutboxRepository repository,
14-
MessageTypes messageTypes)
15-
: base(outboxes, repository, messageTypes) { }
16-
1714
protected override string GetPartitionKeyFor(OrderEvent message) => message.OrderId.ToString("N");
1815
}

Sources/Sales/Sales.Adapters/Orders/OrderSqlRepository.Document.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ namespace MyCompany.ECommerce.Sales.Orders;
99

1010
public static partial class OrderSqlRepository
1111
{
12-
public class Document : Order.Factory, Order.Repository
12+
public class Document([NotNull] RiskManagement riskManagement, IDocumentSession session)
13+
: Order.Factory(riskManagement), Order.Repository
1314
{
1415
private readonly Dictionary<OrderId, (DbOrder OrderData, Guid Version)> _orders = new();
15-
private readonly IDocumentSession _session;
16-
17-
public Document([NotNull] RiskManagement riskManagement, IDocumentSession session) : base(riskManagement) =>
18-
_session = session;
16+
private readonly IDocumentSession _session = session;
1917

2018
protected override Order.Data CreateData(OrderId id, Money maxTotalCost)
2119
{

Sources/Sales/Sales.Adapters/Orders/OrderSqlRepository.EF.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ namespace MyCompany.ECommerce.Sales.Orders;
99

1010
public static partial class OrderSqlRepository
1111
{
12-
public class EF : Order.Factory, Order.Repository
12+
public class EF([NotNull] RiskManagement riskManagement, SalesDbContext dbContext)
13+
: Order.Factory(riskManagement), Order.Repository
1314
{
1415
private readonly Dictionary<OrderId, DbOrder> _orders = new();
15-
private readonly SalesDbContext _dbContext;
16-
17-
public EF([NotNull] RiskManagement riskManagement, SalesDbContext dbContext) : base(riskManagement) =>
18-
_dbContext = dbContext;
16+
private readonly SalesDbContext _dbContext = dbContext;
1917

2018
protected override Order.Data CreateData(OrderId id, Money maxTotalCost)
2119
{

Sources/Sales/Sales.Adapters/Orders/OrderSqlRepository.Raw.Data.cs

+11-12
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,16 @@ public Data(OrderId id, Money maxTotalCost)
4141

4242
private static TrackedSet<Order.Item, DbOrderItem> CreateItemsSet(Guid id,
4343
IEnumerable<DbOrderItem> dbOrderItems) => new(dbOrderItems,
44-
item => new DbOrderItem
45-
{
46-
OrderId = id,
47-
ProductId = item.ProductAmount.ProductId.Value,
48-
AmountUnit = item.ProductAmount.Amount.Unit.ToString(),
49-
AmountValue = item.ProductAmount.Amount.Value,
50-
PriceAgreementType = item.PriceAgreement.Type.ToString(),
51-
Price = item.PriceAgreement.Price?.Value,
52-
Currency = item.PriceAgreement.Price?.Currency.ToString(),
53-
PriceAgreementExpiresOn = item.PriceAgreement.ExpiresOn
54-
},
44+
item => new DbOrderItem(
45+
id,
46+
item.ProductAmount.ProductId.Value,
47+
item.ProductAmount.Amount.Unit.ToString(),
48+
item.ProductAmount.Amount.Value,
49+
item.PriceAgreement.Type.ToString(),
50+
item.PriceAgreement.ExpiresOn,
51+
item.PriceAgreement.Price?.Value,
52+
item.PriceAgreement.Price?.Currency.ToString()!
53+
),
5554
dbItem => new Order.Item(
5655
new ProductAmount(
5756
ProductId.From(dbItem.ProductId),
@@ -76,7 +75,7 @@ protected override async Task SaveNestedDbEntities(IDbTransaction transaction)
7675
var (added, updated, deleted) = _items.GetDiff();
7776
await transaction.Connection.InsertAllAsync(added, transaction: transaction);
7877
await transaction.Connection.UpdateAllAsync(updated,
79-
qualifiers: i => new { i.OrderId, i.ProductId, i.AmountUnit },
78+
qualifiers: i => new { i.OrderId, i.ProductId, i.AmountUnit },
8079
transaction: transaction);
8180
await transaction.Connection.DeleteAllAsync(deleted, transaction: transaction);
8281
}

Sources/Sales/Sales.DeepModel/Pricing/CalculatePrices.cs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public async Task<Offer> For(ClientId clientId, SalesChannel salesChannel,
3232
priceLists.GetBasePricesFor(clientId, productAmounts),
3333
offerModifiers.ChooseFor(offerRequest),
3434
exchangeRates.GetFor(currency));
35+
3536
return Offer.WithBasePrices(productAmounts, basePrices)
3637
.Apply(offerModifier)
3738
.Apply(exchangeRate);

Sources/Sales/Sales.DeepModel/Pricing/Discounts/ClientLevelDiscounts.cs

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55
namespace MyCompany.ECommerce.Sales.Pricing.Discounts;
66

77
[DddDomainService]
8-
public class ClientLevelDiscounts : OfferModifier, QuoteModifier
8+
public class ClientLevelDiscounts(PercentageDiscount baseDiscountValue,
9+
IEnumerable<ProductDiscount> productDiscounts) : OfferModifier, QuoteModifier
910
{
10-
private readonly PercentageDiscount _baseDiscount;
11+
private readonly PercentageDiscount _baseDiscount = baseDiscountValue;
1112

12-
private readonly ImmutableDictionary<ProductUnit, Discount> _productDiscounts;
13-
14-
public ClientLevelDiscounts(PercentageDiscount baseDiscountValue, IEnumerable<ProductDiscount> productDiscounts)
15-
{
16-
_baseDiscount = baseDiscountValue;
17-
_productDiscounts = productDiscounts.ToImmutableDictionary(
13+
private readonly ImmutableDictionary<ProductUnit, Discount> _productDiscounts = productDiscounts.ToImmutableDictionary(
1814
d => d.ProductUnit, d => d.Discount);
19-
}
2015

2116
public Offer ApplyOn(Offer offer) => offer.Apply((QuoteModifier) this);
2217

Sources/Sales/Sales.DeepModel/Pricing/IndividualSalesConditions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public Quote ApplyOn(Quote quote)
1515
{
1616
var quote1 =clientLevelDiscounts.ApplyOn(quote);
1717
var quote2 = productLevelDiscounts.ApplyOn(quote);
18+
1819
return quote1.Price < quote2.Price ? quote1 : quote2;
1920
}
2021
}

Sources/Sales/Sales.DeepModel/Pricing/OfferModifiers.cs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ private async Task<OfferModifier> GetIndividualSalesConditions(OfferRequest offe
2323
var (clientLevelDiscounts, productLevelDiscounts) = await (
2424
discountsRepository.GetFor(offerRequest.ClientId),
2525
discountsRepository.GetFor(offerRequest.ProductAmounts));
26+
2627
return new IndividualSalesConditions(clientLevelDiscounts, productLevelDiscounts);
2728
}
2829

Sources/Search/Search.Infrastructure/Products/ProductElasticRepository.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
namespace MyCompany.ECommerce.Search.Products;
44

55
[UsedImplicitly]
6-
internal class ProductElasticRepository : ProductRepository
6+
internal class ProductElasticRepository(SearchDb db) : ProductRepository
77
{
8-
private readonly SearchDb _db;
9-
10-
public ProductElasticRepository(SearchDb db) => _db = db;
8+
private readonly SearchDb _db = db;
119
}

0 commit comments

Comments
 (0)