-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1090: Notification to the consumer when the product is back in stock #1091
Conversation
<div class="back-in-stock-subscribe"> | ||
<form action="api/stocks/back-in-stock"> | ||
<div> | ||
@if (SignInManager.IsSignedIn(User)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@if (SignInManager.IsSignedIn(User)) | |
@if (User.Identity.IsAuthenticated) |
public string GetCurrentHostName() | ||
{ | ||
return _httpContext.Request.Host.Value; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public string GetCurrentHostName() | |
{ | |
return _httpContext.Request.Host.Value; | |
} | |
public string GetCurrentHostName() => _httpContext.Request.Host.Value; | |
if (await _backInStockSubscriptionRepository.Query() | ||
.Where(o => o.ProductId == productId && o.CustomerEmail == customerEmail) | ||
.AnyAsync()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (await _backInStockSubscriptionRepository.Query() | |
.Where(o => o.ProductId == productId && o.CustomerEmail == customerEmail) | |
.AnyAsync()) | |
if (await _backInStockSubscriptionRepository.Query() | |
.AnyAsync(o => o.ProductId == productId && o.CustomerEmail == customerEmail)) |
|
||
namespace SimplCommerce.Module.Inventory.Event | ||
{ | ||
public class BackInStock : INotification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProductBackInStock might more meaningful
public BackInStockSendEmailHandler(IStockSubscriptionService stockSubscriptionService) | ||
{ | ||
_stockSubscriptionService = stockSubscriptionService; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public BackInStockSendEmailHandler(IStockSubscriptionService stockSubscriptionService) | |
{ | |
_stockSubscriptionService = stockSubscriptionService; | |
} | |
public BackInStockSendEmailHandler(IStockSubscriptionService stockSubscriptionService) | |
=> _stockSubscriptionService = stockSubscriptionService; |
public async Task Handle(BackInStock notification, CancellationToken cancellationToken) | ||
{ | ||
await _stockSubscriptionService.BackInStockSendNotificationsAsync(notification.ProductId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public async Task Handle(BackInStock notification, CancellationToken cancellationToken) | |
{ | |
await _stockSubscriptionService.BackInStockSendNotificationsAsync(notification.ProductId); | |
} | |
public async Task Handle(BackInStock notification, CancellationToken cancellationToken) | |
=> await _stockSubscriptionService.BackInStockSendNotificationsAsync(notification.ProductId); |
{ | ||
public class BackInStockSubscription : EntityBase | ||
{ | ||
public long ProductId { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public long ProductId { get; set; } | |
public long ProductId { get; set; } | |
@@ -12,6 +16,9 @@ public class ModuleInitializer : IModuleInitializer | |||
public void ConfigureServices(IServiceCollection serviceCollection) | |||
{ | |||
serviceCollection.AddTransient<IStockService, StockService>(); | |||
serviceCollection.AddTransient<IStockSubscriptionService, StockSubscriptionService>(); | |||
serviceCollection.AddTransient<INotificationHandler<BackInStock>, BackInStockSendEmailHandler>(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -44,6 +48,8 @@ public async Task UpdateStock(StockUpdateRequest stockUpdateRequest) | |||
var product = await _productRepository.Query().FirstOrDefaultAsync(x => x.Id == stockUpdateRequest.ProductId); | |||
var stock = await _stockRepository.Query().FirstOrDefaultAsync(x => x.ProductId == stockUpdateRequest.ProductId && x.WarehouseId == stockUpdateRequest.WarehouseId); | |||
|
|||
var prevStockQuantity = product.StockQuantity; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}; | ||
|
||
_backInStockSubscriptionRepository.Add(subscription); | ||
await _backInStockSubscriptionRepository.SaveChangesAsync(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await _backInStockSubscriptionRepository.SaveChangesAsync(); | |
await _backInStockSubscriptionRepository.SaveChangesAsync(); |
@thiennn I suggested some improvements to this PR also, there 're some non meaningful names, but seems you ignored all the my code suggestions |
@hishamco I can make your improvements in the new PR |
Believe it or not, it doesn't require a new PR, that's why the reviewing is helpful otherwise it's a waste of time if no one consider it Don't get me wrong |
No problem it happens :) |
#1090 Implementation