From 1ef6d73a7412f712efda3697c7e1444bfc499cb2 Mon Sep 17 00:00:00 2001 From: zaur Date: Sat, 7 Dec 2019 17:54:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=B0=D0=BF=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=B0=D1=82=20=D0=B1=D1=80=D0=BE=D0=BD=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=BD=D0=B0?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Application/Application.csproj | 4 --- .../{ => Query}/GetAllReservationsQuery.cs | 2 +- .../Query/GetAllReservedDatesQuery.cs | 28 +++++++++++++++++++ .../Reservation/Query/ReservedDateOutput.cs | 17 +++++++++++ src/Application/Http/ProfileController.cs | 1 + src/Application/Http/ReservationController.cs | 7 +++++ 6 files changed, 54 insertions(+), 5 deletions(-) rename src/Application/CQS/Reservation/{ => Query}/GetAllReservationsQuery.cs (94%) create mode 100644 src/Application/CQS/Reservation/Query/GetAllReservedDatesQuery.cs create mode 100644 src/Application/CQS/Reservation/Query/ReservedDateOutput.cs diff --git a/src/Application/Application.csproj b/src/Application/Application.csproj index 019e5cd..c304cf2 100644 --- a/src/Application/Application.csproj +++ b/src/Application/Application.csproj @@ -20,8 +20,4 @@ - - - - diff --git a/src/Application/CQS/Reservation/GetAllReservationsQuery.cs b/src/Application/CQS/Reservation/Query/GetAllReservationsQuery.cs similarity index 94% rename from src/Application/CQS/Reservation/GetAllReservationsQuery.cs rename to src/Application/CQS/Reservation/Query/GetAllReservationsQuery.cs index 19afcbf..4c06422 100644 --- a/src/Application/CQS/Reservation/GetAllReservationsQuery.cs +++ b/src/Application/CQS/Reservation/Query/GetAllReservationsQuery.cs @@ -6,7 +6,7 @@ using Domain.Entities; using NHibernate.Linq; -namespace Application.CQS.Reservation +namespace Application.CQS.Reservation.Query { public class GetAllReservationsQuery { diff --git a/src/Application/CQS/Reservation/Query/GetAllReservedDatesQuery.cs b/src/Application/CQS/Reservation/Query/GetAllReservedDatesQuery.cs new file mode 100644 index 0000000..2e45cfe --- /dev/null +++ b/src/Application/CQS/Reservation/Query/GetAllReservedDatesQuery.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Domain; +using Domain.Entities; +using NHibernate.Linq; + +namespace Application.CQS.Reservation.Query +{ + public class GetAllReservedDatesQuery + { + private IRepository ReservationRepository { get; } + + public GetAllReservedDatesQuery(IRepository reservationRepository) + { + ReservationRepository = reservationRepository; + } + + public async Task> ExecuteAsync() + { + return await ReservationRepository.FindAll() + .Where(r => r.ReservedFrom >= DateTime.Now) + .Select(reservation => new ReservedDateOutput(reservation)) + .ToListAsync(); + } + } +} diff --git a/src/Application/CQS/Reservation/Query/ReservedDateOutput.cs b/src/Application/CQS/Reservation/Query/ReservedDateOutput.cs new file mode 100644 index 0000000..d222e0f --- /dev/null +++ b/src/Application/CQS/Reservation/Query/ReservedDateOutput.cs @@ -0,0 +1,17 @@ +using System; +using Domain.Entities; + +namespace Application.CQS.Reservation.Query +{ + public class ReservedDateOutput + { + public DateTime From { get; } + public DateTime To { get; set; } + + public ReservedDateOutput(ReservationEntity reservation) + { + From = reservation.ReservedFrom; + To = reservation.ReservedTo; + } + } +} diff --git a/src/Application/Http/ProfileController.cs b/src/Application/Http/ProfileController.cs index 281b6be..c8b1fc3 100644 --- a/src/Application/Http/ProfileController.cs +++ b/src/Application/Http/ProfileController.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Application.CQS.Profile; using Application.CQS.Reservation; +using Application.CQS.Reservation.Query; using Application.CQS.User.Command; using Application.CQS.User.Input; using Microsoft.AspNetCore.Mvc; diff --git a/src/Application/Http/ReservationController.cs b/src/Application/Http/ReservationController.cs index b68cfc0..f402468 100644 --- a/src/Application/Http/ReservationController.cs +++ b/src/Application/Http/ReservationController.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Application.CQS.Reservation; using Application.CQS.Reservation.Command; +using Application.CQS.Reservation.Query; using Microsoft.AspNetCore.Mvc; namespace Application.Http @@ -20,6 +21,12 @@ [FromQuery] ReservationsFilter filter return await query.ExecuteAsync(filter); } + [HttpGet("dates")] + public async Task> GetAllReservedDatesAsync([FromServices] GetAllReservedDatesQuery query) + { + return await query.ExecuteAsync(); + } + [HttpPost] public async Task CreateReservation([FromServices] CreateReservationCommand command, [FromBody] ReservationInput input) {