Cars and UserProductMapping endpoints and dal (?)
This commit is contained in:
parent
a81fc649f0
commit
fcc2af8e85
|
|
@ -41,6 +41,10 @@ namespace TIAM.Database.DataLayers.Admins
|
||||||
#region Car
|
#region Car
|
||||||
public Car? GetCarById(Guid carId) => Session(ctx => ctx.Cars.FirstOrDefault(x => x.Id == carId));
|
public Car? GetCarById(Guid carId) => Session(ctx => ctx.Cars.FirstOrDefault(x => x.Id == carId));
|
||||||
public List<Car> GetCarByUserProductMappingId(Guid userProductMappingId) => Session(ctx => ctx.Cars.Where(x => x.UserProductMappingId == userProductMappingId).ToList());
|
public List<Car> GetCarByUserProductMappingId(Guid userProductMappingId) => Session(ctx => ctx.Cars.Where(x => x.UserProductMappingId == userProductMappingId).ToList());
|
||||||
|
public Task<bool> AddCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Add(car).State == EntityState.Added);
|
||||||
|
public Task<bool> UpdateCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Update(car).State == EntityState.Modified);
|
||||||
|
public Task<bool> RemoveCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Remove(car).State == EntityState.Deleted);
|
||||||
|
|
||||||
#endregion Car
|
#endregion Car
|
||||||
|
|
||||||
#region Transfer
|
#region Transfer
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,16 @@ public class SignalRTags : AcSignalRTags
|
||||||
|
|
||||||
public const int GetProfileById = 22;
|
public const int GetProfileById = 22;
|
||||||
public const int UpdateProfile = 23;
|
public const int UpdateProfile = 23;
|
||||||
//public const int AddAddress = 24;
|
//public const int AddProfile = 24;
|
||||||
//public const int RemoveAddress = 25;
|
//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;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -18,6 +18,8 @@ using AyCode.Utils.Extensions;
|
||||||
using TIAM.Services;
|
using TIAM.Services;
|
||||||
using TIAMWebApp.Server.Services;
|
using TIAMWebApp.Server.Services;
|
||||||
using TIAM.Entities.Transfers;
|
using TIAM.Entities.Transfers;
|
||||||
|
using TIAMWebApp.Shared.Application.Services;
|
||||||
|
using TIAM.Entities.Drivers;
|
||||||
|
|
||||||
namespace TIAMWebApp.Server.Controllers
|
namespace TIAMWebApp.Server.Controllers
|
||||||
{
|
{
|
||||||
|
|
@ -173,17 +175,16 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
[Route(APIUrls.CreateUserProductMappingRouteName)]
|
[Route(APIUrls.CreateUserProductMappingRouteName)]
|
||||||
[Tags("Finished", "ServiceProvider")]
|
[Tags("Finished", "ServiceProvider")]
|
||||||
[EndpointSummary("Create assigned user to product")]
|
[EndpointSummary("Create assigned user to product")]
|
||||||
public async Task<IActionResult> CreateUserProductMapping(CreateUserProductMappingModel createUserProductMappingModel)
|
[SignalR(SignalRTags.CreateUserProductMapping)]
|
||||||
|
public async Task<IActionResult> 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");
|
return BadRequest("Invalid request");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Info($@"CreateUserProductMappings called with ownerId: {createUserProductMappingModel.ContextId}, {createUserProductMappingModel.ContextId}");
|
_logger.Info($@"CreateUserProductMappings called with ownerId: {userProductMapping.ProductId}, {userProductMapping.UserId}");
|
||||||
|
|
||||||
var userProductMapping = new UserProductMapping(createUserProductMappingModel.ContextId, createUserProductMappingModel.ContextId);
|
|
||||||
|
|
||||||
var result = await adminDal.AddUserProductMappingAsync(userProductMapping);
|
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<string> 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<string> DeleteUserProductMapping(UserProductMapping userProductMapping)
|
||||||
|
{
|
||||||
|
_logger.Info($"UpdateUserProductMapping called! + {userProductMapping.Id}");
|
||||||
|
|
||||||
|
var result = await adminDal.RemoveUserProductMappingAsync(userProductMapping.Id);
|
||||||
|
|
||||||
|
return result ? userProductMapping.ToJson() : string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
//23.
|
//23.
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|
@ -207,6 +234,90 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
//put serviceprovider id and name into a dictionary
|
//put serviceprovider id and name into a dictionary
|
||||||
|
|
||||||
return myServiceproviders;
|
return myServiceproviders;
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet]
|
||||||
|
[Route(APIUrls.GetCarsForUserProductMappingRouteName + "/{userProductMappingId}")]
|
||||||
|
[SignalR(SignalRTags.GetCarsForUserProductMapping)]
|
||||||
|
public async Task<Dictionary<Guid, string>> GetCarsForUserProductMapping(string userProductMappingId)
|
||||||
|
{
|
||||||
|
_logger.Info($@"GetCarsForUserProductMapping called with userProductMappingId: {userProductMappingId}");
|
||||||
|
|
||||||
|
var userProductMappingDictionary = new Dictionary<Guid, string>();
|
||||||
|
|
||||||
|
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<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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpPost]
|
||||||
|
[Route(APIUrls.UpdateCarRouteName)]
|
||||||
|
[Tags("Finished", "Cars")]
|
||||||
|
[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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpPost]
|
||||||
|
[Route(APIUrls.DeleteCarRouteName)]
|
||||||
|
[Tags("Finished", "Cars")]
|
||||||
|
[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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|
|
||||||
|
|
@ -131,18 +131,35 @@ namespace TIAMWebApp.Shared.Application.Models
|
||||||
public const string CreateUserProductMappingRouteName = "CreateUserProductMapping";
|
public const string CreateUserProductMappingRouteName = "CreateUserProductMapping";
|
||||||
public const string CreateUserProductMapping = ServiceProviderAPI + CreateUserProductMappingRouteName;
|
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 GetServiceProvidersRouteName = "GetServiceProviders";
|
||||||
public const string GetServiceProviders = ServiceProviderAPI + GetServiceProvidersRouteName;
|
public const string GetServiceProviders = ServiceProviderAPI + GetServiceProvidersRouteName;
|
||||||
|
|
||||||
public const string GetUserProductMappingsForProductRouteName = "GetUserProductMappingsForProduct";
|
public const string GetUserProductMappingsForProductRouteName = "GetUserProductMappingsForProduct";
|
||||||
public const string GetUserProductMappingsForProduct = ServiceProviderAPI + GetUserProductMappingsForProductRouteName;
|
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
|
//AssingedUsers
|
||||||
public const string CreateAssignedUserRouteName = "CreateAssignedUser";
|
//public const string CreateAssignedUserRouteName = "CreateAssignedUser";
|
||||||
public const string CreateAssignedUser = ServiceProviderAPI + CreateAssignedUserRouteName;
|
//public const string CreateAssignedUser = ServiceProviderAPI + CreateAssignedUserRouteName;
|
||||||
public const string GetAssignedUsersForServiceProviderRouteName = "GetAssignedUsersForServiceProvider";
|
//public const string GetAssignedUsersForServiceProviderRouteName = "GetAssignedUsersForServiceProvider";
|
||||||
public const string GetAssignedUsersForServiceProvider = ServiceProviderAPI + GetAssignedUsersForServiceProviderRouteName;
|
//public const string GetAssignedUsersForServiceProvider = ServiceProviderAPI + GetAssignedUsersForServiceProviderRouteName;
|
||||||
|
|
||||||
//permissions
|
//permissions
|
||||||
//1
|
//1
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,7 @@ namespace TIAMWebApp.Shared.Application.Models
|
||||||
|
|
||||||
public Guid UserId { get; set; }
|
public Guid UserId { get; set; }
|
||||||
|
|
||||||
|
public int? Permission { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue