Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Добавил метод апи для запроса дат бронирования комнат
Browse files Browse the repository at this point in the history
  • Loading branch information
nzour committed Dec 7, 2019
1 parent 304105b commit 1ef6d73
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
</ItemGroup>

<ItemGroup>
<Folder Include="CQS\Reservation\Query" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Domain.Entities;
using NHibernate.Linq;

namespace Application.CQS.Reservation
namespace Application.CQS.Reservation.Query
{
public class GetAllReservationsQuery
{
Expand Down
28 changes: 28 additions & 0 deletions src/Application/CQS/Reservation/Query/GetAllReservedDatesQuery.cs
Original file line number Diff line number Diff line change
@@ -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<ReservationEntity> ReservationRepository { get; }

public GetAllReservedDatesQuery(IRepository<ReservationEntity> reservationRepository)
{
ReservationRepository = reservationRepository;
}

public async Task<IEnumerable<ReservedDateOutput>> ExecuteAsync()
{
return await ReservationRepository.FindAll()
.Where(r => r.ReservedFrom >= DateTime.Now)
.Select(reservation => new ReservedDateOutput(reservation))
.ToListAsync();
}
}
}
17 changes: 17 additions & 0 deletions src/Application/CQS/Reservation/Query/ReservedDateOutput.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
1 change: 1 addition & 0 deletions src/Application/Http/ProfileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/Application/Http/ReservationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +21,12 @@ [FromQuery] ReservationsFilter filter
return await query.ExecuteAsync(filter);
}

[HttpGet("dates")]
public async Task<IEnumerable<ReservedDateOutput>> GetAllReservedDatesAsync([FromServices] GetAllReservedDatesQuery query)
{
return await query.ExecuteAsync();
}

[HttpPost]
public async Task CreateReservation([FromServices] CreateReservationCommand command, [FromBody] ReservationInput input)
{
Expand Down

0 comments on commit 1ef6d73

Please sign in to comment.