Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using CustomCADs.Modules.Accounts.Domain.Repositories;
using CustomCADs.Modules.Accounts.Domain.Repositories.Reads;
using CustomCADs.Modules.Accounts.Domain.Repositories.Writes;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Identity;

namespace CustomCADs.Modules.Accounts.Application.Accounts.Events.Application;

public class UserDeletedHandler(IAccountReads reads, IAccountWrites writes, IUnitOfWork uow)
public class UserDeletedHandler(
IAccountReads reads,
IAccountWrites writes,
IUnitOfWork uow
) : IEventHandler<UserDeletedApplicationEvent>
{
public async Task HandleAsync(UserDeletedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using CustomCADs.Modules.Accounts.Domain.Repositories;
using CustomCADs.Modules.Accounts.Domain.Repositories.Reads;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Identity;

namespace CustomCADs.Modules.Accounts.Application.Accounts.Events.Application;

public class UserEditedHandler(IAccountReads reads, IUnitOfWork uow)
: IEventHandler<UserEditedApplicationEvent>
{
public async Task HandleAsync(UserEditedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using CustomCADs.Modules.Accounts.Domain.Repositories;
using CustomCADs.Modules.Accounts.Domain.Repositories.Writes;
using CustomCADs.Shared.Application.Events.Catalog;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Account.Accounts;

namespace CustomCADs.Modules.Accounts.Application.Accounts.Events.Application;

public class ProductViewedHandler(IAccountWrites writes, IUnitOfWork uow)
public class UserViewedProductHandler(IAccountWrites writes, IUnitOfWork uow)
: IEventHandler<UserViewedProductApplicationEvent>
{
public async Task HandleAsync(ProductViewedApplicationEvent @event)
public async Task HandleAsync(UserViewedProductApplicationEvent @event)
{
await writes.ViewProductAsync(@event.AccountId, @event.Id, @event.ViewedAt).ConfigureAwait(false);
await uow.SaveChangesAsync().ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using CustomCADs.Modules.Carts.Domain.Repositories;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Catalog;

namespace CustomCADs.Modules.Carts.Application.ActiveCarts.Events.Application.ProductDeleted;

public class ProductDeletedHandler(IUnitOfWork uow)
: IEventHandler<ProductDeletedApplicationEvent>
{
public async Task HandleAsync(ProductDeletedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CustomCADs.Modules.Carts.Application.ActiveCarts.Events.Application.DeliveryRequested;
using CustomCADs.Modules.Carts.Domain.Repositories;
using CustomCADs.Modules.Carts.Domain.Repositories.Reads;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Abstractions.Requests.Sender;
using CustomCADs.Shared.Application.UseCases.Accounts.Queries;
using CustomCADs.Shared.Application.UseCases.Shipments.Commands;
Expand All @@ -12,7 +13,7 @@ public class ActiveCartDeliveryRequestedHandler(
IPurchasedCartReads reads,
IUnitOfWork uow,
IRequestSender sender
)
) : IEventHandler<ActiveCartDeliveryRequestedApplicationEvent>
{
public async Task HandleAsync(ActiveCartDeliveryRequestedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CustomCADs.Modules.Carts.Domain.Repositories;
using CustomCADs.Modules.Carts.Domain.Repositories.Reads;
using CustomCADs.Shared.Application.Abstractions.Email;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Abstractions.Requests.Sender;
using CustomCADs.Shared.Application.Events.Carts;
using CustomCADs.Shared.Application.UseCases.Accounts.Queries;
Expand All @@ -15,7 +16,7 @@ public class CartPaymentCompletedHandler(
IUnitOfWork uow,
IRequestSender sender,
IEmailService email
)
) : IEventHandler<CartPaymentCompletedApplicationEvent>
{
public async Task HandleAsync(CartPaymentCompletedApplicationEvent @event)
{
Expand All @@ -27,24 +28,30 @@ public async Task HandleAsync(CartPaymentCompletedApplicationEvent @event)

await uow.BulkDeleteItemsByBuyerIdAsync(@event.BuyerId).ConfigureAwait(false);

string to = await sender.SendQueryAsync(
string recipient = await sender.SendQueryAsync(
query: new GetUserEmailByIdQuery(@event.BuyerId)
).ConfigureAwait(false);

string url = await sender.SendQueryAsync(
string clientUrl = await sender.SendQueryAsync(
query: new GetClientUrlQuery()
).ConfigureAwait(false);

await email.SendRewardGrantedEmailAsync(to, $"{url}/carts/{cart.Id}").ConfigureAwait(false);
await email.SendRewardGrantedEmailAsync(recipient, $"{clientUrl}/carts/{cart.Id}").ConfigureAwait(false);

if (cart is { HasDelivery: true, ShipmentId: not null })
if (cart.HasDelivery)
{
ShipmentId shipmentId = cart.ShipmentId.Value;

await sender.SendCommandAsync(
new ActivateShipmentCommand(shipmentId)
).ConfigureAwait(false);
await email.SendRewardGrantedEmailAsync(to, $"{url}/shipments/{shipmentId}").ConfigureAwait(false);
await ActivateShipmentAsync(cart.ShipmentId).ConfigureAwait(false);
await email.SendRewardGrantedEmailAsync(recipient, $"{clientUrl}/shipments/{cart.ShipmentId}").ConfigureAwait(false);
}
}

private async Task ActivateShipmentAsync(ShipmentId? shipmentId)
{
if (shipmentId is null)
throw new CustomException("Shipment Activation requested, but missing ShipmentId");

await sender.SendCommandAsync(
command: new ActivateShipmentCommand(shipmentId.Value)
).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using CustomCADs.Modules.Catalog.Domain.Repositories;
using CustomCADs.Modules.Catalog.Domain.Repositories.Writes;
using CustomCADs.Shared.Application.Abstractions.Events;

namespace CustomCADs.Modules.Catalog.Application.Products.Events.Application.ProductCreated;

public class ProductCreatedHandler(IProductWrites writes, IUnitOfWork uow)
: IEventHandler<ProductCreatedApplicationEvent>
{
public async Task HandleAsync(ProductCreatedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using CustomCADs.Modules.Catalog.Domain.Repositories;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Catalog;

namespace CustomCADs.Modules.Catalog.Application.Products.Events.Application.ProductPurchased;

public sealed class ProductsPurchasedHandler(IUnitOfWork uow)
: IEventHandler<ProductsPurchasedApplicationEvent>
{
public async Task HandleAsync(ProductsPurchasedApplicationEvent req, CancellationToken ct)
public async Task HandleAsync(ProductsPurchasedApplicationEvent req)
{
await uow.AddProductsPurchasesAsync(req.Ids, count: 1, ct: ct).ConfigureAwait(false);
await uow.AddProductsPurchasesAsync(req.Ids, count: 1).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
using CustomCADs.Modules.Catalog.Domain.Repositories.Reads;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Abstractions.Requests.Sender;
using CustomCADs.Shared.Application.Events.Account.Accounts;
using CustomCADs.Shared.Application.Events.Catalog;
using CustomCADs.Shared.Application.UseCases.Accounts.Queries;

namespace CustomCADs.Modules.Catalog.Application.Products.Events.Application.ProductViewed;

public class ProductViewedHandler(IProductReads reads, IUnitOfWork uow, IRequestSender sender, IEventRaiser raiser)
public class ProductViewedHandler(
IProductReads reads,
IUnitOfWork uow,
IRequestSender sender,
IEventRaiser raiser
) : IEventHandler<ProductViewedApplicationEvent>
{
public async Task HandleAsync(ProductViewedApplicationEvent @event)
{
Expand All @@ -16,14 +22,13 @@ public async Task HandleAsync(ProductViewedApplicationEvent @event)
).ConfigureAwait(false);
if (userAlreadyViewed) return;

var account = await sender.SendQueryAsync(
AccountInfoDto account = await sender.SendQueryAsync(
query: new GetAccountInfoByUsernameQuery(
Username: await sender.SendQueryAsync(
query: new GetUsernameByIdQuery(@event.AccountId)
).ConfigureAwait(false)
)
).ConfigureAwait(false);

if (!account.TrackViewedProducts) return;

Product product = await reads.SingleByIdAsync(@event.Id).ConfigureAwait(false)
Expand All @@ -33,7 +38,7 @@ public async Task HandleAsync(ProductViewedApplicationEvent @event)
await uow.SaveChangesAsync().ConfigureAwait(false);

await raiser.RaiseApplicationEventAsync(
@event: new ProductViewedApplicationEvent(
@event: new UserViewedProductApplicationEvent(
Id: @event.Id,
AccountId: @event.AccountId,
ViewedAt: @event.ViewedAt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CustomCADs.Modules.Customs.Domain.Repositories;
using CustomCADs.Modules.Customs.Domain.Repositories.Reads;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Abstractions.Requests.Sender;
using CustomCADs.Shared.Application.UseCases.Accounts.Queries;
using CustomCADs.Shared.Application.UseCases.Shipments.Commands;
Expand All @@ -11,7 +12,7 @@ public class CustomDeliveryRequestedHandler(
ICustomReads reads,
IUnitOfWork uow,
IRequestSender sender
)
) : IEventHandler<CustomDeliveryRequestedApplicationEvent>
{
public async Task HandleAsync(CustomDeliveryRequestedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CustomCADs.Modules.Customs.Domain.Repositories;
using CustomCADs.Modules.Customs.Domain.Repositories.Reads;
using CustomCADs.Shared.Application.Abstractions.Email;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Abstractions.Requests.Sender;
using CustomCADs.Shared.Application.Events.Customs;
using CustomCADs.Shared.Application.UseCases.Accounts.Queries;
Expand All @@ -15,7 +16,7 @@ public class CustomPaymentCompletedHandler(
IUnitOfWork uow,
IRequestSender sender,
IEmailService email
)
) : IEventHandler<CustomPaymentCompletedApplicationEvent>
{
public async Task HandleAsync(CustomPaymentCompletedApplicationEvent @event)
{
Expand All @@ -25,24 +26,31 @@ public async Task HandleAsync(CustomPaymentCompletedApplicationEvent @event)
custom.FinishPayment(success: true);
await uow.SaveChangesAsync().ConfigureAwait(false);

string to = await sender.SendQueryAsync(
string recipient = await sender.SendQueryAsync(
query: new GetUserEmailByIdQuery(@event.BuyerId)
).ConfigureAwait(false);

string url = await sender.SendQueryAsync(
string clientUrl = await sender.SendQueryAsync(
query: new GetClientUrlQuery()
).ConfigureAwait(false);

await email.SendRewardGrantedEmailAsync(to, $"{url}/customs/{custom.Id}").ConfigureAwait(false);
await email.SendRewardGrantedEmailAsync(recipient, $"{clientUrl}/customs/{custom.Id}").ConfigureAwait(false);

if (custom is { ForDelivery: true, CompletedCustom.ShipmentId: not null })
if (custom.ForDelivery)
{
ShipmentId shipmentId = custom.CompletedCustom.ShipmentId.Value;

await sender.SendCommandAsync(
command: new ActivateShipmentCommand(shipmentId)
).ConfigureAwait(false);
await email.SendRewardGrantedEmailAsync(to, $"{url}/shipments/{shipmentId}").ConfigureAwait(false);
ShipmentId? shipmentId = custom.CompletedCustom?.ShipmentId;
await ActivateShipmentAsync(shipmentId).ConfigureAwait(false);
await email.SendRewardGrantedEmailAsync(recipient, $"{clientUrl}/shipments/{shipmentId}").ConfigureAwait(false);
}
}

private async Task ActivateShipmentAsync(ShipmentId? shipmentId)
{
if (shipmentId is null)
throw new CustomException("Shipment Activation requested, but missing ShipmentId");

await sender.SendCommandAsync(
command: new ActivateShipmentCommand(shipmentId.Value)
).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
using CustomCADs.Modules.Files.Application.Cads.Storage;
using CustomCADs.Modules.Files.Domain.Repositories;
using CustomCADs.Modules.Files.Domain.Repositories.Reads;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Catalog;

namespace CustomCADs.Modules.Files.Application.Cads.Events.Application;

public class ProductDeletedHandler(ICadReads reads, IWrites<Cad> writes, IUnitOfWork uow, ICadStorageService storage, BaseCachingService<CadId, Cad> cache)
public class ProductDeletedHandler(
ICadReads reads,
IWrites<Cad> writes,
IUnitOfWork uow,
ICadStorageService storage,
BaseCachingService<CadId, Cad> cache
) : IEventHandler<ProductDeletedApplicationEvent>
{
public async Task HandleAsync(ProductDeletedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
using CustomCADs.Modules.Files.Application.Images.Storage;
using CustomCADs.Modules.Files.Domain.Repositories;
using CustomCADs.Modules.Files.Domain.Repositories.Reads;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Catalog;

namespace CustomCADs.Modules.Files.Application.Images.Events.Application;

public class ProductDeletedHandler(IImageReads reads, IWrites<Image> writes, IUnitOfWork uow, IImageStorageService storage, BaseCachingService<ImageId, Image> cache)
public class ProductDeletedHandler(
IImageReads reads,
IWrites<Image> writes,
IUnitOfWork uow,
IImageStorageService storage,
BaseCachingService<ImageId, Image> cache
) : IEventHandler<ProductDeletedApplicationEvent>
{
public async Task HandleAsync(ProductDeletedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using CustomCADs.Shared.Application.Abstractions.Email;
using CustomCADs.Shared.Application.Abstractions.Events;

namespace CustomCADs.Modules.Identity.Application.Users.Events.Application.Emails.EmailVerification;

public class EmailVerificationRequestedEventHandler(IEmailService email)
public class EmailVerificationRequestedHandler(IEmailService email)
: IEventHandler<EmailVerificationRequestedApplicationEvent>
{
public async Task HandleAsync(EmailVerificationRequestedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using CustomCADs.Shared.Application.Abstractions.Email;
using CustomCADs.Shared.Application.Abstractions.Events;

namespace CustomCADs.Modules.Identity.Application.Users.Events.Application.Emails.PasswordReset;

public class PasswordResetRequestedEventHandler(IEmailService email)
public class PasswordResetRequestedHandler(IEmailService email)
: IEventHandler<PasswordResetRequestedApplicationEvent>
{
public async Task HandleAsync(PasswordResetRequestedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using CustomCADs.Shared.Application.Events.Account.Roles;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Account.Roles;

namespace CustomCADs.Modules.Identity.Application.Users.Events.Application.Roles;

public class RoleCreatedHandler(IRoleService service)
public class RoleCreatedHandler(IRoleService service) : IEventHandler<RoleCreatedApplicationEvent>
{
public async Task HandleAsync(RoleCreatedApplicationEvent @event)
=> await service.CreateAsync(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using CustomCADs.Shared.Application.Events.Account.Roles;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Account.Roles;

namespace CustomCADs.Modules.Identity.Application.Users.Events.Application.Roles;

public class RoleDeletedHandler(IRoleService service)
public class RoleDeletedHandler(IRoleService service) : IEventHandler<RoleDeletedApplicationEvent>
{
public async Task HandleAsync(RoleDeletedApplicationEvent @event)
=> await service.DeleteAsync(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using CustomCADs.Shared.Application.Events.Account.Accounts;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Account.Accounts;

namespace CustomCADs.Modules.Identity.Application.Users.Events.Application.Users;

public class AccountCreatedHandler(IUserService service)
: IEventHandler<AccountCreatedApplicationEvent>
{
public async Task HandleAsync(AccountCreatedApplicationEvent @event)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using CustomCADs.Shared.Application.Events.Account.Accounts;
using CustomCADs.Shared.Application.Abstractions.Events;
using CustomCADs.Shared.Application.Events.Account.Accounts;

namespace CustomCADs.Modules.Identity.Application.Users.Events.Application.Users;

public class AccountDeletedHandler(IUserService service)
: IEventHandler<AccountDeletedApplicationEvent>
{
public async Task HandleAsync(AccountDeletedApplicationEvent @event)
{
Expand Down
Loading
Loading