Skip to content

Commit

Permalink
Merge pull request #10 from KhanbalaRashidov/master
Browse files Browse the repository at this point in the history
primary constructors
  • Loading branch information
technites-pl authored Jul 30, 2024
2 parents 4b14c34 + 133712b commit 3b778b7
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Build/Nuke/Elastic/ElasticSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace MyCompany.ECommerce.Nuke.Elastic;

public class ElasticSettings
public record ElasticSettings
{
public const string Key = "Elastic";

Expand Down
2 changes: 1 addition & 1 deletion Build/Nuke/Postgres/PostgresSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace MyCompany.ECommerce.Nuke.Postgres;

public class PostgresSettings
public record PostgresSettings
{
public const string Key = "Postgres";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

namespace MyCompany.ECommerce.Payments.Requesting;

public class PaymentRequestFulfilled : DomainEvent
public class PaymentRequestFulfilled(Guid requestId, DateTime fulfilledOn) : DomainEvent
{
public Guid RequestId { get; }
public DateTime FulfilledOn { get; }

public PaymentRequestFulfilled(Guid requestId, DateTime fulfilledOn)
{
RequestId = requestId;
FulfilledOn = fulfilledOn;
}
public Guid RequestId { get; } = requestId;
public DateTime FulfilledOn { get; } = fulfilledOn;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@

namespace MyCompany.ECommerce.Payments.Requesting;

public readonly struct RequestPayment : Command
public readonly struct RequestPayment(Guid requestId, Guid clientId, decimal amount, string currencyCode) : Command
{
public Guid RequestId { get; }
public Guid ClientId { get; }
public decimal Amount { get; }
public string CurrencyCode { get; }

public RequestPayment(Guid requestId, Guid clientId, decimal amount, string currencyCode)
{
RequestId = requestId;
ClientId = clientId;
Amount = amount;
CurrencyCode = currencyCode;
}
public Guid RequestId { get; } = requestId;
public Guid ClientId { get; } = clientId;
public decimal Amount { get; } = amount;
public string CurrencyCode { get; } = currencyCode;
}
12 changes: 1 addition & 11 deletions Sources/Sales/Sales.Adapters/Database/Sql/Raw/DbOrderItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,4 @@
namespace MyCompany.ECommerce.Sales.Database.Sql.Raw;

[Table("Sales_RawSql.OrderItems")]
public record DbOrderItem
{
public Guid OrderId { get; init; }
public Guid ProductId { get; init; }
public string AmountUnit { get; init; }
public int AmountValue { get; init; }
public string PriceAgreementType { get; init; }
public DateTime? PriceAgreementExpiresOn { get; init; }
public decimal? Price { get; init; }
public string Currency { get; init; }
}
public record DbOrderItem(Guid OrderId, Guid ProductId, string AmountUnit, int AmountValue, string PriceAgreementType, DateTime? PriceAgreementExpiresOn, decimal? Price, string Currency);
11 changes: 4 additions & 7 deletions Sources/Sales/Sales.Adapters/Orders/InPLaceOrderEventsOutbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

namespace MyCompany.ECommerce.Sales.Orders;

public class InPlaceOrderEventsOutbox : InPlaceTransactionalOutbox<OrderEvent>, OrderEventsOutbox
{
[SuppressMessage("ReSharper", "SuggestBaseTypeForParameterInConstructor",
[method: SuppressMessage("ReSharper", "SuggestBaseTypeForParameterInConstructor",
Justification = "Required by DI container")]
public InPlaceOrderEventsOutbox(TransactionalOutboxes outboxes, TransactionalOutboxRepository repository,
MessageTypes messageTypes)
: base(outboxes, repository, messageTypes) { }

public class InPlaceOrderEventsOutbox(TransactionalOutboxes outboxes, TransactionalOutboxRepository repository,
MessageTypes messageTypes) : InPlaceTransactionalOutbox<OrderEvent>(outboxes, repository, messageTypes), OrderEventsOutbox
{
protected override string GetPartitionKeyFor(OrderEvent message) => message.OrderId.ToString("N");
}
9 changes: 3 additions & 6 deletions Sources/Sales/Sales.Adapters/Orders/KafkaOrderEventsOutbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@

namespace MyCompany.ECommerce.Sales.Orders;

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

[SuppressMessage("ReSharper", "SuggestBaseTypeForParameter", Justification = "Required by DI container")]
public KafkaOrderEventsOutbox(TransactionalOutboxes outboxes, TransactionalOutboxRepository repository,
MessageTypes messageTypes)
: base(outboxes, repository, messageTypes) { }

protected override string GetPartitionKeyFor(OrderEvent message) => message.OrderId.ToString("N");
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ namespace MyCompany.ECommerce.Sales.Orders;

public static partial class OrderSqlRepository
{
public class Document : Order.Factory, Order.Repository
public class Document([NotNull] RiskManagement riskManagement, IDocumentSession session)
: Order.Factory(riskManagement), Order.Repository
{
private readonly Dictionary<OrderId, (DbOrder OrderData, Guid Version)> _orders = new();
private readonly IDocumentSession _session;

public Document([NotNull] RiskManagement riskManagement, IDocumentSession session) : base(riskManagement) =>
_session = session;
private readonly IDocumentSession _session = session;

protected override Order.Data CreateData(OrderId id, Money maxTotalCost)
{
Expand Down
8 changes: 3 additions & 5 deletions Sources/Sales/Sales.Adapters/Orders/OrderSqlRepository.EF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ namespace MyCompany.ECommerce.Sales.Orders;

public static partial class OrderSqlRepository
{
public class EF : Order.Factory, Order.Repository
public class EF([NotNull] RiskManagement riskManagement, SalesDbContext dbContext)
: Order.Factory(riskManagement), Order.Repository
{
private readonly Dictionary<OrderId, DbOrder> _orders = new();
private readonly SalesDbContext _dbContext;

public EF([NotNull] RiskManagement riskManagement, SalesDbContext dbContext) : base(riskManagement) =>
_dbContext = dbContext;
private readonly SalesDbContext _dbContext = dbContext;

protected override Order.Data CreateData(OrderId id, Money maxTotalCost)
{
Expand Down
23 changes: 11 additions & 12 deletions Sources/Sales/Sales.Adapters/Orders/OrderSqlRepository.Raw.Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ public Data(OrderId id, Money maxTotalCost)

private static TrackedSet<Order.Item, DbOrderItem> CreateItemsSet(Guid id,
IEnumerable<DbOrderItem> dbOrderItems) => new(dbOrderItems,
item => new DbOrderItem
{
OrderId = id,
ProductId = item.ProductAmount.ProductId.Value,
AmountUnit = item.ProductAmount.Amount.Unit.ToString(),
AmountValue = item.ProductAmount.Amount.Value,
PriceAgreementType = item.PriceAgreement.Type.ToString(),
Price = item.PriceAgreement.Price?.Value,
Currency = item.PriceAgreement.Price?.Currency.ToString(),
PriceAgreementExpiresOn = item.PriceAgreement.ExpiresOn
},
item => new DbOrderItem(
id,
item.ProductAmount.ProductId.Value,
item.ProductAmount.Amount.Unit.ToString(),
item.ProductAmount.Amount.Value,
item.PriceAgreement.Type.ToString(),
item.PriceAgreement.ExpiresOn,
item.PriceAgreement.Price?.Value,
item.PriceAgreement.Price?.Currency.ToString()!
),
dbItem => new Order.Item(
new ProductAmount(
ProductId.From(dbItem.ProductId),
Expand All @@ -76,7 +75,7 @@ protected override async Task SaveNestedDbEntities(IDbTransaction transaction)
var (added, updated, deleted) = _items.GetDiff();
await transaction.Connection.InsertAllAsync(added, transaction: transaction);
await transaction.Connection.UpdateAllAsync(updated,
qualifiers: i => new { i.OrderId, i.ProductId, i.AmountUnit },
qualifiers: i => new { i.OrderId, i.ProductId, i.AmountUnit },
transaction: transaction);
await transaction.Connection.DeleteAllAsync(deleted, transaction: transaction);
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Sales/Sales.DeepModel/Pricing/CalculatePrices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public async Task<Offer> For(ClientId clientId, SalesChannel salesChannel,
priceLists.GetBasePricesFor(clientId, productAmounts),
offerModifiers.ChooseFor(offerRequest),
exchangeRates.GetFor(currency));

return Offer.WithBasePrices(productAmounts, basePrices)
.Apply(offerModifier)
.Apply(exchangeRate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
namespace MyCompany.ECommerce.Sales.Pricing.Discounts;

[DddDomainService]
public class ClientLevelDiscounts : OfferModifier, QuoteModifier
public class ClientLevelDiscounts(PercentageDiscount baseDiscountValue,
IEnumerable<ProductDiscount> productDiscounts) : OfferModifier, QuoteModifier
{
private readonly PercentageDiscount _baseDiscount;
private readonly PercentageDiscount _baseDiscount = baseDiscountValue;

private readonly ImmutableDictionary<ProductUnit, Discount> _productDiscounts;

public ClientLevelDiscounts(PercentageDiscount baseDiscountValue, IEnumerable<ProductDiscount> productDiscounts)
{
_baseDiscount = baseDiscountValue;
_productDiscounts = productDiscounts.ToImmutableDictionary(
private readonly ImmutableDictionary<ProductUnit, Discount> _productDiscounts = productDiscounts.ToImmutableDictionary(
d => d.ProductUnit, d => d.Discount);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public Quote ApplyOn(Quote quote)
{
var quote1 =clientLevelDiscounts.ApplyOn(quote);
var quote2 = productLevelDiscounts.ApplyOn(quote);

return quote1.Price < quote2.Price ? quote1 : quote2;
}
}
1 change: 1 addition & 0 deletions Sources/Sales/Sales.DeepModel/Pricing/OfferModifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private async Task<OfferModifier> GetIndividualSalesConditions(OfferRequest offe
var (clientLevelDiscounts, productLevelDiscounts) = await (
discountsRepository.GetFor(offerRequest.ClientId),
discountsRepository.GetFor(offerRequest.ProductAmounts));

return new IndividualSalesConditions(clientLevelDiscounts, productLevelDiscounts);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace MyCompany.ECommerce.Search.Products;

[UsedImplicitly]
internal class ProductElasticRepository : ProductRepository
internal class ProductElasticRepository(SearchDb db) : ProductRepository
{
private readonly SearchDb _db;

public ProductElasticRepository(SearchDb db) => _db = db;
private readonly SearchDb _db = db;
}

0 comments on commit 3b778b7

Please sign in to comment.