Implement CompanyDataChanging, CarDataChanging; improvements, fixes...
This commit is contained in:
parent
536b9304d0
commit
b140458409
|
|
@ -38,16 +38,16 @@ public class SignalRTags : AcSignalRTags
|
|||
//public const int GetProfiles = 36;
|
||||
public const int GetProfilesByContextId = 37;
|
||||
public const int UpdateProfile = 38;
|
||||
|
||||
//public const int AddAddress = 39;
|
||||
//public const int RemoveAddress = 40;
|
||||
|
||||
public const int CreateUserProductMapping = 27;
|
||||
public const int UpdateUserProductMapping = 28;
|
||||
public const int DeleteUserProductMapping = 29; //set permissions to 0
|
||||
public const int CreateUserProductMapping = 47;
|
||||
public const int UpdateUserProductMapping = 48;
|
||||
public const int DeleteUserProductMapping = 49; //set permissions to 0
|
||||
|
||||
public const int GetCarsForUserProductMapping = 30;
|
||||
public const int CreateCar = 31;
|
||||
public const int UpdateCar = 32;
|
||||
public const int DeleteCar = 33;
|
||||
public const int GetCarsForUserProductMapping = 50;
|
||||
public const int CreateCar = 51;
|
||||
public const int UpdateCar = 52;
|
||||
public const int DeleteCar = 53;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text.Json;
|
||||
using AyCode.Core.Helpers;
|
||||
using TIAMWebApp.Shared.Application.Models;
|
||||
using TIAMWebApp.Shared.Application.Models.ClientSide.Messages;
|
||||
using AyCode.Models.Enums;
|
||||
|
|
@ -53,7 +54,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
var result = await _messageSenderService.SendMessageAsync(messageElement, (int)message.MessageType);
|
||||
//_adminDal.AddEmailMessageAsync((TIAM.Entities.Emails.EmailMessage)SerializedMessageSenderModel.Message);
|
||||
messageElement.EmailAddress = "noreply@anataworld.com";
|
||||
_adminDal.AddEmailMessageAsync(messageElement).Forget();
|
||||
await _adminDal.AddEmailMessageAsync(messageElement);
|
||||
Console.WriteLine("SendEmail result: " + result);
|
||||
return Ok(result);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||
using QRCoder;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using AyCode.Core.Enums;
|
||||
using AyCode.Core.Extensions;
|
||||
using TIAM.Database.DataLayers.Admins;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
|
|
@ -13,6 +14,8 @@ using TIAM.Entities.Addresses;
|
|||
using TIAM.Entities.Profiles;
|
||||
using AyCode.Core.Loggers;
|
||||
using AyCode.Services.SignalRs;
|
||||
using AyCode.Utils.Extensions;
|
||||
using TIAM.Entities.Drivers;
|
||||
using TIAM.Services;
|
||||
|
||||
namespace TIAMWebApp.Server.Controllers
|
||||
|
|
@ -24,79 +27,96 @@ namespace TIAMWebApp.Server.Controllers
|
|||
{
|
||||
private readonly TIAM.Core.Loggers.Logger<ServiceProviderAPIController> _logger = new(logWriters.ToArray());
|
||||
|
||||
[NonAction]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
private async Task<bool> CompanyDataChanging(Company company, DataChangeMode dataChangeMode)
|
||||
{
|
||||
var logText = $"CompanyDataChanging {dataChangeMode} called; id: {company.Id}; ownerId: {company.OwnerId}; Name: {company.Name}";
|
||||
|
||||
if (company.Name.IsNullOrEmpty())
|
||||
{
|
||||
_logger.Error(logText);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.Info(logText);
|
||||
|
||||
switch (dataChangeMode)
|
||||
{
|
||||
case DataChangeMode.Add:
|
||||
if (company.Id.IsNullOrEmpty()) company.Id = Guid.NewGuid();
|
||||
|
||||
company.SetProfile(new Profile(Guid.NewGuid(), company.Name));
|
||||
company.Profile.SetAddress(new Address(Guid.NewGuid(), "Controller AddCompanyAsync; address text..."));
|
||||
|
||||
return await adminDal.CreateServiceProviderAsync(company);
|
||||
|
||||
case DataChangeMode.Update:
|
||||
return await adminDal.UpdateCompanyAsync(company);
|
||||
case DataChangeMode.Remove:
|
||||
return await adminDal.RemoveCompanyAsync(company);
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(dataChangeMode), dataChangeMode, null);
|
||||
}
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
[SignalR(SignalRTags.AddCompany)]
|
||||
public async Task<string> AddCompanyAsync(Company company)
|
||||
=> await CompanyDataChanging(company, DataChangeMode.Add) ? company.ToJson() : string.Empty;
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route(APIUrls.UpdateServiceProviderRouteName)]
|
||||
[SignalR(SignalRTags.UpdateCompany)]
|
||||
public async Task<string> UpdateServiceProvider(Company company)
|
||||
=> await CompanyDataChanging(company, DataChangeMode.Update) ? company.ToJson() : string.Empty;
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route(APIUrls.RemoveServiceProviderRouteName)]
|
||||
[SignalR(SignalRTags.RemoveCompany)]
|
||||
public async Task<string> RemoveServiceProvider(Company company)
|
||||
=> await CompanyDataChanging(company, DataChangeMode.Remove) ? company.ToJson() : string.Empty;
|
||||
|
||||
//15.
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route(APIUrls.CreateServiceProviderRouteName)]
|
||||
[Tags("In-Progress", "ServiceProvider")]
|
||||
[EndpointSummary("Create service provider")]
|
||||
public async Task<string> CreateServiceProvider([FromBody] ServiceProviderModel serializedServiceProviderModel)
|
||||
public async Task<string> CreateServiceProvider([FromBody] ServiceProviderModel? serializedServiceProviderModel)
|
||||
{
|
||||
_logger.Info(@"CreateServiceProvider called");
|
||||
|
||||
//if (serializedServiceProviderModel.GetArrayLength() == 0)
|
||||
if (serializedServiceProviderModel == null)
|
||||
{
|
||||
return string.Empty;//BadRequest("SerializedLoginModel is required").ToJson();
|
||||
return string.Empty; //BadRequest("SerializedLoginModel is required").ToJson();
|
||||
}
|
||||
else
|
||||
|
||||
//Company? serviceProvider = JObject.Parse(serializedServiceProviderModel.GetRawText()).ToObject<Company>();
|
||||
var serviceProvider = serializedServiceProviderModel;
|
||||
|
||||
var id = Guid.NewGuid();
|
||||
var name = serviceProvider.Name;
|
||||
var commissionRate = serviceProvider.CommissionPercent;
|
||||
|
||||
//no owner set yet
|
||||
var ownerId = serviceProvider.OwnerId == Guid.Empty ? null : serviceProvider.OwnerId;
|
||||
//ownerId = Guid.Parse("540271F6-C604-4C16-8160-D5A7CAFEDF00"); //TESZT - J.
|
||||
|
||||
if (name is null) return string.Empty; //BadRequest("Invalid request");
|
||||
|
||||
var company = new Company(id, name, ownerId, Guid.NewGuid())
|
||||
{
|
||||
|
||||
//Company? serviceProvider = JObject.Parse(serializedServiceProviderModel.GetRawText()).ToObject<Company>();
|
||||
var serviceProvider = serializedServiceProviderModel;
|
||||
if (serviceProvider != null)
|
||||
{
|
||||
var id = Guid.NewGuid();
|
||||
var name = serviceProvider.Name;
|
||||
var commissionRate = serviceProvider.CommissionPercent;
|
||||
CommissionPercent = commissionRate
|
||||
};
|
||||
|
||||
|
||||
//no owner set yet
|
||||
var ownerId = serviceProvider.OwnerId == Guid.Empty ? null : serviceProvider.OwnerId;
|
||||
//ownerId = Guid.Parse("540271F6-C604-4C16-8160-D5A7CAFEDF00"); //TESZT - J.
|
||||
|
||||
if (name is null)
|
||||
{
|
||||
return string.Empty;//BadRequest("Invalid request");
|
||||
}
|
||||
else
|
||||
{
|
||||
var company = new Company(id, name, ownerId, Guid.NewGuid())
|
||||
{
|
||||
CommissionPercent = commissionRate
|
||||
};
|
||||
|
||||
return await AddCompanyAsync(company);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
return string.Empty;//BadRequest();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.AddCompany)]
|
||||
public async Task<string> AddCompanyAsync(Company company)
|
||||
{
|
||||
if (company.Id.IsNullOrEmpty()) company.Id = Guid.NewGuid();
|
||||
|
||||
_logger.Info($@"ServiceProvider to be creating; id: {company.Id}, name: {company.Name}, ownerId: {company.OwnerId}");
|
||||
|
||||
company.SetProfile(new Profile(Guid.NewGuid(), company.Name));
|
||||
company.Profile.SetAddress(new Address(Guid.NewGuid(), "Controller AddCompanyAsync; address text..."));
|
||||
|
||||
var result = await adminDal.CreateServiceProviderAsync(company);
|
||||
if (!result)
|
||||
{
|
||||
return string.Empty;//BadRequest(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return company.ToJson();//Ok(toCreate);
|
||||
}
|
||||
return await AddCompanyAsync(company);
|
||||
}
|
||||
|
||||
//16.
|
||||
|
|
@ -109,17 +129,6 @@ namespace TIAMWebApp.Server.Controllers
|
|||
return await adminDal.GetServiceProvidersJsonAsync();
|
||||
}
|
||||
|
||||
//[AllowAnonymous]
|
||||
//[HttpGet]
|
||||
//[Route(APIUrls.GetServiceProvidersRouteName)]
|
||||
//public Task<string> GetServiceProviders() => Task.FromResult(GetServiceProvidersMethod());
|
||||
|
||||
//[SignalR(SignalRTags.GetCompaniesAsync)]
|
||||
//public string GetServiceProvidersMethod()
|
||||
//{
|
||||
// return adminDal.GetServiceProvidersJson();
|
||||
//}
|
||||
|
||||
//18.
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
|
|
@ -131,18 +140,6 @@ namespace TIAMWebApp.Server.Controllers
|
|||
return await adminDal.GetServiceProviderByIdAsync(id);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route(APIUrls.UpdateServiceProviderRouteName)]
|
||||
[SignalR(SignalRTags.UpdateCompany)]
|
||||
public async Task<string> UpdateServiceProvider(Company companyToModify)
|
||||
{
|
||||
_logger.Info($"UpdateServiceProvider called! + {companyToModify.Id}");
|
||||
|
||||
var result = await adminDal.UpdateCompanyAsync(companyToModify);
|
||||
|
||||
return result ? companyToModify.ToJson() : string.Empty;
|
||||
}
|
||||
|
||||
//17.
|
||||
[Authorize]
|
||||
|
|
@ -243,6 +240,37 @@ namespace TIAMWebApp.Server.Controllers
|
|||
return cars;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
private async Task<bool> CarDataChanging(Car car, DataChangeMode dataChangeMode)
|
||||
{
|
||||
var logText = $"CarDataChanging {dataChangeMode} called; id: {car.Id}; ownerId: {car.UserProductMappingId}; licensePlate: {car.LicencePlate}";
|
||||
|
||||
if (car.UserProductMappingId.IsNullOrEmpty() || car.LicencePlate.IsNullOrWhiteSpace())
|
||||
{
|
||||
_logger.Error(logText);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.Info(logText);
|
||||
|
||||
switch (dataChangeMode)
|
||||
{
|
||||
case DataChangeMode.Add:
|
||||
if (car.Id.IsNullOrEmpty()) car.Id = Guid.NewGuid();
|
||||
|
||||
return await adminDal.AddCarAsync(car);
|
||||
case DataChangeMode.Update:
|
||||
return await adminDal.UpdateCarAsync(car);
|
||||
case DataChangeMode.Remove:
|
||||
return await adminDal.RemoveCarAsync(car);
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(dataChangeMode), dataChangeMode, null);
|
||||
}
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[Route(APIUrls.CreateCarRouteName)]
|
||||
|
|
@ -250,20 +278,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[EndpointSummary("Create car")]
|
||||
[SignalR(SignalRTags.CreateCar)]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
}
|
||||
=> await CarDataChanging(car, DataChangeMode.Add) ? Ok(car) : BadRequest("Invalid request");
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
|
|
@ -272,20 +287,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[EndpointSummary("Update car")]
|
||||
[SignalR(SignalRTags.UpdateCar)]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
}
|
||||
=> await CarDataChanging(car, DataChangeMode.Update) ? Ok(car) : BadRequest("Invalid request");
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
|
|
@ -294,20 +296,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[EndpointSummary("Delete car")]
|
||||
[SignalR(SignalRTags.DeleteCar)]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
}
|
||||
=> await CarDataChanging(car, DataChangeMode.Remove) ? Ok(car) : BadRequest("Invalid request");
|
||||
|
||||
[HttpPost]
|
||||
[Route(APIUrls.AddProductRouteName)]
|
||||
|
|
|
|||
|
|
@ -169,13 +169,6 @@ public class DevAdminSignalRHub : Hub<ISignalRHubItemServer>, IAcSignalRHubServe
|
|||
address = await _adminDal.GetAddressByIdAsync(id);
|
||||
await ResponseToCaller(messageTag, new SignalResponseJsonMessage(SignalResponseStatus.Success, new List<Address> { address! }), requestId);
|
||||
|
||||
return;
|
||||
case SignalRTags.RemoveCompany:
|
||||
var deleteCompany = message!.MessagePackTo<SignalPostJsonDataMessage<Company>>().PostData;
|
||||
|
||||
await _adminDal.RemoveCompanyAsync(deleteCompany.Id);
|
||||
await ResponseToCaller(messageTag, new SignalResponseJsonMessage(SignalResponseStatus.Success), requestId);
|
||||
|
||||
return;
|
||||
|
||||
case SignalRTags.UpdateAddress:
|
||||
|
|
|
|||
|
|
@ -114,6 +114,9 @@ namespace TIAMWebApp.Shared.Application.Models
|
|||
public const string UpdateServiceProviderRouteName = "UpdateServiceProvider";
|
||||
public const string UpdateServiceProviderUrl = ServiceProviderAPI + UpdateServiceProviderRouteName;
|
||||
|
||||
public const string RemoveServiceProviderRouteName = "RemoveServiceProvider";
|
||||
public const string RemoveServiceProviderUrl = ServiceProviderAPI + UpdateServiceProviderRouteName;
|
||||
|
||||
|
||||
|
||||
public const string GetQrCodeByProductIdRouteName = "GetQRCodeByProductId";
|
||||
|
|
|
|||
Loading…
Reference in New Issue