From fcc2af8e855e7642190c1895f4fdcda4b6aff576 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 2 Jun 2024 10:57:09 +0200 Subject: [PATCH 1/3] Cars and UserProductMapping endpoints and dal (?) --- TIAM.Database/DataLayers/Admins/AdminDal.cs | 4 + TIAM.Services/SignalRTags.cs | 14 +- TIAMSharedUI/Todo.txt | 1 + .../ServiceProviderAPIController.cs | 121 +++++++++++++++++- TIAMWebApp/Shared/Models/APIUrls.cs | 25 +++- .../Shared/Models/CreateAssignedUserModel.cs | 2 + 6 files changed, 156 insertions(+), 11 deletions(-) create mode 100644 TIAMSharedUI/Todo.txt diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index d669d65b..aaacd18e 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -41,6 +41,10 @@ namespace TIAM.Database.DataLayers.Admins #region Car public Car? GetCarById(Guid carId) => Session(ctx => ctx.Cars.FirstOrDefault(x => x.Id == carId)); public List GetCarByUserProductMappingId(Guid userProductMappingId) => Session(ctx => ctx.Cars.Where(x => x.UserProductMappingId == userProductMappingId).ToList()); + public Task AddCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Add(car).State == EntityState.Added); + public Task UpdateCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Update(car).State == EntityState.Modified); + public Task RemoveCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Remove(car).State == EntityState.Deleted); + #endregion Car #region Transfer diff --git a/TIAM.Services/SignalRTags.cs b/TIAM.Services/SignalRTags.cs index 3b19f2d0..75650c45 100644 --- a/TIAM.Services/SignalRTags.cs +++ b/TIAM.Services/SignalRTags.cs @@ -29,6 +29,16 @@ public class SignalRTags : AcSignalRTags public const int GetProfileById = 22; public const int UpdateProfile = 23; - //public const int AddAddress = 24; - //public const int RemoveAddress = 25; + //public const int AddProfile = 24; + //public const int RemoveProfile = 25; + + public const int GetUserProductMappingsForProduct = 26; + public const int CreateUserProductMapping = 27; + public const int UpdateUserProductMapping = 28; + public const int DeleteUserProductMapping = 29; //set permissions to 0 + + public const int GetCarsForUserProductMapping = 30; + public const int CreateCar = 31; + public const int UpdateCar = 32; + public const int DeleteCar = 33; } \ No newline at end of file diff --git a/TIAMSharedUI/Todo.txt b/TIAMSharedUI/Todo.txt new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/TIAMSharedUI/Todo.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs index 71a998dd..1c6707e6 100644 --- a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs +++ b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs @@ -18,6 +18,8 @@ using AyCode.Utils.Extensions; using TIAM.Services; using TIAMWebApp.Server.Services; using TIAM.Entities.Transfers; +using TIAMWebApp.Shared.Application.Services; +using TIAM.Entities.Drivers; namespace TIAMWebApp.Server.Controllers { @@ -173,17 +175,16 @@ namespace TIAMWebApp.Server.Controllers [Route(APIUrls.CreateUserProductMappingRouteName)] [Tags("Finished", "ServiceProvider")] [EndpointSummary("Create assigned user to product")] - public async Task CreateUserProductMapping(CreateUserProductMappingModel createUserProductMappingModel) + [SignalR(SignalRTags.CreateUserProductMapping)] + public async Task CreateUserProductMapping(UserProductMapping userProductMapping) { - if(createUserProductMappingModel.ContextId == Guid.Empty || createUserProductMappingModel.UserId == Guid.Empty) + if(userProductMapping.ProductId == Guid.Empty || userProductMapping.UserId == Guid.Empty) { return BadRequest("Invalid request"); } else { - _logger.Info($@"CreateUserProductMappings called with ownerId: {createUserProductMappingModel.ContextId}, {createUserProductMappingModel.ContextId}"); - - var userProductMapping = new UserProductMapping(createUserProductMappingModel.ContextId, createUserProductMappingModel.ContextId); + _logger.Info($@"CreateUserProductMappings called with ownerId: {userProductMapping.ProductId}, {userProductMapping.UserId}"); var result = await adminDal.AddUserProductMappingAsync(userProductMapping); @@ -191,6 +192,32 @@ namespace TIAMWebApp.Server.Controllers } } + [AllowAnonymous] + [HttpPost] + [Route(APIUrls.UpdateUserProductMappingRouteName)] + [SignalR(SignalRTags.UpdateUserProductMapping)] + public async Task UpdateUserProductMapping(UserProductMapping userProductMapping) + { + _logger.Info($"UpdateUserProductMapping called! + {userProductMapping.Id}"); + + var result = await adminDal.UpdateUserProductMappingAsync(userProductMapping); + + return result ? userProductMapping.ToJson() : string.Empty; + } + + [AllowAnonymous] + [HttpPost] + [Route(APIUrls.DeleteUserProductMappingRouteName)] + [SignalR(SignalRTags.DeleteUserProductMapping)] + public async Task DeleteUserProductMapping(UserProductMapping userProductMapping) + { + _logger.Info($"UpdateUserProductMapping called! + {userProductMapping.Id}"); + + var result = await adminDal.RemoveUserProductMappingAsync(userProductMapping.Id); + + return result ? userProductMapping.ToJson() : string.Empty; + } + //23. [AllowAnonymous] [HttpPost] @@ -207,6 +234,90 @@ namespace TIAMWebApp.Server.Controllers //put serviceprovider id and name into a dictionary return myServiceproviders; + } + + [AllowAnonymous] + [HttpGet] + [Route(APIUrls.GetCarsForUserProductMappingRouteName + "/{userProductMappingId}")] + [SignalR(SignalRTags.GetCarsForUserProductMapping)] + public async Task> GetCarsForUserProductMapping(string userProductMappingId) + { + _logger.Info($@"GetCarsForUserProductMapping called with userProductMappingId: {userProductMappingId}"); + + var userProductMappingDictionary = new Dictionary(); + + var serviceProviders = adminDal.GetCarByUserProductMappingId(Guid.Parse(userProductMappingId)); + + var myServiceproviders = serviceProviders.Where(x => x.Id == Guid.Parse(userProductMappingId)).ToDictionary(x => x.Id, x => x.Name); + //put serviceprovider id and name into a dictionary + + return myServiceproviders; + } + + [AllowAnonymous] + [HttpPost] + [Route(APIUrls.CreateCarRouteName)] + [Tags("Finished", "Cars")] + [EndpointSummary("Create car")] + [SignalR(SignalRTags.CreateCar)] + public async Task CreateCar(Car car) + { + if (car.UserProductMappingId == Guid.Empty || car.LicencePlate == null) + { + return BadRequest("Invalid request"); + } + else + { + _logger.Info($@"CreateCar called with ownerId: {car.UserProductMappingId}, {car.LicencePlate}"); + + var result = await adminDal.AddCarAsync(car); + + return Ok(car); + } + } + + [AllowAnonymous] + [HttpPost] + [Route(APIUrls.UpdateCarRouteName)] + [Tags("Finished", "Cars")] + [EndpointSummary("Update car")] + [SignalR(SignalRTags.UpdateCar)] + public async Task UpdateCar(Car car) + { + if (car.UserProductMappingId == Guid.Empty || car.LicencePlate == null) + { + return BadRequest("Invalid request"); + } + else + { + _logger.Info($@"CreateCar called with ownerId: {car.UserProductMappingId}, {car.LicencePlate}"); + + var result = await adminDal.UpdateCarAsync(car); + + return Ok(car); + } + } + + [AllowAnonymous] + [HttpPost] + [Route(APIUrls.DeleteCarRouteName)] + [Tags("Finished", "Cars")] + [EndpointSummary("Delete car")] + [SignalR(SignalRTags.DeleteCar)] + public async Task DeleteCar(Car car) + { + if (car.UserProductMappingId == Guid.Empty || car.LicencePlate == null) + { + return BadRequest("Invalid request"); + } + else + { + _logger.Info($@"CreateCar called with ownerId: {car.UserProductMappingId}, {car.LicencePlate}"); + + var result = await adminDal.RemoveCarAsync(car); + + return Ok(car); + } } [HttpPost] diff --git a/TIAMWebApp/Shared/Models/APIUrls.cs b/TIAMWebApp/Shared/Models/APIUrls.cs index a74063fd..96a3b2b0 100644 --- a/TIAMWebApp/Shared/Models/APIUrls.cs +++ b/TIAMWebApp/Shared/Models/APIUrls.cs @@ -131,18 +131,35 @@ namespace TIAMWebApp.Shared.Application.Models public const string CreateUserProductMappingRouteName = "CreateUserProductMapping"; public const string CreateUserProductMapping = ServiceProviderAPI + CreateUserProductMappingRouteName; + public const string UpdateUserProductMappingRouteName = "UpdateUserProductMapping"; + public const string UpdateUserProductMapping = ServiceProviderAPI + UpdateUserProductMappingRouteName; + + public const string DeleteUserProductMappingRouteName = "DeleteUserProductMapping"; + public const string DeleteUserProductMapping = ServiceProviderAPI + DeleteUserProductMappingRouteName; + public const string GetServiceProvidersRouteName = "GetServiceProviders"; public const string GetServiceProviders = ServiceProviderAPI + GetServiceProvidersRouteName; public const string GetUserProductMappingsForProductRouteName = "GetUserProductMappingsForProduct"; public const string GetUserProductMappingsForProduct = ServiceProviderAPI + GetUserProductMappingsForProductRouteName; + public const string GetCarsForUserProductMappingRouteName = "GetCarsForUserProductMapping"; + public const string GetCarsForUserProductMapping = ServiceProviderAPI + GetCarsForUserProductMappingRouteName; + + public const string CreateCarRouteName = "GetCarsForUserProductMapping"; + public const string CreateCar = ServiceProviderAPI + CreateCarRouteName; + + public const string UpdateCarRouteName = "GetCarsForUserProductMapping"; + public const string UpdateCar = ServiceProviderAPI + UpdateCarRouteName; + + public const string DeleteCarRouteName = "GetCarsForUserProductMapping"; + public const string DeleteCar = ServiceProviderAPI + DeleteCarRouteName; //AssingedUsers - public const string CreateAssignedUserRouteName = "CreateAssignedUser"; - public const string CreateAssignedUser = ServiceProviderAPI + CreateAssignedUserRouteName; - public const string GetAssignedUsersForServiceProviderRouteName = "GetAssignedUsersForServiceProvider"; - public const string GetAssignedUsersForServiceProvider = ServiceProviderAPI + GetAssignedUsersForServiceProviderRouteName; + //public const string CreateAssignedUserRouteName = "CreateAssignedUser"; + //public const string CreateAssignedUser = ServiceProviderAPI + CreateAssignedUserRouteName; + //public const string GetAssignedUsersForServiceProviderRouteName = "GetAssignedUsersForServiceProvider"; + //public const string GetAssignedUsersForServiceProvider = ServiceProviderAPI + GetAssignedUsersForServiceProviderRouteName; //permissions //1 diff --git a/TIAMWebApp/Shared/Models/CreateAssignedUserModel.cs b/TIAMWebApp/Shared/Models/CreateAssignedUserModel.cs index a866a8e4..886d7078 100644 --- a/TIAMWebApp/Shared/Models/CreateAssignedUserModel.cs +++ b/TIAMWebApp/Shared/Models/CreateAssignedUserModel.cs @@ -13,5 +13,7 @@ namespace TIAMWebApp.Shared.Application.Models public Guid UserId { get; set; } + public int? Permission { get; set; } + } } From b917b3d09ffe5876136a4adf6b86939a00db42bd Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 2 Jun 2024 11:02:29 +0200 Subject: [PATCH 2/3] fix --- .../Controllers/ServiceProviderAPIController.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs index 1c6707e6..edc5a013 100644 --- a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs +++ b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs @@ -240,18 +240,13 @@ namespace TIAMWebApp.Server.Controllers [HttpGet] [Route(APIUrls.GetCarsForUserProductMappingRouteName + "/{userProductMappingId}")] [SignalR(SignalRTags.GetCarsForUserProductMapping)] - public async Task> GetCarsForUserProductMapping(string userProductMappingId) + public async Task> GetCarsForUserProductMapping(string userProductMappingId) { _logger.Info($@"GetCarsForUserProductMapping called with userProductMappingId: {userProductMappingId}"); - var userProductMappingDictionary = new Dictionary(); + var cars = adminDal.GetCarByUserProductMappingId(Guid.Parse(userProductMappingId)); - var serviceProviders = adminDal.GetCarByUserProductMappingId(Guid.Parse(userProductMappingId)); - - var myServiceproviders = serviceProviders.Where(x => x.Id == Guid.Parse(userProductMappingId)).ToDictionary(x => x.Id, x => x.Name); - //put serviceprovider id and name into a dictionary - - return myServiceproviders; + return cars; } [AllowAnonymous] From 126e90752043736b1624eb0441d26f2668d4cdde Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 2 Jun 2024 15:44:06 +0200 Subject: [PATCH 3/3] apiurls fix + emailmessage, formula1 fixes --- TIAM.Services.Server/MessageSenderService.cs | 6 +-- .../Pages/Components/InputWizard.razor.cs | 6 +-- TIAMSharedUI/Pages/Formula1.razor | 41 +++++++++++++++++-- .../Controllers/MessageAPIController.cs | 6 ++- .../Controllers/TransferDataAPIController.cs | 8 ++-- TIAMWebApp/Shared/Models/APIUrls.cs | 6 +-- 6 files changed, 54 insertions(+), 19 deletions(-) diff --git a/TIAM.Services.Server/MessageSenderService.cs b/TIAM.Services.Server/MessageSenderService.cs index b67541d7..08e197ff 100644 --- a/TIAM.Services.Server/MessageSenderService.cs +++ b/TIAM.Services.Server/MessageSenderService.cs @@ -59,7 +59,7 @@ namespace TIAM.Services.Server if (message.SenderId == Guid.Empty) { - + message.EmailAddress = "noreply@anataworld.com"; from = new EmailAddress("noreply@anataworld.com", "TourIAm mailservice"); } else @@ -91,8 +91,8 @@ namespace TIAM.Services.Server { Console.WriteLine($"{response.StatusCode}, {response.Body.ReadAsStringAsync()}"); } - - adminDal.AddEmailMessageAsync(message).Forget(); + //message.Id = Guid.NewGuid(); + //adminDal.AddEmailMessageAsync(message).Forget(); } catch(Exception ex) { diff --git a/TIAMSharedUI/Pages/Components/InputWizard.razor.cs b/TIAMSharedUI/Pages/Components/InputWizard.razor.cs index 0d55b5a7..b263bb03 100644 --- a/TIAMSharedUI/Pages/Components/InputWizard.razor.cs +++ b/TIAMSharedUI/Pages/Components/InputWizard.razor.cs @@ -116,7 +116,7 @@ namespace TIAMSharedUI.Pages.Components _logger.Info("Hellooooo " + type.AssemblyQualifiedName); var propertyList = type.GetProperties(); - var length = propertyList.Length - IgnoreReflection.Count; + //var length = propertyList.Length - IgnoreReflection.Count; //var propertyList = typeof(TestUserData).GetProperties(); formLayoutBuilder.OpenComponent(0); @@ -484,7 +484,7 @@ namespace TIAMSharedUI.Pages.Components layoutItemBuilder.AddAttribute(i++, "Click", EventCallback.Factory.Create(this, OnNext)); layoutItemBuilder.AddAttribute(i++, "SubmitFormOnClick", false); layoutItemBuilder.AddAttribute(i++, "CssClass", "btn btn-primary mt-3"); - if (!(k < length - 1)) + if (!(k < FormSteps.Count - 1)) { layoutItemBuilder.AddAttribute(i++, "disabled", "true"); @@ -520,7 +520,7 @@ namespace TIAMSharedUI.Pages.Components editor.AddAttribute(i++, "type", "submit"); editor.AddAttribute(i++, "class", "btn btn-primary mt-3 w-100"); editor.AddAttribute(i++, "style", "margin: 0 auto"); - if (CurrentStep < length - 1) + if (CurrentStep < FormSteps.Count - 1) { editor.AddAttribute(i++, "disabled", "true"); diff --git a/TIAMSharedUI/Pages/Formula1.razor b/TIAMSharedUI/Pages/Formula1.razor index 797b77fe..d612027f 100644 --- a/TIAMSharedUI/Pages/Formula1.razor +++ b/TIAMSharedUI/Pages/Formula1.razor @@ -417,7 +417,7 @@ new HeroSliderItem public List TransferIgnorList = new List { - "Id", + "Id", "UserId", "Destination", "PickupAddress", @@ -442,9 +442,9 @@ new HeroSliderItem public async Task SubmitForm(object result) { var orderModel = result as TransferWizardModel; - + //check if user exists - if (sessionService.IsAuthenticated && sessionService.User != null ) + if (sessionService.IsAuthenticated && sessionService.User != null) { //Basic settings orderModel.UserId = sessionService.User.UserModelDto.Id; @@ -461,7 +461,7 @@ new HeroSliderItem if (user != null) { orderModel.UserId = user.Id; - + orderModel.ProductId = user.Products.FirstOrDefault()?.Id; } else @@ -515,6 +515,35 @@ new HeroSliderItem public async Task> ProcessTransfers(TransferWizardModel orderModel) { List transferList = new List(); + double _transferPrice = 0.0f; + if(orderModel.NumberOfPassengers < 5) { + switch (transferList.Count) + { + case (1): + _transferPrice = 119/2; + break; + case (2): + _transferPrice = 199 / 4; + break; + case (3): + _transferPrice = 269 / 6; + break; + } + }else if (orderModel.NumberOfPassengers > 5 && orderModel.NumberOfPassengers < 8) { + switch (transferList.Count) + { + case (1): + _transferPrice = 219f /2; + break; + case (2): + _transferPrice = 359 / 4; + break; + case (3): + _transferPrice = 489 / 6; + break; + } + } + foreach (var date in OrderDates) { @@ -525,6 +554,9 @@ new HeroSliderItem // Outbound trip transfer.PickupAddress = OrderLocation; transfer.Destination = "Hungaroring"; + transfer.PhoneNumber = orderModel.PhoneNumber; + transfer.EmailAddress = orderModel.EmailAddress; + transfer.Price = _transferPrice; transferList.Add(transfer); // Return trip @@ -534,6 +566,7 @@ new HeroSliderItem transfer.Destination = OrderLocation; transfer.PhoneNumber = orderModel.PhoneNumber; transfer.EmailAddress = orderModel.EmailAddress; + transfer.Price = _transferPrice; transferList.Add(transfer); } diff --git a/TIAMWebApp/Server/Controllers/MessageAPIController.cs b/TIAMWebApp/Server/Controllers/MessageAPIController.cs index 906a537c..3eebef98 100644 --- a/TIAMWebApp/Server/Controllers/MessageAPIController.cs +++ b/TIAMWebApp/Server/Controllers/MessageAPIController.cs @@ -71,8 +71,10 @@ namespace TIAMWebApp.Server.Controllers var messageElement = message.Message; Console.WriteLine(message.Message); var result = await _messageSenderService.SendMessageAsync(messageElement, (int)message.MessageType); - //_adminDal.AddEmailMessageAsync((TIAM.Entities.Emails.EmailMessage)SerializedMessageSenderModel.Message); - Console.WriteLine("SendEmail result: " + result); + //_adminDal.AddEmailMessageAsync((TIAM.Entities.Emails.EmailMessage)SerializedMessageSenderModel.Message); + messageElement.EmailAddress = "noreply@anataworld.com"; + _adminDal.AddEmailMessageAsync(messageElement).Forget(); + Console.WriteLine("SendEmail result: " + result); return Ok(result); } diff --git a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs index 3e228f28..2ed97d0c 100644 --- a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs +++ b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs @@ -299,23 +299,23 @@ namespace TIAMWebApp.Server.Controllers [AllowAnonymous] [HttpPost] [Route(APIUrls.CreateTransfersRouteName)] - public async Task CreateTransfers([FromBody] JsonElement serializedTransferModel) + public async Task CreateTransfers([FromBody] JsonElement serializedTransferList) { _logger.Info(@"CreateTransfers called!"); - if (string.IsNullOrEmpty(serializedTransferModel.GetRawText())) + if (string.IsNullOrEmpty(serializedTransferList.GetRawText())) { return BadRequest("SerializedTramsferDestinationWizardModel is required"); } else { - _logger.Info($@"Serialized model: {serializedTransferModel.GetRawText()}"); + _logger.Info($@"Serialized model: {serializedTransferList.GetRawText()}"); var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; - List? transfers = JsonConvert.DeserializeObject>(serializedTransferModel.GetRawText(), settings); + List? transfers = JsonConvert.DeserializeObject>(serializedTransferList.GetRawText(), settings); //List? transfers = JObject.Parse(serializedTransferModel.GetRawText()).ToObject>(); List createdTransfers = new List(); diff --git a/TIAMWebApp/Shared/Models/APIUrls.cs b/TIAMWebApp/Shared/Models/APIUrls.cs index 96a3b2b0..0700ced5 100644 --- a/TIAMWebApp/Shared/Models/APIUrls.cs +++ b/TIAMWebApp/Shared/Models/APIUrls.cs @@ -146,13 +146,13 @@ namespace TIAMWebApp.Shared.Application.Models public const string GetCarsForUserProductMappingRouteName = "GetCarsForUserProductMapping"; public const string GetCarsForUserProductMapping = ServiceProviderAPI + GetCarsForUserProductMappingRouteName; - public const string CreateCarRouteName = "GetCarsForUserProductMapping"; + public const string CreateCarRouteName = "CreateCar"; public const string CreateCar = ServiceProviderAPI + CreateCarRouteName; - public const string UpdateCarRouteName = "GetCarsForUserProductMapping"; + public const string UpdateCarRouteName = "UpdateCar"; public const string UpdateCar = ServiceProviderAPI + UpdateCarRouteName; - public const string DeleteCarRouteName = "GetCarsForUserProductMapping"; + public const string DeleteCarRouteName = "DeleteCar"; public const string DeleteCar = ServiceProviderAPI + DeleteCarRouteName; //AssingedUsers