Skip to content

Commit

Permalink
#13 added basic support qr codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssipakov authored and ssipakov committed Apr 3, 2023
1 parent 3313b6b commit ac7211c
Show file tree
Hide file tree
Showing 86 changed files with 74,533 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface IReservationRepository : IGenericRepository<Reservation>
Task<Reservation?> CheckReservation(long spaceId, string subSpaceId, DateTime reservationFrom, DateTime reservationTo);

Task<IEnumerable<Reservation>> GetReservationsByUserId(long userId);

Task<IEnumerable<Reservation>> GetReservationsBySpaceId(long spaceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public async Task<IEnumerable<Reservation>> GetReservationsByUserId(long userId)
{
return await dbSet.Include(x=>x.PriceSpecification).Where(x => x.TenantUserId == userId).ToListAsync();
}

public async Task<IEnumerable<Reservation>> GetReservationsBySpaceId(long spaceId)
{
return await dbSet.Include(x => x.PriceSpecification).Include(x => x.Space)
.Where(x => x.SpaceId == spaceId).ToListAsync();
}

public override async Task<IEnumerable<Reservation>> All()
{
Expand Down
20 changes: 20 additions & 0 deletions AlgoTecture.Domain/Models/Dto/SpaceWithProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using AlgoTecture.Domain.Models.RepositoryModels;

namespace AlgoTecture.Domain.Models.Dto;

public class SpaceWithProperty
{
public long Id { get; set; }

public int UtilizationTypeId { get; set; }

public UtilizationType UtilizationType { get; set; }

public string SpaceAddress { get; set; }

public double Latitude { get; set; }

public double Longitude { get; set; }

public SpaceProperty SpaceProperty { get; set; }
}
1 change: 1 addition & 0 deletions AlgoTecture.Domain/Models/RepositoryModels/Space.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Space
public double Latitude { get; set; }

public double Longitude { get; set; }

public string SpaceProperty { get; set; }
}
}
2 changes: 2 additions & 0 deletions AlgoTecture.Libraries.Reservations/IReservationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface IReservationService
Task<Reservation?> AddReservation(AddOrUpdateReservationModel addOrUpdateReservationModel);

Task<Reservation?> UpdateReservation(AddOrUpdateReservationModel addOrUpdateReservationModel);

Task<IEnumerable<Reservation>> GetReservationsBySpaceId(long spaceId);
}
5 changes: 5 additions & 0 deletions AlgoTecture.Libraries.Reservations/ReservationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public ReservationService(IUnitOfWork unitOfWork)
resultReservation = await _unitOfWork.Reservations.Upsert(entity);
return resultReservation;
}

public async Task<IEnumerable<Reservation>> GetReservationsBySpaceId(long spaceId)
{
return await _unitOfWork.Reservations.GetReservationsBySpaceId(spaceId);
}
}
27 changes: 25 additions & 2 deletions AlgoTecture.Libraries.Spaces/Implementations/SpaceGetter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using AlgoTecture.Data.Persistence.Core.Interfaces;
using AlgoTecture.Domain.Models;
using AlgoTecture.Domain.Models.Dto;
using AlgoTecture.Domain.Models.RepositoryModels;
using AlgoTecture.Libraries.Spaces.Interfaces;
using Newtonsoft.Json;

namespace AlgoTecture.Libraries.Spaces.Implementations
{
Expand All @@ -19,17 +22,37 @@ public async Task<Space> GetByCoordinates(double latitude, double longitude)

return targetSpace;
}

public async Task<List<Space>> GetByType(int utilizationTypeId)
{
var targetSpaces = await _unitOfWork.Spaces.GetByType(utilizationTypeId);

return targetSpaces;
}

public async Task<Space> GetById(long spaceId)
{
return await _unitOfWork.Spaces.GetById(spaceId);
}

public async Task<SpaceWithProperty?> GetByIdWithProperty(long spaceId)
{
var targetSpaceWithProperty = new SpaceWithProperty();

var space = await _unitOfWork.Spaces.GetById(spaceId);
if (space == null) return null;

var spaceProperty = JsonConvert.DeserializeObject<SpaceProperty>(space.SpaceProperty);

targetSpaceWithProperty.Id = space.Id;
targetSpaceWithProperty.Latitude = space.Latitude;
targetSpaceWithProperty.Longitude = space.Longitude;
targetSpaceWithProperty.SpaceAddress = space.SpaceAddress;
targetSpaceWithProperty.SpaceProperty = spaceProperty;
targetSpaceWithProperty.UtilizationType = space.UtilizationType;
targetSpaceWithProperty.UtilizationTypeId = space.UtilizationTypeId;

return targetSpaceWithProperty;
}
}
}
5 changes: 4 additions & 1 deletion AlgoTecture.Libraries.Spaces/Interfaces/ISpaceGetter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AlgoTecture.Domain.Models.RepositoryModels;
using AlgoTecture.Domain.Models.Dto;
using AlgoTecture.Domain.Models.RepositoryModels;

namespace AlgoTecture.Libraries.Spaces.Interfaces
{
Expand All @@ -9,5 +10,7 @@ public interface ISpaceGetter
Task<List<Space>> GetByType(int utilizationTypeId);

Task<Space> GetById(long spaceId);

Task<SpaceWithProperty?> GetByIdWithProperty(long spaceId);
}
}
3 changes: 1 addition & 2 deletions AlgoTecture.TelegramBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ public static async Task Main(string[] args)

try
{
var pathToLog = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "algotecture", "log", "serilog-log-.json");
var pathToLog = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "algotecture", "log", "telegram-bot", "serilog-log-.json");

webAppBuilder.Host.UseSerilog((context, services, configuration) =>
{
var env = context.HostingEnvironment;

configuration
//.ReadFrom.Configuration(services)
.Enrich.FromLogContext()
.Enrich.WithProperty("App", env.ApplicationName)
.Enrich.WithProperty("EnvironmentName", env.EnvironmentName)
Expand Down
19 changes: 19 additions & 0 deletions AlgoTecture.WebApi.QrCode/AlgoTecture.WebApi.QrCode.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AlgoTecture.Common\AlgoTecture.Common.csproj" />
<ProjectReference Include="..\AlgoTecture.Libraries.Reservations\AlgoTecture.Libraries.Reservations.csproj" />
<ProjectReference Include="..\AlgoTecture.Libraries.Spaces\AlgoTecture.Libraries.Spaces.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Services" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions AlgoTecture.WebApi.QrCode/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId) {
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
26 changes: 26 additions & 0 deletions AlgoTecture.WebApi.QrCode/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace AlgoTecture.WebApi.QrCode.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
8 changes: 8 additions & 0 deletions AlgoTecture.WebApi.QrCode/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page
@using System.Globalization
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
</div>
40 changes: 40 additions & 0 deletions AlgoTecture.WebApi.QrCode/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using AlgoTecture.Domain.Models;
using AlgoTecture.Domain.Models.RepositoryModels;
using AlgoTecture.Libraries.Reservations;
using AlgoTecture.Libraries.Spaces.Interfaces;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace AlgoTecture.WebApi.QrCode.Pages;

public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
private readonly IReservationService _reservationService;
private readonly ISpaceGetter _spaceGetter;

public IEnumerable<Reservation> TargetReservations { get; set; }
public Space TargetSpace { get; set; }

public SpaceProperty TargetsSpaceProperty { get; set; }

public IndexModel(ILogger<IndexModel> logger, IReservationService reservationService, ISpaceGetter spaceGetter)
{
_logger = logger;
_reservationService = reservationService;
_spaceGetter = spaceGetter;
}

public async Task OnGet()
{
int spaceId = 1;
var data = Request.Query["spaceId"];
var isValid = int.TryParse(data, out var value);

if (isValid)
{
spaceId = value;
}
TargetSpace = await _spaceGetter.GetById(spaceId);
TargetReservations = await _reservationService.GetReservationsBySpaceId(spaceId);
}
}
8 changes: 8 additions & 0 deletions AlgoTecture.WebApi.QrCode/Pages/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>This page will be completed soon.</p>
18 changes: 18 additions & 0 deletions AlgoTecture.WebApi.QrCode/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace AlgoTecture.WebApi.QrCode.Pages;

public class PrivacyModel : PageModel
{
private readonly ILogger<PrivacyModel> _logger;

public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}

public void OnGet()
{
}
}
51 changes: 51 additions & 0 deletions AlgoTecture.WebApi.QrCode/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>@ViewData["Title"] - AlgoTecture</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css"/>
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/AlgoTecture.WebApi.QrCode.styles.css" asp-append-version="true"/>
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/SpacePage">AlgoTecture</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/SpacePage">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2023 - AlgoTecture - <a asp-area="" asp-page="/Privacy">Privacy</a>
</div>
</footer>

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>

@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
Loading

0 comments on commit ac7211c

Please sign in to comment.