mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-05-06 05:20:54 +08:00
remove logical isDeleted and use global query instead
This commit is contained in:
parent
1ed1fb3339
commit
1c6bf65c65
@ -30,7 +30,7 @@ public class BookingProjection : IProjectionProcessor
|
|||||||
private async Task Apply(BookingCreatedDomainEvent @event, CancellationToken cancellationToken = default)
|
private async Task Apply(BookingCreatedDomainEvent @event, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var reservation =
|
var reservation =
|
||||||
await _bookingDbContext.Bookings.SingleOrDefaultAsync(x => x.Id == @event.Id && !x.IsDeleted,
|
await _bookingDbContext.Bookings.SingleOrDefaultAsync(x => x.Id == @event.Id,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
|
|
||||||
if (reservation == null)
|
if (reservation == null)
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public class CreateFlightCommandHandler : ICommandHandler<CreateFlightCommand, F
|
|||||||
{
|
{
|
||||||
Guard.Against.Null(command, nameof(command));
|
Guard.Against.Null(command, nameof(command));
|
||||||
|
|
||||||
var flight = await _flightDbContext.Flights.SingleOrDefaultAsync(x => x.Id == command.Id && !x.IsDeleted,
|
var flight = await _flightDbContext.Flights.SingleOrDefaultAsync(x => x.Id == command.Id,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
|
|
||||||
if (flight is not null)
|
if (flight is not null)
|
||||||
|
|||||||
@ -29,7 +29,7 @@ public class GetAvailableFlightsQueryHandler : IQueryHandler<GetAvailableFlights
|
|||||||
{
|
{
|
||||||
Guard.Against.Null(query, nameof(query));
|
Guard.Against.Null(query, nameof(query));
|
||||||
|
|
||||||
var flight = await _flightDbContext.Flights.Where(x => !x.IsDeleted).ToListAsync(cancellationToken);
|
var flight = await _flightDbContext.Flights.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
if (!flight.Any())
|
if (!flight.Any())
|
||||||
throw new FlightNotFountException();
|
throw new FlightNotFountException();
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public class GetFlightByIdQueryHandler : IQueryHandler<GetFlightByIdQuery, Fligh
|
|||||||
Guard.Against.Null(query, nameof(query));
|
Guard.Against.Null(query, nameof(query));
|
||||||
|
|
||||||
var flight =
|
var flight =
|
||||||
await _flightDbContext.Flights.SingleOrDefaultAsync(x => x.Id == query.Id && !x.IsDeleted, cancellationToken);
|
await _flightDbContext.Flights.SingleOrDefaultAsync(x => x.Id == query.Id, cancellationToken);
|
||||||
|
|
||||||
if (flight is null)
|
if (flight is null)
|
||||||
throw new FlightNotFountException();
|
throw new FlightNotFountException();
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public class UpdateFlightCommandHandler : ICommandHandler<UpdateFlightCommand, F
|
|||||||
{
|
{
|
||||||
Guard.Against.Null(command, nameof(command));
|
Guard.Against.Null(command, nameof(command));
|
||||||
|
|
||||||
var flight = await _flightDbContext.Flights.SingleOrDefaultAsync(x => x.Id == command.Id && !x.IsDeleted,
|
var flight = await _flightDbContext.Flights.SingleOrDefaultAsync(x => x.Id == command.Id,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
|
|
||||||
if (flight is null)
|
if (flight is null)
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public class CreateSeatCommandHandler : IRequestHandler<CreateSeatCommand, SeatR
|
|||||||
{
|
{
|
||||||
Guard.Against.Null(command, nameof(command));
|
Guard.Against.Null(command, nameof(command));
|
||||||
|
|
||||||
var seat = await _flightDbContext.Seats.SingleOrDefaultAsync(x => x.Id == command.Id && !x.IsDeleted, cancellationToken);
|
var seat = await _flightDbContext.Seats.SingleOrDefaultAsync(x => x.Id == command.Id, cancellationToken);
|
||||||
|
|
||||||
if (seat is not null)
|
if (seat is not null)
|
||||||
throw new SeatAlreadyExistException();
|
throw new SeatAlreadyExistException();
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public class GetAvailableSeatsQueryHandler : IRequestHandler<GetAvailableSeatsQu
|
|||||||
{
|
{
|
||||||
Guard.Against.Null(query, nameof(query));
|
Guard.Against.Null(query, nameof(query));
|
||||||
|
|
||||||
var seats = await _flightDbContext.Seats.Where(x => x.FlightId == query.FlightId && !x.IsDeleted).ToListAsync(cancellationToken);
|
var seats = await _flightDbContext.Seats.Where(x => x.FlightId == query.FlightId).ToListAsync(cancellationToken);
|
||||||
|
|
||||||
if (!seats.Any())
|
if (!seats.Any())
|
||||||
throw new AllSeatsFullException();
|
throw new AllSeatsFullException();
|
||||||
|
|||||||
@ -25,8 +25,7 @@ public class ReserveSeatCommandHandler : IRequestHandler<ReserveSeatCommand, Sea
|
|||||||
{
|
{
|
||||||
Guard.Against.Null(command, nameof(command));
|
Guard.Against.Null(command, nameof(command));
|
||||||
|
|
||||||
var seat = await _flightDbContext.Seats.SingleOrDefaultAsync(x => x.SeatNumber == command.SeatNumber && x.FlightId == command.FlightId
|
var seat = await _flightDbContext.Seats.SingleOrDefaultAsync(x => x.SeatNumber == command.SeatNumber && x.FlightId == command.FlightId, cancellationToken);
|
||||||
&& !x.IsDeleted, cancellationToken);
|
|
||||||
|
|
||||||
if (seat is null)
|
if (seat is null)
|
||||||
throw new SeatNumberIncorrectException();
|
throw new SeatNumberIncorrectException();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user