-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#126 Accessibility - query metadata in booked records
- Loading branch information
1 parent
938c66e
commit 371112f
Showing
6 changed files
with
75 additions
and
57 deletions.
There are no files selected for viewing
13 changes: 5 additions & 8 deletions
13
...pplication/Bookings/Queries/GetBookedRecordsOfFacility/GetBookedRecordsOfFacilityQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Core.Queries; | ||
|
||
namespace Accessibility.Application.Bookings.Queries.GetBookedRecordsOfFacility | ||
{ | ||
public class GetBookedRecordsOfFacilityQuery : IQuery<List<BookedRecordOfFacilityDto>> | ||
public class GetBookedRecordsOfFacilityQuery : IQuery<QueryCollectionResult<BookedRecordOfFacilityDto>> | ||
{ | ||
public GetBookedRecordsOfFacilityQuery(Guid facilityId, DateTime dateFrom, DateTime dateTo) | ||
public GetBookedRecordsOfFacilityQuery(Guid facilityId, GetBookedRecordsOfFacilityQueryParams @params) | ||
{ | ||
FacilityId = facilityId; | ||
DateFrom = dateFrom; | ||
DateTo = dateTo; | ||
Params = @params; | ||
} | ||
|
||
public Guid FacilityId { get; set; } | ||
public DateTime DateFrom { get; set; } | ||
public DateTime DateTo { get; set; } | ||
public Guid FacilityId { get; } | ||
public GetBookedRecordsOfFacilityQueryParams Params { get; } | ||
} | ||
} |
50 changes: 9 additions & 41 deletions
50
...ion/Bookings/Queries/GetBookedRecordsOfFacility/GetBookedRecordsOfFacilityQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,24 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Dapper; | ||
using System.Collections.Generic; | ||
using Core.Database; | ||
using Core.Queries; | ||
|
||
namespace Accessibility.Application.Bookings.Queries.GetBookedRecordsOfFacility | ||
{ | ||
public class GetBookedRecordsOfFacilityQueryHandler : IQueryHandler<GetBookedRecordsOfFacilityQuery, List<BookedRecordOfFacilityDto>> | ||
public class GetBookedRecordsOfFacilityQueryHandler : IQueryHandler<GetBookedRecordsOfFacilityQuery, QueryCollectionResult<BookedRecordOfFacilityDto>> | ||
{ | ||
private readonly ISqlConnectionFactory sqlConnectionFactory; | ||
private readonly IBookingQueryRepository repository; | ||
|
||
public GetBookedRecordsOfFacilityQueryHandler(ISqlConnectionFactory sqlConnectionFactory) | ||
public GetBookedRecordsOfFacilityQueryHandler(IBookingQueryRepository repository) | ||
{ | ||
this.sqlConnectionFactory = sqlConnectionFactory; | ||
this.repository = repository; | ||
} | ||
|
||
public async Task<List<BookedRecordOfFacilityDto>> Handle(GetBookedRecordsOfFacilityQuery request, CancellationToken cancellationToken) | ||
public Task<QueryCollectionResult<BookedRecordOfFacilityDto>> Handle(GetBookedRecordsOfFacilityQuery request, CancellationToken cancellationToken) | ||
{ | ||
var connection = sqlConnectionFactory.GetConnection(); | ||
|
||
return (await connection.QueryAsync<BookedRecordOfFacilityDto>( | ||
@"SELECT | ||
b.booking_id as BookingId, | ||
r.booked_record_id as BookedRecordId, | ||
r.offer_id as OfferId, | ||
o.name as OfferName, | ||
r.employee_id as EmployeeId, | ||
null as EmployeeName, | ||
b.customer_id as CustomerId, | ||
r.date as DateFrom, | ||
r.date + r.duration * INTERVAL '1 minute' as DateTo, | ||
r.duration as Duration, | ||
r.status as Status, | ||
r.price as Price, | ||
r.currency as Currency | ||
FROM | ||
booking.bookings b | ||
INNER JOIN | ||
booking.booked_records r ON b.booking_id = r.booking_id | ||
INNER JOIN | ||
facility.offers o ON r.offer_id = o.offer_id | ||
WHERE | ||
b.facility_id = @FacilityId AND | ||
r.date BETWEEN @DateFrom::timestamp AND @DateTo::timestamp", | ||
new | ||
{ | ||
request.FacilityId, | ||
request.DateFrom, | ||
request.DateTo | ||
})) | ||
.AsList(); | ||
return repository.GetBookedRecords( | ||
request.FacilityId, | ||
request.Params | ||
); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...tion/Bookings/Queries/GetBookedRecordsOfFacility/GetBookedRecordsOfFacilityQueryParams.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using Core.Queries; | ||
|
||
namespace Accessibility.Application.Bookings.Queries.GetBookedRecordsOfFacility | ||
{ | ||
public class GetBookedRecordsOfFacilityQueryParams : QueryParams | ||
{ | ||
public DateTime DateFrom { get; set; } | ||
public DateTime DateTo { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters