Skip to content

feat: Rename _context variable #8

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Expand Up @@ -2,24 +2,24 @@
{
public class PaymentCompletedEventConsumer : IConsumer<PaymentCompletedEvent>
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;
private readonly ILogger<PaymentCompletedEventConsumer> _logger;

public PaymentCompletedEventConsumer(
AppDbContext context,
AppDbContext dbContext,
ILogger<PaymentCompletedEventConsumer> logger)
{
_context = context;
_dbContext = dbContext;
_logger = logger;
}

public async Task Consume(ConsumeContext<PaymentCompletedEvent> context)
{
var order = await _context.Orders.FindAsync(context.Message.OrderId);
var order = await _dbContext.Orders.FindAsync(context.Message.OrderId);
if (order is not null)
{
order.Status = OrderStatus.Completed;
await _context.SaveChangesAsync();
await _dbContext.SaveChangesAsync();

_logger.LogInformation("Order (Id={@orderId}) status changed : {@orderStatus}", context.Message.OrderId, order.Status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
{
public class PaymentFailedEventConsumer : IConsumer<PaymentFailedEvent>
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;
private readonly ILogger<PaymentCompletedEventConsumer> _logger;

public PaymentFailedEventConsumer(
AppDbContext context,
AppDbContext dbContext,
ILogger<PaymentCompletedEventConsumer> logger)
{
_context = context;
_dbContext = dbContext;
_logger = logger;
}

public async Task Consume(ConsumeContext<PaymentFailedEvent> context)
{
var order = await _context.Orders.FindAsync(context.Message.OrderId);
var order = await _dbContext.Orders.FindAsync(context.Message.OrderId);
if (order is not null)
{
order.Status = OrderStatus.Fail;
order.FailMessage = context.Message.Message;
await _context.SaveChangesAsync();
await _dbContext.SaveChangesAsync();

_logger.LogInformation("Order (Id={@orderId}) status changed : {@orderStatus}", context.Message.OrderId, order.Status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
{
public class StockNotReservedEventConsumer : IConsumer<StockNotReservedEvent>
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;
private readonly ILogger<PaymentCompletedEventConsumer> _logger;

public StockNotReservedEventConsumer(
AppDbContext context,
AppDbContext dbContext,
ILogger<PaymentCompletedEventConsumer> logger)
{
_context = context;
_dbContext = dbContext;
_logger = logger;
}

public async Task Consume(ConsumeContext<StockNotReservedEvent> context)
{
var order = await _context.Orders.FindAsync(context.Message.OrderId);
var order = await _dbContext.Orders.FindAsync(context.Message.OrderId);
if (order is not null)
{
order.Status = OrderStatus.Fail;
order.FailMessage = context.Message.Message;
await _context.SaveChangesAsync();
await _dbContext.SaveChangesAsync();

_logger.LogInformation("Order (Id={@orderId}) status changed : {@orderStatus}", context.Message.OrderId, order.Status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
[ApiController]
public class OrdersController : ControllerBase
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;
private readonly IPublishEndpoint _publishEndpoint;

public OrdersController(
AppDbContext context,
AppDbContext dbContext,
IPublishEndpoint publishEndpoint)
{
_context = context;
_dbContext = dbContext;
_publishEndpoint = publishEndpoint;
}

Expand Down Expand Up @@ -73,8 +73,8 @@ private async Task<Order> AddOrderAsync(OrderCreateRequest request)
});
});

await _context.AddAsync(order);
await _context.SaveChangesAsync();
await _dbContext.AddAsync(order);
await _dbContext.SaveChangesAsync();

return order;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
{
public class OrderCreatedEventConsumer : IConsumer<OrderCreatedEvent>
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;
private readonly ILogger<OrderCreatedEventConsumer> _logger;
private readonly ISendEndpointProvider _sendEndpointProvider;
private readonly IPublishEndpoint _publishEndpoint;

public OrderCreatedEventConsumer
(AppDbContext context,
(AppDbContext dbContext,
ILogger<OrderCreatedEventConsumer> logger,
ISendEndpointProvider sendEndpointProvider,
IPublishEndpoint publishEndpoint)
{
_context = context;
_dbContext = dbContext;
_logger = logger;
_sendEndpointProvider = sendEndpointProvider;
_publishEndpoint = publishEndpoint;
Expand All @@ -39,11 +39,11 @@ public async Task Consume(ConsumeContext<OrderCreatedEvent> context)

foreach (var orderItem in context.Message.OrderItems)
{
var stock = await _context.Stocks.FirstOrDefaultAsync(x => x.ProductId == orderItem.ProductId);
var stock = await _dbContext.Stocks.FirstOrDefaultAsync(x => x.ProductId == orderItem.ProductId);

stock.Count -= orderItem.Count;

await _context.SaveChangesAsync();
await _dbContext.SaveChangesAsync();
}

_logger.LogInformation("Stock was reserved for buyer Id :{@buyerId}", context.Message.BuyerId);
Expand All @@ -69,7 +69,7 @@ private async Task<bool> CheckStockOfAllProductsAsync(ConsumeContext<OrderCreate
{
foreach (var orderItem in context.Message.OrderItems)
{
bool isHasStock = await _context.Stocks.AnyAsync(x => x.ProductId == orderItem.ProductId && x.Count > orderItem.Count);
bool isHasStock = await _dbContext.Stocks.AnyAsync(x => x.ProductId == orderItem.ProductId && x.Count > orderItem.Count);
if (!isHasStock)
{
return isHasStock; //herhangi bir üründe stok yoksa işlemi bitir.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
{
public class PaymentFailedEventConsumer : IConsumer<PaymentFailedEvent>
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;
private readonly ILogger<PaymentFailedEventConsumer> _logger;

public PaymentFailedEventConsumer(
AppDbContext context,
AppDbContext dbContext,
ILogger<PaymentFailedEventConsumer> logger)
{
_context = context;
_dbContext = dbContext;
_logger = logger;
}

public async Task Consume(ConsumeContext<PaymentFailedEvent> context)
{
foreach (var item in context.Message.OrderItems)
{
var stock = await _context.Stocks.FirstOrDefaultAsync(x => x.ProductId == item.ProductId);
var stock = await _dbContext.Stocks.FirstOrDefaultAsync(x => x.ProductId == item.ProductId);
if (stock is not null)
{
stock.Count += item.Count;
await _context.SaveChangesAsync();
await _dbContext.SaveChangesAsync();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
[ApiController]
public class StocksController : ControllerBase
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;

public StocksController(AppDbContext context)
public StocksController(AppDbContext dbContext)
{
_context = context;
_dbContext = dbContext;
}

[HttpGet]
public async Task<IActionResult> All(CancellationToken cancellationToken)
{
var stocks = await _context.Stocks.ToListAsync(cancellationToken);
var stocks = await _dbContext.Stocks.ToListAsync(cancellationToken);
if (!stocks.Any())
{
return NotFound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
{
public class GetProductsByUserIdQueryHandler : IRequestHandler<GetProductsByUserIdQuery, List<ProductDto>>
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;

public GetProductsByUserIdQueryHandler(AppDbContext context)
public GetProductsByUserIdQueryHandler(AppDbContext dbContext)
{
_context = context;
_dbContext = dbContext;
}

public async Task<List<ProductDto>> Handle(GetProductsByUserIdQuery request, CancellationToken cancellationToken)
{
var products = await _context.Products
var products = await _dbContext.Products
.Where(product => product.UserId == request.UserId)
.Select(product => new ProductDto
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
{
public class OrderRequestCompletedEventConsumer : IConsumer<IOrchestrationOrderRequestCompletedEvent>
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;
private readonly ILogger<OrderRequestCompletedEventConsumer> _logger;

public OrderRequestCompletedEventConsumer(AppDbContext context, ILogger<OrderRequestCompletedEventConsumer> logger)
public OrderRequestCompletedEventConsumer(AppDbContext dbContext, ILogger<OrderRequestCompletedEventConsumer> logger)
{
_context = context;
_dbContext = dbContext;
_logger = logger;
}

public async Task Consume(ConsumeContext<IOrchestrationOrderRequestCompletedEvent> context)
{
var order = await _context.Orders.FindAsync(context.Message.OrderId);
var order = await _dbContext.Orders.FindAsync(context.Message.OrderId);
if (order is not null)
{
order.Status = OrderStatus.Completed;
await _context.SaveChangesAsync();
await _dbContext.SaveChangesAsync();

_logger.LogInformation($"Order (Id={context.Message.OrderId}) status changed : {order.Status}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
{
public class OrderRequestFailedEventConsumer : IConsumer<IOrchestrationOrderRequestFailedEvent>
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;
private readonly ILogger<OrderRequestFailedEventConsumer> _logger;

public OrderRequestFailedEventConsumer(AppDbContext context, ILogger<OrderRequestFailedEventConsumer> logger)
public OrderRequestFailedEventConsumer(AppDbContext dbContext, ILogger<OrderRequestFailedEventConsumer> logger)
{
_context = context;
_dbContext = dbContext;
_logger = logger;
}

public async Task Consume(ConsumeContext<IOrchestrationOrderRequestFailedEvent> context)
{
var order = await _context.Orders.FindAsync(context.Message.OrderId);
var order = await _dbContext.Orders.FindAsync(context.Message.OrderId);

if (order != null)
{
order.Status = OrderStatus.Fail;
order.FailMessage = context.Message.Reason;
await _context.SaveChangesAsync();
await _dbContext.SaveChangesAsync();

_logger.LogInformation($"Order (Id={context.Message.OrderId}) status changed : {order.Status}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace Orchestration.OrderService.API.Controllers
[ApiController]
public class OrdersController : ControllerBase
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;
private readonly ISendEndpointProvider _sendEndpointProvider;

public OrdersController(
AppDbContext context,
AppDbContext dbContext,
ISendEndpointProvider sendEndpointProvider)
{
_context = context;
_dbContext = dbContext;
_sendEndpointProvider = sendEndpointProvider;
}

Expand Down Expand Up @@ -76,8 +76,8 @@ private async Task<Order> AddOrderAsync(OrderCreateRequest request)
});
});

await _context.AddAsync(order);
await _context.SaveChangesAsync();
await _dbContext.AddAsync(order);
await _dbContext.SaveChangesAsync();

return order;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
{
public class OrderCreatedEventConsumer : IConsumer<IOrchestrationOrderCreatedEvent>
{
private readonly AppDbContext _context;
private readonly AppDbContext _dbContext;
private readonly ILogger<OrderCreatedEventConsumer> _logger;
private readonly IPublishEndpoint _publishEndpoint;

public OrderCreatedEventConsumer
(AppDbContext context,
(AppDbContext dbContext,
ILogger<OrderCreatedEventConsumer> logger,
IPublishEndpoint publishEndpoint)
{
_context = context;
_dbContext = dbContext;
_logger = logger;
_publishEndpoint = publishEndpoint;
}
Expand All @@ -33,11 +33,11 @@ await _publishEndpoint.Publish<IOrchestrationStockNotReservedEvent>(new Orchestr

foreach (var orderItem in context.Message.OrderItems)
{
var stock = await _context.Stocks.FirstOrDefaultAsync(x => x.ProductId == orderItem.ProductId);
var stock = await _dbContext.Stocks.FirstOrDefaultAsync(x => x.ProductId == orderItem.ProductId);

stock.Count -= orderItem.Count;

await _context.SaveChangesAsync();
await _dbContext.SaveChangesAsync();
}

_logger.LogInformation("Stock was reserved for CorrelationId Id :{@correlationId}", context.Message.CorrelationId);
Expand All @@ -58,7 +58,7 @@ private async Task<bool> CheckStockOfAllProductsAsync(ConsumeContext<IOrchestrat
{
foreach (var orderItem in context.Message.OrderItems)
{
bool isHasStock = await _context.Stocks.AnyAsync(x => x.ProductId == orderItem.ProductId && x.Count > orderItem.Count);
bool isHasStock = await _dbContext.Stocks.AnyAsync(x => x.ProductId == orderItem.ProductId && x.Count > orderItem.Count);
if (!isHasStock)
{
return isHasStock; //herhangi bir üründe stok yoksa işlemi bitir.
Expand Down
Loading