From 55bef31a2ecf7f7897d8335709a903b4f24ee26b Mon Sep 17 00:00:00 2001 From: cuqmbr Date: Tue, 23 May 2023 16:08:35 +0300 Subject: [PATCH] feat: add city search autocompletion and suggestion --- Server/Configurations/MapperInitializer.cs | 2 +- Server/Controllers/AddressController.cs | 2 +- Server/Controllers/CityController.cs | 2 +- Server/Controllers/CompanyController.cs | 2 +- Server/Controllers/CountryController.cs | 2 +- Server/Controllers/DriverController.cs | 2 +- Server/Controllers/ReviewController.cs | 2 +- Server/Controllers/RouteAddressController.cs | 2 +- Server/Controllers/RouteController.cs | 2 +- Server/Controllers/StateController.cs | 2 +- Server/Controllers/TicketController.cs | 2 +- Server/Controllers/TicketGroupController.cs | 2 +- Server/Controllers/UserController.cs | 2 +- Server/Controllers/VehicleController.cs | 2 +- .../VehicleEnrollmentController.cs | 2 +- .../VehicleEnrollmentSearchController.cs | 35 +++++++-- Server/Program.cs | 2 +- Server/Services/AddressManagementService.cs | 2 +- Server/Services/CityManagementService.cs | 2 +- Server/Services/CompanyManagementService.cs | 2 +- Server/Services/CountryManagementService.cs | 2 +- Server/Services/DriverManagementService.cs | 2 +- Server/Services/IAddressManagementService.cs | 2 +- Server/Services/ICityManagementService.cs | 2 +- Server/Services/ICompanyManagementService.cs | 2 +- Server/Services/ICountryManagementService.cs | 2 +- Server/Services/IDriverManagementService.cs | 2 +- Server/Services/IReviewManagementService.cs | 2 +- .../IRouteAddressManagementService.cs | 2 +- Server/Services/IRouteManagementService.cs | 2 +- Server/Services/IStateManagementService.cs | 2 +- .../Services/ITicketGroupManagementService.cs | 2 +- Server/Services/ITicketManagementService.cs | 2 +- Server/Services/IUserManagementService.cs | 2 +- .../IVehicleEnrollmentManagementService.cs | 2 +- Server/Services/IVehicleManagementService.cs | 2 +- Server/Services/ReviewManagementService.cs | 2 +- .../Services/RouteAddressManagementService.cs | 2 +- Server/Services/RouteManagementService.cs | 2 +- Server/Services/StateManagementService.cs | 2 +- Server/Services/StatisticsService.cs | 2 +- .../Services/TicketGroupManagementService.cs | 2 +- Server/Services/TicketManagementService.cs | 2 +- Server/Services/UserManagementService.cs | 2 +- .../VehicleEnrollmentManagementService.cs | 2 +- .../VehicleEnrollmentSearchService.cs | 73 +++++++++++++++++-- Server/Services/VehicleManagementService.cs | 2 +- .../{ => DatabaseModels}/AddressDto.cs | 2 +- .../{ => DatabaseModels}/CityDto.cs | 2 +- .../{ => DatabaseModels}/CompanyDto.cs | 2 +- .../{ => DatabaseModels}/CountryDto.cs | 2 +- .../{ => DatabaseModels}/DriverDto.cs | 2 +- .../{ => DatabaseModels}/PaymentDto.cs | 2 +- .../{ => DatabaseModels}/ReviewDto.cs | 2 +- .../RouteAddressDetailsDto.cs | 2 +- .../{ => DatabaseModels}/RouteAddressDto.cs | 2 +- .../{ => DatabaseModels}/RouteDto.cs | 2 +- .../{ => DatabaseModels}/StateDto.cs | 2 +- .../{ => DatabaseModels}/TicketDto.cs | 2 +- .../{ => DatabaseModels}/TicketGroupDto.cs | 2 +- .../{ => DatabaseModels}/UserDto.cs | 2 +- .../{ => DatabaseModels}/VehicleDto.cs | 2 +- .../VehicleEnrollmentDto.cs | 2 +- .../Services/AutocompleteCityDto.cs | 11 +++ 64 files changed, 170 insertions(+), 71 deletions(-) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/AddressDto.cs (96%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/CityDto.cs (93%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/CompanyDto.cs (92%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/CountryDto.cs (94%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/DriverDto.cs (86%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/PaymentDto.cs (86%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/ReviewDto.cs (95%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/RouteAddressDetailsDto.cs (95%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/RouteAddressDto.cs (95%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/RouteDto.cs (92%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/StateDto.cs (94%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/TicketDto.cs (96%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/TicketGroupDto.cs (95%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/UserDto.cs (98%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/VehicleDto.cs (97%) rename SharedModels/DataTransferObjects/{ => DatabaseModels}/VehicleEnrollmentDto.cs (97%) create mode 100644 SharedModels/DataTransferObjects/Services/AutocompleteCityDto.cs diff --git a/Server/Configurations/MapperInitializer.cs b/Server/Configurations/MapperInitializer.cs index d542581..531de56 100644 --- a/Server/Configurations/MapperInitializer.cs +++ b/Server/Configurations/MapperInitializer.cs @@ -1,6 +1,6 @@ using AutoMapper; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using Route = Server.Models.Route; namespace Server.Configurations; diff --git a/Server/Controllers/AddressController.cs b/Server/Controllers/AddressController.cs index fc92b14..92e8436 100644 --- a/Server/Controllers/AddressController.cs +++ b/Server/Controllers/AddressController.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/CityController.cs b/Server/Controllers/CityController.cs index e49f975..f2044d2 100644 --- a/Server/Controllers/CityController.cs +++ b/Server/Controllers/CityController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/CompanyController.cs b/Server/Controllers/CompanyController.cs index 4120705..ec6bc3e 100644 --- a/Server/Controllers/CompanyController.cs +++ b/Server/Controllers/CompanyController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/CountryController.cs b/Server/Controllers/CountryController.cs index 1e977f4..08ca674 100644 --- a/Server/Controllers/CountryController.cs +++ b/Server/Controllers/CountryController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/DriverController.cs b/Server/Controllers/DriverController.cs index 90cd044..c115cd3 100644 --- a/Server/Controllers/DriverController.cs +++ b/Server/Controllers/DriverController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/ReviewController.cs b/Server/Controllers/ReviewController.cs index bec5681..4084a48 100644 --- a/Server/Controllers/ReviewController.cs +++ b/Server/Controllers/ReviewController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/RouteAddressController.cs b/Server/Controllers/RouteAddressController.cs index f4cac3e..0172fdb 100644 --- a/Server/Controllers/RouteAddressController.cs +++ b/Server/Controllers/RouteAddressController.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/RouteController.cs b/Server/Controllers/RouteController.cs index 58ac123..4644141 100644 --- a/Server/Controllers/RouteController.cs +++ b/Server/Controllers/RouteController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/StateController.cs b/Server/Controllers/StateController.cs index 7d63b47..988dd4f 100644 --- a/Server/Controllers/StateController.cs +++ b/Server/Controllers/StateController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/TicketController.cs b/Server/Controllers/TicketController.cs index b6a3822..7b10866 100644 --- a/Server/Controllers/TicketController.cs +++ b/Server/Controllers/TicketController.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/TicketGroupController.cs b/Server/Controllers/TicketGroupController.cs index 60ac118..f4a3292 100644 --- a/Server/Controllers/TicketGroupController.cs +++ b/Server/Controllers/TicketGroupController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/UserController.cs b/Server/Controllers/UserController.cs index 0e96512..8376671 100644 --- a/Server/Controllers/UserController.cs +++ b/Server/Controllers/UserController.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/VehicleController.cs b/Server/Controllers/VehicleController.cs index 59a5f9e..537af3a 100644 --- a/Server/Controllers/VehicleController.cs +++ b/Server/Controllers/VehicleController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/VehicleEnrollmentController.cs b/Server/Controllers/VehicleEnrollmentController.cs index b3da24d..3ae094b 100644 --- a/Server/Controllers/VehicleEnrollmentController.cs +++ b/Server/Controllers/VehicleEnrollmentController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters.Objects; namespace Server.Controllers; diff --git a/Server/Controllers/VehicleEnrollmentSearchController.cs b/Server/Controllers/VehicleEnrollmentSearchController.cs index 84a8837..1ed3acf 100644 --- a/Server/Controllers/VehicleEnrollmentSearchController.cs +++ b/Server/Controllers/VehicleEnrollmentSearchController.cs @@ -3,7 +3,7 @@ using Server.Services; namespace Server.Controllers; -[Route("api/search")] +[Route("api/")] [ApiController] public class VehicleEnrollmentSearchController : ControllerBase { @@ -14,10 +14,10 @@ public class VehicleEnrollmentSearchController : ControllerBase _vehicleEnrollmentSearchService = vehicleEnrollmentSearchService; } - [HttpGet] - public async Task GetRoute(int from, int to, DateTime date) + [HttpGet("search")] + public async Task GetEnrollments(int fromCityId, int toCityId, DateTime date) { - var result = await _vehicleEnrollmentSearchService.GetRoute(from, to, date); + var result = await _vehicleEnrollmentSearchService.GetEnrollments(fromCityId, toCityId, date); if (!result.isSucceed) { @@ -26,5 +26,30 @@ public class VehicleEnrollmentSearchController : ControllerBase return Ok(result.result); } -} + [HttpGet("autocomplete")] + public async Task AutocompleteCityName([FromQuery] string type, [FromQuery] string query, [FromQuery] int limit) + { + var result = await _vehicleEnrollmentSearchService.GetPopularCityNames(type, query, limit); + + if (!result.isSucceed) + { + return result.actionResult; + } + + return new OkObjectResult(result.cities); + } + + [HttpGet("popular")] + public async Task GetPopularCityNames([FromQuery] string type, [FromQuery] int limit) + { + var result = await _vehicleEnrollmentSearchService.GetPopularCityNames(type, limit); + + if (!result.isSucceed) + { + return result.actionResult; + } + + return new OkObjectResult(result.cities); + } +} \ No newline at end of file diff --git a/Server/Program.cs b/Server/Program.cs index cc3e3d8..6f277de 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -12,7 +12,7 @@ using Server.Data; using Server.Helpers; using Server.Models; using Server.Services; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using Utils; var builder = WebApplication.CreateBuilder(args); diff --git a/Server/Services/AddressManagementService.cs b/Server/Services/AddressManagementService.cs index 6260d00..cfcadd4 100644 --- a/Server/Services/AddressManagementService.cs +++ b/Server/Services/AddressManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/CityManagementService.cs b/Server/Services/CityManagementService.cs index 66196c0..6c6c94b 100644 --- a/Server/Services/CityManagementService.cs +++ b/Server/Services/CityManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/CompanyManagementService.cs b/Server/Services/CompanyManagementService.cs index b426c9c..cf207cd 100644 --- a/Server/Services/CompanyManagementService.cs +++ b/Server/Services/CompanyManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/CountryManagementService.cs b/Server/Services/CountryManagementService.cs index 4d7f5ba..1721ae4 100644 --- a/Server/Services/CountryManagementService.cs +++ b/Server/Services/CountryManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/DriverManagementService.cs b/Server/Services/DriverManagementService.cs index 466f662..a5f8ac9 100644 --- a/Server/Services/DriverManagementService.cs +++ b/Server/Services/DriverManagementService.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; using Utils; diff --git a/Server/Services/IAddressManagementService.cs b/Server/Services/IAddressManagementService.cs index eef33d2..9ae19e2 100644 --- a/Server/Services/IAddressManagementService.cs +++ b/Server/Services/IAddressManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/ICityManagementService.cs b/Server/Services/ICityManagementService.cs index ff20640..f8818f8 100644 --- a/Server/Services/ICityManagementService.cs +++ b/Server/Services/ICityManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/ICompanyManagementService.cs b/Server/Services/ICompanyManagementService.cs index 191bab7..e25d179 100644 --- a/Server/Services/ICompanyManagementService.cs +++ b/Server/Services/ICompanyManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/ICountryManagementService.cs b/Server/Services/ICountryManagementService.cs index ae27114..20bf0ee 100644 --- a/Server/Services/ICountryManagementService.cs +++ b/Server/Services/ICountryManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/IDriverManagementService.cs b/Server/Services/IDriverManagementService.cs index f6cdf5e..8603c8b 100644 --- a/Server/Services/IDriverManagementService.cs +++ b/Server/Services/IDriverManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/IReviewManagementService.cs b/Server/Services/IReviewManagementService.cs index 8a67969..521e1df 100644 --- a/Server/Services/IReviewManagementService.cs +++ b/Server/Services/IReviewManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/IRouteAddressManagementService.cs b/Server/Services/IRouteAddressManagementService.cs index 04170b6..d1b7b79 100644 --- a/Server/Services/IRouteAddressManagementService.cs +++ b/Server/Services/IRouteAddressManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/IRouteManagementService.cs b/Server/Services/IRouteManagementService.cs index dd4ddf2..4a8e952 100644 --- a/Server/Services/IRouteManagementService.cs +++ b/Server/Services/IRouteManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/IStateManagementService.cs b/Server/Services/IStateManagementService.cs index b1cacff..e90f1bb 100644 --- a/Server/Services/IStateManagementService.cs +++ b/Server/Services/IStateManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/ITicketGroupManagementService.cs b/Server/Services/ITicketGroupManagementService.cs index e495a4b..c3226ae 100644 --- a/Server/Services/ITicketGroupManagementService.cs +++ b/Server/Services/ITicketGroupManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/ITicketManagementService.cs b/Server/Services/ITicketManagementService.cs index 991bcdc..9648c30 100644 --- a/Server/Services/ITicketManagementService.cs +++ b/Server/Services/ITicketManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/IUserManagementService.cs b/Server/Services/IUserManagementService.cs index de77bb1..e3877b6 100644 --- a/Server/Services/IUserManagementService.cs +++ b/Server/Services/IUserManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/IVehicleEnrollmentManagementService.cs b/Server/Services/IVehicleEnrollmentManagementService.cs index cac6588..5b99f3d 100644 --- a/Server/Services/IVehicleEnrollmentManagementService.cs +++ b/Server/Services/IVehicleEnrollmentManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/IVehicleManagementService.cs b/Server/Services/IVehicleManagementService.cs index 88da190..4466d8d 100644 --- a/Server/Services/IVehicleManagementService.cs +++ b/Server/Services/IVehicleManagementService.cs @@ -1,6 +1,6 @@ using System.Dynamic; using Microsoft.AspNetCore.Mvc; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/ReviewManagementService.cs b/Server/Services/ReviewManagementService.cs index faba1c2..ecf47d8 100644 --- a/Server/Services/ReviewManagementService.cs +++ b/Server/Services/ReviewManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; using Utils; diff --git a/Server/Services/RouteAddressManagementService.cs b/Server/Services/RouteAddressManagementService.cs index 8d493e8..7be22b9 100644 --- a/Server/Services/RouteAddressManagementService.cs +++ b/Server/Services/RouteAddressManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/RouteManagementService.cs b/Server/Services/RouteManagementService.cs index b1d0796..b90c193 100644 --- a/Server/Services/RouteManagementService.cs +++ b/Server/Services/RouteManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; using Route = Server.Models.Route; diff --git a/Server/Services/StateManagementService.cs b/Server/Services/StateManagementService.cs index 9aaa334..151a4c3 100644 --- a/Server/Services/StateManagementService.cs +++ b/Server/Services/StateManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/StatisticsService.cs b/Server/Services/StatisticsService.cs index 87eb47e..29f0092 100644 --- a/Server/Services/StatisticsService.cs +++ b/Server/Services/StatisticsService.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Statistics; diff --git a/Server/Services/TicketGroupManagementService.cs b/Server/Services/TicketGroupManagementService.cs index 7b75b13..6b23cd1 100644 --- a/Server/Services/TicketGroupManagementService.cs +++ b/Server/Services/TicketGroupManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; using Utils; diff --git a/Server/Services/TicketManagementService.cs b/Server/Services/TicketManagementService.cs index 83da07b..728a18c 100644 --- a/Server/Services/TicketManagementService.cs +++ b/Server/Services/TicketManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/UserManagementService.cs b/Server/Services/UserManagementService.cs index 894933f..bb1123a 100644 --- a/Server/Services/UserManagementService.cs +++ b/Server/Services/UserManagementService.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; diff --git a/Server/Services/VehicleEnrollmentManagementService.cs b/Server/Services/VehicleEnrollmentManagementService.cs index cd4b24d..75e1e11 100644 --- a/Server/Services/VehicleEnrollmentManagementService.cs +++ b/Server/Services/VehicleEnrollmentManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; using Utils; diff --git a/Server/Services/VehicleEnrollmentSearchService.cs b/Server/Services/VehicleEnrollmentSearchService.cs index 772bc3b..4f823a5 100644 --- a/Server/Services/VehicleEnrollmentSearchService.cs +++ b/Server/Services/VehicleEnrollmentSearchService.cs @@ -1,9 +1,9 @@ -using System.Dynamic; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; -using Server.Helpers; using Server.Models; +using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Services; using SharedModels.Responses; namespace Server.Services; @@ -17,8 +17,8 @@ public class VehicleEnrollmentSearchService _dbContext = dbContext; } - public async Task<(bool isSucceed, IActionResult? actionResult, IList result)> - GetRoute(int fromCityId, int toCityId, DateTime date) + public async Task<(bool isSucceed, IActionResult actionResult, IList result)> + GetEnrollments(int fromCityId, int toCityId, DateTime date) { var dbEnrollments = await _dbContext.VehicleEnrollments .Include(ve => ve.Tickets) @@ -247,7 +247,7 @@ public class VehicleEnrollmentSearchService return (false, new NotFoundResult(), null!); } - return (true, null, result.EnrollmentGroups); + return (true, null!, result.EnrollmentGroups); DateTime GetDepartureTime(VehicleEnrollment enrollment) { @@ -315,4 +315,67 @@ public class VehicleEnrollmentSearchService return result; } } + + public async Task<(bool isSucceed, IActionResult actionResult, IList cities)> + GetPopularCityNames(string type, string name, int limit) + { + var dbCities = await _dbContext.Cities.Include(c => c.State).ThenInclude(s => s.Country) + .Where(c => EF.Functions.ILike(c.Name, $"%{name}%")).ToArrayAsync(); + var dbTicketGroups = await _dbContext.TicketGroups.Include(tg => tg.Tickets) + .ThenInclude(t => t.VehicleEnrollment).ThenInclude(ve => ve.Route).ThenInclude(r => r.RouteAddresses) + .ThenInclude(ra => ra.Address).ThenInclude(a => a.City) + .Where(tg => tg.PurchaseDateTimeUtc >= DateTime.UtcNow.AddDays(-60)) + .ToArrayAsync(); + + var cityFrequency = dbCities.ToDictionary(key => key, value => 0); + + foreach (var tg in dbTicketGroups) + { + var departureCity = tg.GetDepartureAddress().City; + var arrivalCity = tg.GetArrivalAddress().City; + + if ((type == "from" || type == "any") && cityFrequency.ContainsKey(departureCity)) + { + cityFrequency[departureCity]++; + } + + if ((type == "to" || type == "any") && cityFrequency.ContainsKey(arrivalCity)) + { + cityFrequency[arrivalCity]++; + } + } + + var orderedCityFrequency = cityFrequency.OrderByDescending(kvp => kvp.Value); + + int order = 1; + var popularCitiesDto = new List(); + foreach (var city in orderedCityFrequency.Take(limit).Select(kvp => kvp.Key)) + { + popularCitiesDto.Add(new AutocompleteCityDto + { + Id = city.Id, + Name = city.Name, + StateName = city.State.Name, + CountryName = city.State.Country.Name, + FullName = city.GetFullName(), + Order = order + }); + + order++; + } + + return (true, null!, popularCitiesDto); + } + + public async Task<(bool isSucceed, IActionResult actionResult, IList cities)> + GetPopularCityNames(string type, int limit) + { + return await GetPopularCityNames(type, "", limit); + } + + public async Task<(bool isSucceed, IActionResult actionResult, IList cities)> + GetPopularCityNames(int limit) + { + return await GetPopularCityNames("any", "", limit); + } } \ No newline at end of file diff --git a/Server/Services/VehicleManagementService.cs b/Server/Services/VehicleManagementService.cs index cfabe9f..593ffc5 100644 --- a/Server/Services/VehicleManagementService.cs +++ b/Server/Services/VehicleManagementService.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; using Server.Models; -using SharedModels.DataTransferObjects; +using SharedModels.DataTransferObjects.Model; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; using Utils; diff --git a/SharedModels/DataTransferObjects/AddressDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/AddressDto.cs similarity index 96% rename from SharedModels/DataTransferObjects/AddressDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/AddressDto.cs index 14203e8..4047c8c 100644 --- a/SharedModels/DataTransferObjects/AddressDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/AddressDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class AddressDto : CreateAddressDto { diff --git a/SharedModels/DataTransferObjects/CityDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/CityDto.cs similarity index 93% rename from SharedModels/DataTransferObjects/CityDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/CityDto.cs index 8a23a49..46d6161 100644 --- a/SharedModels/DataTransferObjects/CityDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/CityDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class CityDto : CreateCityDto { diff --git a/SharedModels/DataTransferObjects/CompanyDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/CompanyDto.cs similarity index 92% rename from SharedModels/DataTransferObjects/CompanyDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/CompanyDto.cs index 700c9f6..b098322 100644 --- a/SharedModels/DataTransferObjects/CompanyDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/CompanyDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class CompanyDto : CreateCompanyDto { diff --git a/SharedModels/DataTransferObjects/CountryDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/CountryDto.cs similarity index 94% rename from SharedModels/DataTransferObjects/CountryDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/CountryDto.cs index 7fc36dc..ee76102 100644 --- a/SharedModels/DataTransferObjects/CountryDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/CountryDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class CountryDto : CreateCountryDto { diff --git a/SharedModels/DataTransferObjects/DriverDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/DriverDto.cs similarity index 86% rename from SharedModels/DataTransferObjects/DriverDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/DriverDto.cs index 98d45db..42b3345 100644 --- a/SharedModels/DataTransferObjects/DriverDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/DriverDto.cs @@ -1,4 +1,4 @@ -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class DriverDto : UserDto { diff --git a/SharedModels/DataTransferObjects/PaymentDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/PaymentDto.cs similarity index 86% rename from SharedModels/DataTransferObjects/PaymentDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/PaymentDto.cs index c28437f..7eefc71 100644 --- a/SharedModels/DataTransferObjects/PaymentDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/PaymentDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class PaymentDto { diff --git a/SharedModels/DataTransferObjects/ReviewDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/ReviewDto.cs similarity index 95% rename from SharedModels/DataTransferObjects/ReviewDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/ReviewDto.cs index ae3277a..3d3f6d6 100644 --- a/SharedModels/DataTransferObjects/ReviewDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/ReviewDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class ReviewDto : CreateReviewDto { diff --git a/SharedModels/DataTransferObjects/RouteAddressDetailsDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/RouteAddressDetailsDto.cs similarity index 95% rename from SharedModels/DataTransferObjects/RouteAddressDetailsDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/RouteAddressDetailsDto.cs index 54eb5e5..88f0723 100644 --- a/SharedModels/DataTransferObjects/RouteAddressDetailsDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/RouteAddressDetailsDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class RouteAddressDetailsDto : CreateRouteAddressDetailsDto { diff --git a/SharedModels/DataTransferObjects/RouteAddressDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/RouteAddressDto.cs similarity index 95% rename from SharedModels/DataTransferObjects/RouteAddressDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/RouteAddressDto.cs index 57e411e..464e43b 100644 --- a/SharedModels/DataTransferObjects/RouteAddressDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/RouteAddressDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class RouteAddressDto : CreateRouteAddressDto { diff --git a/SharedModels/DataTransferObjects/RouteDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/RouteDto.cs similarity index 92% rename from SharedModels/DataTransferObjects/RouteDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/RouteDto.cs index 5784aff..00d5d25 100644 --- a/SharedModels/DataTransferObjects/RouteDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/RouteDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class RouteDto : CreateRouteDto { diff --git a/SharedModels/DataTransferObjects/StateDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/StateDto.cs similarity index 94% rename from SharedModels/DataTransferObjects/StateDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/StateDto.cs index 9d9f4e6..7680718 100644 --- a/SharedModels/DataTransferObjects/StateDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/StateDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class StateDto : CreateStateDto { diff --git a/SharedModels/DataTransferObjects/TicketDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/TicketDto.cs similarity index 96% rename from SharedModels/DataTransferObjects/TicketDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/TicketDto.cs index 8af8fcd..8a441c7 100644 --- a/SharedModels/DataTransferObjects/TicketDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/TicketDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class TicketDto : CreateTicketDto { diff --git a/SharedModels/DataTransferObjects/TicketGroupDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/TicketGroupDto.cs similarity index 95% rename from SharedModels/DataTransferObjects/TicketGroupDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/TicketGroupDto.cs index eb21cff..f5e92f5 100644 --- a/SharedModels/DataTransferObjects/TicketGroupDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/TicketGroupDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class TicketGroupDto : CreateTicketGroupDto { diff --git a/SharedModels/DataTransferObjects/UserDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/UserDto.cs similarity index 98% rename from SharedModels/DataTransferObjects/UserDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/UserDto.cs index 111418a..739025a 100644 --- a/SharedModels/DataTransferObjects/UserDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/UserDto.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations; using Utils; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class UserDto { diff --git a/SharedModels/DataTransferObjects/VehicleDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/VehicleDto.cs similarity index 97% rename from SharedModels/DataTransferObjects/VehicleDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/VehicleDto.cs index a7a901c..8b718b3 100644 --- a/SharedModels/DataTransferObjects/VehicleDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/VehicleDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class VehicleDto : CreateVehicleDto { diff --git a/SharedModels/DataTransferObjects/VehicleEnrollmentDto.cs b/SharedModels/DataTransferObjects/DatabaseModels/VehicleEnrollmentDto.cs similarity index 97% rename from SharedModels/DataTransferObjects/VehicleEnrollmentDto.cs rename to SharedModels/DataTransferObjects/DatabaseModels/VehicleEnrollmentDto.cs index 347fa4b..19e3ec2 100644 --- a/SharedModels/DataTransferObjects/VehicleEnrollmentDto.cs +++ b/SharedModels/DataTransferObjects/DatabaseModels/VehicleEnrollmentDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace SharedModels.DataTransferObjects; +namespace SharedModels.DataTransferObjects.Model; public class VehicleEnrollmentDto : CreateVehicleEnrollmentDto { diff --git a/SharedModels/DataTransferObjects/Services/AutocompleteCityDto.cs b/SharedModels/DataTransferObjects/Services/AutocompleteCityDto.cs new file mode 100644 index 0000000..47db73e --- /dev/null +++ b/SharedModels/DataTransferObjects/Services/AutocompleteCityDto.cs @@ -0,0 +1,11 @@ +namespace SharedModels.DataTransferObjects.Services; + +public class AutocompleteCityDto +{ + public int Id { get; set; } + public string Name { get; set; } = null!; + public string StateName { get; set; } = null!; + public string CountryName { get; set; } = null!; + public string FullName { get; set; } = null!; + public int Order { get; set; } +} \ No newline at end of file