This commit is contained in:
Loretta 2024-06-24 14:11:53 +02:00
parent 7843108576
commit 1f34a556eb
2 changed files with 19 additions and 45 deletions

View File

@ -130,8 +130,10 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> RemoveProductAsync(Guid productId) => TransactionAsync(ctx => ctx.RemoveProduct(productId)); public Task<bool> RemoveProductAsync(Guid productId) => TransactionAsync(ctx => ctx.RemoveProduct(productId));
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude)); public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
public List<UserProductMapping>? GetAllUserProductMappings(bool autoInclude = true) => Session(ctx => ctx.UserProductMappings).ToList();
public Task<UserProductMapping?> GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude)); public Task<UserProductMapping?> GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
public List<UserProductMapping> GetUserProductMappingByUserId(Guid userId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingsByUserId(userId, autoInclude).ToList());
public List<UserProductMapping> GetAllUserProductMappings(bool autoInclude = true) => Session(ctx => ctx.UserProductMappings).ToList();
public List<PermissionContextMapping> GetPermissionContextsView(Guid subjectId, Guid contextId) public List<PermissionContextMapping> GetPermissionContextsView(Guid subjectId, Guid contextId)
=> Session(x => x.GetPermissionContextsView(subjectId, contextId).ToList()); => Session(x => x.GetPermissionContextsView(subjectId, contextId).ToList());

View File

@ -239,61 +239,46 @@ namespace TIAMWebApp.Server.Controllers
[HttpPost] [HttpPost]
[Route(APIUrls.GetUserProductMappingsByUserIdRouteName)] [Route(APIUrls.GetUserProductMappingsByUserIdRouteName)]
[SignalR(SignalRTags.GetUserProductMappingsByUserId)] [SignalR(SignalRTags.GetUserProductMappingsByUserId)]
public async Task<string> GetUserProductMappingsByUserId(Guid userId) public Task<string> GetUserProductMappingsByUserId(Guid userId)
{ {
_logger.Info($@"GetUserProductMappingsByUserId called with userId: {userId}"); _logger.Info($@"GetUserProductMappingsByUserId called with userId: {userId}");
var userProductMappings = adminDal.GetAllUserProductMappings(); return Task.FromResult(adminDal.GetUserProductMappingByUserId(userId).OrderBy(x => x.ProductId).ToJson());
var myUserProductMappings = userProductMappings.Where(x => x.UserId == userId).OrderBy(x => x.ProductId).ToList();
//put serviceprovider id and name into a dictionary
return myUserProductMappings.ToJson();
} }
[AllowAnonymous] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route(APIUrls.GetUserProductMappingByIdRouteName)] [Route(APIUrls.GetUserProductMappingByIdRouteName)]
[SignalR(SignalRTags.GetUserProductMappingById)] [SignalR(SignalRTags.GetUserProductMappingById)]
public async Task<string> GetUserProductMappingById(Guid id) public Task<string> GetUserProductMappingById(Guid id)
{ {
_logger.Info($@"GetUserProductMappingsByUserId called with userId: {id}"); _logger.Info($@"GetUserProductMappingsByUserId called with userId: {id}");
var userProductMappings = adminDal.GetAllUserProductMappings(); return Task.FromResult(adminDal.GetUserProductMappingById(id).ToJson());
var myUserProductMappings = userProductMappings.Where(x => x.Id == id).ToList();
//put serviceprovider id and name into a dictionary
return myUserProductMappings.ToJson();
} }
[AllowAnonymous] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route(APIUrls.GetAllUserProductMappingsRouteName)] [Route(APIUrls.GetAllUserProductMappingsRouteName)]
[SignalR(SignalRTags.GetAllUserProductMappings)] [SignalR(SignalRTags.GetAllUserProductMappings)]
public async Task<string> GetAllUserProductMappings() public Task<string> GetAllUserProductMappings()
{ {
_logger.Info($@"GetAllUserProductMappings called"); _logger.Info($@"GetAllUserProductMappings called");
var serviceProviders = adminDal.GetAllUserProductMappings()!.OrderBy(x => x.ProductId); var serviceProviders = adminDal.GetAllUserProductMappings()!.OrderBy(x => x.ProductId);
return Task.FromResult(serviceProviders.ToJson());
//put serviceprovider id and name into a dictionary
return serviceProviders.ToJson();
} }
[AllowAnonymous] [AllowAnonymous]
[HttpGet] [HttpGet]
[Route(APIUrls.GetCarsForUserProductMappingRouteName + "/{userProductMappingId}")] [Route(APIUrls.GetCarsForUserProductMappingRouteName + "/{userProductMappingId}")]
[SignalR(SignalRTags.GetCarsForUserProductMapping)] [SignalR(SignalRTags.GetCarsForUserProductMapping)]
public async Task<List<Car>> GetCarsForUserProductMapping(Guid userProductMappingId) public Task<List<Car>> GetCarsForUserProductMapping(Guid userProductMappingId)
{ {
_logger.Info($@"GetCarsForUserProductMapping called with userProductMappingId: {userProductMappingId}"); _logger.Info($@"GetCarsForUserProductMapping called with userProductMappingId: {userProductMappingId}");
var cars = adminDal.GetCarByUserProductMappingId(userProductMappingId); var cars = adminDal.GetCarByUserProductMappingId(userProductMappingId);
return Task.FromResult(cars);
return cars;
} }
[AllowAnonymous] [AllowAnonymous]
@ -305,7 +290,6 @@ namespace TIAMWebApp.Server.Controllers
_logger.Info($@"GetAllCars called "); _logger.Info($@"GetAllCars called ");
var cars = await adminDal.GetAllCarsAsync(); var cars = await adminDal.GetAllCarsAsync();
return cars; return cars;
} }
@ -347,12 +331,10 @@ namespace TIAMWebApp.Server.Controllers
[Tags("Finished", "Cars")] [Tags("Finished", "Cars")]
[EndpointSummary("Create car")] [EndpointSummary("Create car")]
[SignalR(SignalRTags.CreateCar)] [SignalR(SignalRTags.CreateCar)]
public async Task<Car> CreateCar(Car car) public async Task<Car?> CreateCar(Car car)
{ {
var result = await CarDataChanging(car, TrackingState.Add); var result = await CarDataChanging(car, TrackingState.Add);
if (result) return result ? car : null;
return car;
else return null;
} }
[AllowAnonymous] [AllowAnonymous]
@ -361,12 +343,10 @@ namespace TIAMWebApp.Server.Controllers
[Tags("Finished", "Cars")] [Tags("Finished", "Cars")]
[EndpointSummary("Update car")] [EndpointSummary("Update car")]
[SignalR(SignalRTags.UpdateCar)] [SignalR(SignalRTags.UpdateCar)]
public async Task<Car> UpdateCar(Car car) public async Task<Car?> UpdateCar(Car car)
{ {
var result = await CarDataChanging(car, TrackingState.Update); var result = await CarDataChanging(car, TrackingState.Update);
if (result) return result ? car : null;
return car;
else return null;
} }
@ -384,8 +364,7 @@ namespace TIAMWebApp.Server.Controllers
[Tags("In-Progress", "Product")] [Tags("In-Progress", "Product")]
[SignalR(SignalRTags.AddProduct)] [SignalR(SignalRTags.AddProduct)]
public async Task<IActionResult> AddProduct([FromBody] Product product) public async Task<IActionResult> AddProduct([FromBody] Product product)
{ {
_logger.Info(@"AddProduct called"); _logger.Info(@"AddProduct called");
if (product == null) if (product == null)
@ -394,7 +373,7 @@ namespace TIAMWebApp.Server.Controllers
} }
else else
{ {
var result = adminDal.AddProductAsync(product); var result = await adminDal.AddProductAsync(product);
return Ok(product); return Ok(product);
} }
} }
@ -466,19 +445,12 @@ namespace TIAMWebApp.Server.Controllers
[HttpGet] [HttpGet]
[Route(APIUrls.GetAllProductsRouteName)] [Route(APIUrls.GetAllProductsRouteName)]
[Tags("In-Progress", "Product")] [Tags("In-Progress", "Product")]
public async Task<string> GetAllProducts() public Task<string> GetAllProducts()
{ {
_logger.Info("GetAllProducts called"); _logger.Info("GetAllProducts called");
var products = adminDal.GetProductsJson(); var products = adminDal.GetProductsJson();
if (products != null) return Task.FromResult(products);
{
return products;
}
else
{
return null;
}
} }
[AllowAnonymous] [AllowAnonymous]