diff --git a/src/deskstar-backend/Deskstar/Controllers/ResourcesController.cs b/src/deskstar-backend/Deskstar/Controllers/ResourcesController.cs index fd6a85f0..87e8d3b9 100644 --- a/src/deskstar-backend/Deskstar/Controllers/ResourcesController.cs +++ b/src/deskstar-backend/Deskstar/Controllers/ResourcesController.cs @@ -57,9 +57,9 @@ public IActionResult UpdateDesk(string deskId, UpdateDeskDto dto) Guid? roomId = dto.RoomId == null ? null : new Guid(dto.RoomId); Guid? deskTypeId = dto.DeskTypeId == null ? null : new Guid(dto.DeskTypeId); - _resourceUsecases.UpdateDesk(companyId, deskGuid, dto.DeskName, roomId, deskTypeId); - - return Ok(); + var desk = _resourceUsecases.UpdateDesk(companyId, deskGuid, dto.DeskName, roomId, deskTypeId); + var updatedDesk = _mapper.Map(desk); + return Ok(updatedDesk); } catch (EntityNotFoundException e) { @@ -106,9 +106,9 @@ public IActionResult UpdateDeskType(string deskTypeId, UpdateDeskTypeDto dto) var deskTypeGuid = new Guid(deskTypeId); var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId; - _resourceUsecases.UpdateDeskType(companyId, deskTypeGuid, dto.DeskTypeName); - - return Ok(); + var deskType = _resourceUsecases.UpdateDeskType(companyId, deskTypeGuid, dto.DeskTypeName); + var updatedDeskType = _mapper.Map(deskType); + return Ok(updatedDeskType); } catch (EntityNotFoundException e) { @@ -155,9 +155,9 @@ public IActionResult UpdateBuilding(string buildingId, UpdateBuildingDto dto) var buildingGuid = new Guid(buildingId); var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId; - _resourceUsecases.UpdateBuilding(companyId, buildingGuid, dto.BuildingName, dto.Location); - - return Ok(); + var building = _resourceUsecases.UpdateBuilding(companyId, buildingGuid, dto.BuildingName, dto.Location); + var updatedBuilding = _mapper.Map(building); + return Ok(updatedBuilding); } catch (EntityNotFoundException e) { @@ -205,9 +205,9 @@ public IActionResult UpdateFloor(string floorId, UpdateFloorDto dto) var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId; Guid? buildingGuid = dto.BuildingId == null ? null : new Guid(dto.BuildingId); - _resourceUsecases.UpdateFloor(companyId, floorGuid, dto.FloorName, buildingGuid); - - return Ok(); + var floor = _resourceUsecases.UpdateFloor(companyId, floorGuid, dto.FloorName, buildingGuid); + var updatedFloor = _mapper.Map(floor); + return Ok(updatedFloor); } catch (EntityNotFoundException e) { @@ -255,9 +255,9 @@ public IActionResult UpdateRoom(string roomId, UpdateRoomDto dto) var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId; Guid? floorId = dto.FloorId == null ? null : new Guid(dto.FloorId); - _resourceUsecases.UpdateRoom(companyId, roomGuid, dto.RoomName, floorId); - - return Ok(); + var room = _resourceUsecases.UpdateRoom(companyId, roomGuid, dto.RoomName, floorId); + var updatedRoom = _mapper.Map(room); + return Ok(updatedRoom); } catch (EntityNotFoundException e) { diff --git a/src/deskstar-backend/Deskstar/Models/AutoMapperConfiguration.cs b/src/deskstar-backend/Deskstar/Models/AutoMapperConfiguration.cs index 1c3ca39f..f7c888f0 100644 --- a/src/deskstar-backend/Deskstar/Models/AutoMapperConfiguration.cs +++ b/src/deskstar-backend/Deskstar/Models/AutoMapperConfiguration.cs @@ -2,28 +2,33 @@ namespace Deskstar.Models { - public interface IAutoMapperConfiguration - { - public MapperConfiguration GetConfiguration(); - } + public interface IAutoMapperConfiguration + { + public MapperConfiguration GetConfiguration(); + } - public class AutoMapperConfiguration : IAutoMapperConfiguration + public class AutoMapperConfiguration : IAutoMapperConfiguration + { + public MapperConfiguration GetConfiguration() { - public MapperConfiguration GetConfiguration() - { - var config = new MapperConfiguration(cfg => - { - UserProfileDto.CreateMappings(cfg); - UserProfileCompanyDto.createMappings(cfg); - DeskTypeDto.createMappings(cfg); - ExtendedBooking.createMappings(cfg); - CreateBuildingResponseObject.createMappings(cfg); - CreateDeskResponseObject.createMappings(cfg); - CreateDeskTypeResponseObject.createMappings(cfg); - CreateFloorResponseObject.createMappings(cfg); - CreateRoomResponseObject.createMappings(cfg); - }); - return config; - } + var config = new MapperConfiguration(cfg => + { + UserProfileDto.CreateMappings(cfg); + UserProfileCompanyDto.createMappings(cfg); + DeskTypeDto.createMappings(cfg); + ExtendedBooking.createMappings(cfg); + CreateBuildingResponseObject.createMappings(cfg); + CreateDeskResponseObject.createMappings(cfg); + CreateDeskTypeResponseObject.createMappings(cfg); + CreateFloorResponseObject.createMappings(cfg); + CreateRoomResponseObject.createMappings(cfg); + UpdateBuildingResponseObject.createMappings(cfg); + UpdateDeskResponseObject.createMappings(cfg); + UpdateDeskTypeResponseObject.createMappings(cfg); + UpdateFloorResponseObject.createMappings(cfg); + UpdateRoomResponseObject.createMappings(cfg); + }); + return config; } + } } \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/CreateResources/CreateBuildingResponseObject.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateBuildingResponseObject.cs index 35be874b..6f2350e3 100644 --- a/src/deskstar-backend/Deskstar/Models/CreateResources/CreateBuildingResponseObject.cs +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateBuildingResponseObject.cs @@ -1,17 +1,21 @@ +using System.ComponentModel.DataAnnotations; using AutoMapper; namespace Deskstar.Models; public class CreateBuildingResponseObject { - public CreateBuildingResponseObject() { } + public CreateBuildingResponseObject() { } - public static void createMappings(IMapperConfigurationExpression cfg) - { - cfg.CreateMap(); - } + public static void createMappings(IMapperConfigurationExpression cfg) + { + cfg.CreateMap(); + } - public Guid BuildingId { get; set; } - public string BuildingName { get; set; } = null!; - public string Location { get; set; } = null!; + [Required] + public Guid BuildingId { get; set; } + [Required] + public string BuildingName { get; set; } = null!; + [Required] + public string Location { get; set; } = null!; } diff --git a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateBuildingDto.cs b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateBuildingDto.cs index d4fc96ed..b6579ec6 100644 --- a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateBuildingDto.cs +++ b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateBuildingDto.cs @@ -1,6 +1,6 @@ namespace Deskstar.Models; public class UpdateBuildingDto{ - public string? BuildingName; - public string? Location; + public string? BuildingName {get;set;} + public string? Location {get;set;} } diff --git a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateBuildingResponseObject.cs b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateBuildingResponseObject.cs new file mode 100644 index 00000000..904e8765 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateBuildingResponseObject.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; +using AutoMapper; + +namespace Deskstar.Models; + +public class UpdateBuildingResponseObject +{ + public static void createMappings(IMapperConfigurationExpression cfg) + { + cfg.CreateMap(); + } + [Required] + public Guid BuildingId { get; set; } + [Required] + public string BuildingName { get; set; } = null!; + [Required] + public string Location { get; set; } = null!; +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskDto.cs b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskDto.cs index 8716541c..ef5b1102 100644 --- a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskDto.cs +++ b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskDto.cs @@ -2,7 +2,7 @@ namespace Deskstar.Models; public class UpdateDeskDto { - public string? DeskName; - public string? RoomId; - public string? DeskTypeId; + public string? DeskName {get;set;} + public string? RoomId {get;set;} + public string? DeskTypeId {get;set;} } \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskResponseObject.cs b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskResponseObject.cs new file mode 100644 index 00000000..ce47cebd --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskResponseObject.cs @@ -0,0 +1,43 @@ +using System.ComponentModel.DataAnnotations; +using AutoMapper; + +namespace Deskstar.Models; + +public class UpdateDeskResponseObject +{ + public static void createMappings(IMapperConfigurationExpression cfg) + { + cfg.CreateMap() + .ForMember(dest => dest.BuildingId, act => act.MapFrom(src => src.Room.Floor.Building.BuildingId)) + .ForMember(dest => dest.BuildingName, act => act.MapFrom(src => src.Room.Floor.Building.BuildingName)) + .ForMember(dest => dest.Location, act => act.MapFrom(src => src.Room.Floor.Building.Location)) + .ForMember(dest => dest.FloorId, act => act.MapFrom(src => src.Room.Floor.FloorId)) + .ForMember(dest => dest.FloorName, act => act.MapFrom(src => src.Room.Floor.FloorName)) + .ForMember(dest => dest.Location, act => act.MapFrom(src => src.Room.Floor.Building.Location)) + .ForMember(dest => dest.RoomId, act => act.MapFrom(src => src.Room.RoomId)) + .ForMember(dest => dest.RoomName, act => act.MapFrom(src => src.Room.RoomName)) + .ForMember(dest => dest.DeskTypeName, act => act.MapFrom(src => src.DeskType.DeskTypeName)); + } + [Required] + public Guid DeskId { get; set; } + [Required] + public string DeskName { get; set; } = null!; + [Required] + public Guid DeskTypeId { get; set; } + [Required] + public string DeskTypeName { get; set; } = null!; + [Required] + public Guid RoomId { get; set; } + [Required] + public string RoomName { get; set; } = null!; + [Required] + public Guid FloorId { get; set; } + [Required] + public string FloorName { get; set; } = null!; + [Required] + public Guid BuildingId { get; set; } + [Required] + public string BuildingName { get; set; } = null!; + [Required] + public string Location { get; set; } = null!; +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskTypeDto.cs b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskTypeDto.cs index 22ba16ab..c90c595b 100644 --- a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskTypeDto.cs +++ b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskTypeDto.cs @@ -1,5 +1,5 @@ namespace Deskstar.Models; public class UpdateDeskTypeDto{ - public string? DeskTypeName; + public string? DeskTypeName {get;set;} } \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskTypeResponseObject.cs b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskTypeResponseObject.cs new file mode 100644 index 00000000..30af5024 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateDeskTypeResponseObject.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; +using AutoMapper; + +namespace Deskstar.Models; + +public class UpdateDeskTypeResponseObject +{ + public static void createMappings(IMapperConfigurationExpression cfg) + { + cfg.CreateMap(); + } + [Required] + public Guid DeskTypeId { get; set; } + [Required] + public string DeskTypeName { get; set; } = null!; + +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateFloorDto.cs b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateFloorDto.cs index a687e5a4..c022b1f0 100644 --- a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateFloorDto.cs +++ b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateFloorDto.cs @@ -1,6 +1,6 @@ namespace Deskstar.Models; public class UpdateFloorDto{ - public string? FloorName; - public string? BuildingId; + public string? FloorName {get;set;} + public string? BuildingId {get;set;} } \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateFloorResponseObject.cs b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateFloorResponseObject.cs new file mode 100644 index 00000000..e4aec858 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateFloorResponseObject.cs @@ -0,0 +1,25 @@ +using System.ComponentModel.DataAnnotations; +using AutoMapper; + +namespace Deskstar.Models; + +public class UpdateFloorResponseObject +{ + public static void createMappings(IMapperConfigurationExpression cfg) + { + cfg.CreateMap() + .ForMember(dest => dest.BuildingName, act => act.MapFrom(src => src.Building.BuildingName)) + .ForMember(dest => dest.Location, act => act.MapFrom(src => src.Building.Location)); + } + + [Required] + public Guid FloorId { get; set; } + [Required] + public string FloorName { get; set; } = null!; + [Required] + public Guid BuildingId { get; set; } + [Required] + public string BuildingName { get; set; } = null!; + [Required] + public string Location { get; set; } = null!; +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateRoomDto.cs b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateRoomDto.cs index 86ad032e..016e84fd 100644 --- a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateRoomDto.cs +++ b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateRoomDto.cs @@ -2,6 +2,6 @@ namespace Deskstar.Models; public class UpdateRoomDto { - public string? FloorId; - public string? RoomName; + public string? FloorId {get;set;} + public string? RoomName {get;set;} } \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateRoomResponseObject.cs b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateRoomResponseObject.cs new file mode 100644 index 00000000..6c764dad --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/UpdateResources/UpdateRoomResponseObject.cs @@ -0,0 +1,30 @@ +using System.ComponentModel.DataAnnotations; +using AutoMapper; + +namespace Deskstar.Models; + +public class UpdateRoomResponseObject +{ + + public static void createMappings(IMapperConfigurationExpression cfg) + { + cfg.CreateMap() + .ForMember(dest => dest.BuildingName, act => act.MapFrom(src => src.Floor.Building.BuildingName)) + .ForMember(dest => dest.BuildingId, act => act.MapFrom(src => src.Floor.Building.BuildingId)) + .ForMember(dest => dest.FloorName, act => act.MapFrom(src => src.Floor.FloorName)) + .ForMember(dest => dest.Location, act => act.MapFrom(src => src.Floor.Building.Location)); + } + public Guid RoomId { get; set; } + [Required] + public string RoomName { get; set; } = null!; + [Required] + public Guid FloorId { get; set; } + [Required] + public string FloorName { get; set; } = null!; + [Required] + public Guid BuildingId { get; set; } + [Required] + public string BuildingName { get; set; } = null!; + [Required] + public string Location { get; set; } = null!; +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Usecases/ResourceUsecases.cs b/src/deskstar-backend/Deskstar/Usecases/ResourceUsecases.cs index f980e235..b0cac09e 100644 --- a/src/deskstar-backend/Deskstar/Usecases/ResourceUsecases.cs +++ b/src/deskstar-backend/Deskstar/Usecases/ResourceUsecases.cs @@ -2,7 +2,7 @@ using Deskstar.DataAccess; using Deskstar.Entities; using Deskstar.Models; - +using Microsoft.EntityFrameworkCore; namespace Deskstar.Usecases; public interface IResourceUsecases @@ -20,11 +20,11 @@ public interface IResourceUsecases public Floor CreateFloor(string floorName, Guid buildingId); public Building CreateBuilding(string buildingName, string location, Guid companyId); - public Guid UpdateBuilding(Guid companyId, Guid buildingGuid, string? buildingName, string? location); - public Guid UpdateFloor(Guid companyId, Guid floorId, string? floorName, Guid? buildingId); - public Guid UpdateRoom(Guid companyId, Guid roomId, string? roomName, Guid? floorId); - public Guid UpdateDesk(Guid companyId, Guid deskId, string? deskName, Guid? roomId, Guid? deskTypeId); - public Guid UpdateDeskType(Guid companyId, Guid deskTypeId, string? deskTypeName); + public Building UpdateBuilding(Guid companyId, Guid buildingGuid, string? buildingName, string? location); + public Floor UpdateFloor(Guid companyId, Guid floorId, string? floorName, Guid? buildingId); + public Room UpdateRoom(Guid companyId, Guid roomId, string? roomName, Guid? floorId); + public Desk UpdateDesk(Guid companyId, Guid deskId, string? deskName, Guid? roomId, Guid? deskTypeId); + public DeskType UpdateDeskType(Guid companyId, Guid deskTypeId, string? deskTypeName); } public class ResourceUsecases : IResourceUsecases @@ -41,14 +41,14 @@ public ResourceUsecases(ILogger logger, DataContext context, I _userUsecases = userUsecases; } - public Guid UpdateBuilding(Guid companyId, Guid buildingId, string? buildingName, string? location) + public Building UpdateBuilding(Guid companyId, Guid buildingId, string? buildingName, string? location) { - var buildingExists = _context.Buildings.SingleOrDefault(b => b.BuildingId == buildingId); + var buildingExists = _context.Buildings.Include(b => b.Company).ThenInclude(c => c.Buildings).SingleOrDefault(b => b.BuildingId == buildingId); if (buildingExists == null) throw new EntityNotFoundException($"There is no building with id '{buildingId}'"); if (buildingExists.CompanyId != companyId) - throw new InsufficientPermissionException($"'{companyId}' has no access to administrate building '{buildingId}'"); + throw new InsufficientPermissionException($"Your company has no access to administrate building '{buildingExists.BuildingName}'"); //change location if (location != null) @@ -65,7 +65,7 @@ public Guid UpdateBuilding(Guid companyId, Guid buildingId, string? buildingName throw new ArgumentInvalidException($"Building name must not be empty"); var buildingNameIsUnique = buildingExists.Company.Buildings.Select(b => b.BuildingName).All(name => name != buildingName); if (!buildingNameIsUnique) - throw new ArgumentInvalidException($"There is already a building named '{buildingName}' in company '{buildingExists.CompanyId}'"); + throw new ArgumentInvalidException($"There is already a building named '{buildingName}' in your company"); buildingExists.BuildingName = buildingName; } @@ -73,17 +73,17 @@ public Guid UpdateBuilding(Guid companyId, Guid buildingId, string? buildingName _context.Buildings.Update(buildingExists); _context.SaveChanges(); - return buildingId; + return buildingExists; } - public Guid UpdateFloor(Guid companyId, Guid floorId, string? floorName, Guid? buildingId) + public Floor UpdateFloor(Guid companyId, Guid floorId, string? floorName, Guid? buildingId) { - var floorExists = _context.Floors.SingleOrDefault(f => f.FloorId == floorId); + var floorExists = _context.Floors.Include(f => f.Building).SingleOrDefault(f => f.FloorId == floorId); if (floorExists == null) throw new EntityNotFoundException($"There is no floor with id '{floorId}'"); if (floorExists.Building.CompanyId != companyId) - throw new InsufficientPermissionException($"'{companyId}' has no access to administrate floor '{floorId}'"); + throw new InsufficientPermissionException($"Your company has no access to administrate floor '{floorExists.FloorName}'"); //change building if (buildingId != null) @@ -92,11 +92,11 @@ public Guid UpdateFloor(Guid companyId, Guid floorId, string? floorName, Guid? b if (buildingExists == null) throw new EntityNotFoundException($"Building does not exist with id '{(Guid)buildingId}'"); if (buildingExists.CompanyId != companyId) - throw new InsufficientPermissionException($"'{companyId}' has no access to move a floor to building '{(Guid)buildingId}'"); + throw new InsufficientPermissionException($"Your company has no access to move a floor to building '{buildingExists.BuildingName}'"); var floorNameToBeChecked = floorName != null ? floorName : floorExists.FloorName; var floorNameExists = _context.Floors.SingleOrDefault(f => f.BuildingId == buildingId && f.FloorName == floorNameToBeChecked); if (floorNameExists != null) - throw new ArgumentInvalidException($"You cant move floor '{floorId}' to building '{buildingId}'. In building '{buildingId}' already exists a floor called '{floorNameToBeChecked}'"); + throw new ArgumentInvalidException($"You cant move floor '{floorExists.FloorName}' to building '{buildingExists.BuildingName}'. In building '{buildingExists.BuildingName}' already exists a floor called '{floorNameToBeChecked}'"); floorExists.BuildingId = (Guid)buildingId; } @@ -110,7 +110,7 @@ public Guid UpdateFloor(Guid companyId, Guid floorId, string? floorName, Guid? b { var floorNameIsUnique = floorExists.Building.Floors.Select(f => f.FloorName).All(name => name != floorName); if (!floorNameIsUnique) - throw new ArgumentInvalidException($"There is already a floor named '{floorName}' in building '{floorExists.BuildingId}'"); + throw new ArgumentInvalidException($"There is already a floor named '{floorName}' in building '{floorExists.Building.BuildingName}'"); } floorExists.FloorName = floorName; @@ -119,30 +119,30 @@ public Guid UpdateFloor(Guid companyId, Guid floorId, string? floorName, Guid? b _context.Floors.Update(floorExists); _context.SaveChanges(); - return floorId; + return floorExists; } - public Guid UpdateRoom(Guid companyId, Guid roomId, string? roomName, Guid? floorId) + public Room UpdateRoom(Guid companyId, Guid roomId, string? roomName, Guid? floorId) { - var roomExists = _context.Rooms.SingleOrDefault(r => r.RoomId == roomId); + var roomExists = _context.Rooms.Include(r => r.Floor).ThenInclude(f => f.Building).SingleOrDefault(r => r.RoomId == roomId); if (roomExists == null) throw new EntityNotFoundException($"There is no room with id '{roomId}'"); if (roomExists.Floor.Building.CompanyId != companyId) - throw new InsufficientPermissionException($"'{companyId}' has no access to administrate floor '{roomExists.FloorId}'"); + throw new InsufficientPermissionException($"Your company has no access to administrate room '{roomExists.RoomName}'"); //change floor if (floorId != null) { - var floorExists = _context.Floors.SingleOrDefault(f => f.FloorId == (Guid)floorId); + var floorExists = _context.Floors.Include(f => f.Building).SingleOrDefault(f => f.FloorId == (Guid)floorId); if (floorExists == null) throw new EntityNotFoundException($"Floor does not exist with id '{(Guid)floorId}'"); if (floorExists.Building.CompanyId != companyId) - throw new InsufficientPermissionException($"'{companyId}' has no access to move a room to floor '{(Guid)floorId}'"); + throw new InsufficientPermissionException($"Your company has no access to move a room to floor '{floorExists.FloorName}'"); var roomNameToBeChecked = roomName != null ? roomName : roomExists.RoomName; var roomNameExists = _context.Rooms.SingleOrDefault(r => r.FloorId == floorId && r.RoomName == roomNameToBeChecked); if (roomNameExists != null) - throw new ArgumentInvalidException($"You cant move room '{roomId}' to floor '{floorId}'. In floor '{floorId}' already exists a room called '{roomNameToBeChecked}'"); + throw new ArgumentInvalidException($"You cant move room '{roomExists.RoomName}' to floor '{floorExists.FloorName}'. In floor '{floorExists.FloorName}' already exists a room called '{roomNameToBeChecked}'"); roomExists.FloorId = (Guid)floorId; } @@ -156,7 +156,7 @@ public Guid UpdateRoom(Guid companyId, Guid roomId, string? roomName, Guid? floo { var roomNameIsUnique = roomExists.Floor.Rooms.Select(r => r.RoomName).All(name => name != roomName); if (!roomNameIsUnique) - throw new ArgumentInvalidException($"There is already a room named '{roomName}' in floor '{roomExists.FloorId}'"); + throw new ArgumentInvalidException($"There is already a room named '{roomName}' in floor '{roomExists.Floor.FloorName}'"); } roomExists.RoomName = roomName; @@ -165,30 +165,30 @@ public Guid UpdateRoom(Guid companyId, Guid roomId, string? roomName, Guid? floo _context.Rooms.Update(roomExists); _context.SaveChanges(); - return roomId; + return roomExists; } - public Guid UpdateDesk(Guid companyId, Guid deskId, string? deskName, Guid? roomId, Guid? deskTypeId) + public Desk UpdateDesk(Guid companyId, Guid deskId, string? deskName, Guid? roomId, Guid? deskTypeId) { - var deskExists = _context.Desks.SingleOrDefault(d => d.DeskId == deskId); + var deskExists = _context.Desks.Include(d => d.DeskType).Include(d => d.Room).ThenInclude(r => r.Floor).ThenInclude(f => f.Building).SingleOrDefault(d => d.DeskId == deskId); if (deskExists == null) throw new EntityNotFoundException($"There is no desk with id '{deskId}'"); if (deskExists.Room.Floor.Building.CompanyId != companyId) - throw new InsufficientPermissionException($"'{companyId}' has no access to administrate desk '{deskId}'"); + throw new InsufficientPermissionException($"Your company has no access to administrate desk '{deskExists.DeskName}'"); //change room if (roomId != null) { - var roomExists = _context.Rooms.SingleOrDefault(r => r.RoomId == (Guid)roomId); + var roomExists = _context.Rooms.Include(r => r.Floor).ThenInclude(f => f.Building).SingleOrDefault(r => r.RoomId == (Guid)roomId); if (roomExists == null) throw new EntityNotFoundException($"Room does not exist with id '{(Guid)roomId}'"); if (roomExists.Floor.Building.CompanyId != companyId) - throw new InsufficientPermissionException($"'{companyId}' has no access to add a desk to room '{(Guid)roomId}'"); + throw new InsufficientPermissionException($"Your company has no access to add a desk to room '{roomExists.RoomName}'"); var deskNameToBeChecked = deskName != null ? deskName : deskExists.DeskName; var deskNameExists = _context.Desks.SingleOrDefault(d => d.RoomId == roomId && d.DeskName == deskNameToBeChecked); if (deskNameExists != null) - throw new ArgumentInvalidException($"You cant move desk '{deskId}' to room '{roomId}'. In room '{roomId}' already exists a desk called '{deskNameToBeChecked}'"); + throw new ArgumentInvalidException($"You cant move desk '{deskExists.DeskName}' to room '{roomExists.RoomName}'. In room '{roomExists.RoomName}' already exists a desk called '{deskNameToBeChecked}'"); deskExists.RoomId = (Guid)roomId; } @@ -202,7 +202,7 @@ public Guid UpdateDesk(Guid companyId, Guid deskId, string? deskName, Guid? room { var deskNameIsUnique = deskExists.Room.Desks.Select(d => d.DeskName).All(name => name != deskName); if (!deskNameIsUnique) - throw new ArgumentInvalidException($"There is already a desk named '{deskName}' in room '{deskExists.RoomId}'"); + throw new ArgumentInvalidException($"There is already a desk named '{deskName}' in room '{deskExists.Room.RoomName}'"); } deskExists.DeskName = deskName; @@ -215,7 +215,7 @@ public Guid UpdateDesk(Guid companyId, Guid deskId, string? deskName, Guid? room if (deskTypeExists == null) throw new EntityNotFoundException($"DeskType does not exist with id '{(Guid)deskTypeId}'"); if (deskTypeExists.CompanyId != companyId) - throw new InsufficientPermissionException($"'{companyId}' has no access to desk type '{(Guid)deskTypeId}'"); + throw new InsufficientPermissionException($"Your company has no access to desk type '{deskTypeExists.DeskTypeName}'"); deskExists.DeskTypeId = (Guid)deskTypeId; } @@ -223,16 +223,16 @@ public Guid UpdateDesk(Guid companyId, Guid deskId, string? deskName, Guid? room _context.Desks.Update(deskExists); _context.SaveChanges(); - return deskId; + return deskExists; } - public Guid UpdateDeskType(Guid companyId, Guid deskTypeId, string? deskTypeName) + public DeskType UpdateDeskType(Guid companyId, Guid deskTypeId, string? deskTypeName) { var deskTypeExists = _context.DeskTypes.SingleOrDefault(dt => dt.DeskTypeId == deskTypeId); if (deskTypeExists == null) throw new EntityNotFoundException($"There is no desk type with id '{deskTypeId}'"); if (deskTypeExists.CompanyId != companyId) - throw new InsufficientPermissionException($"'{companyId}' has no access to administrate desk type '{deskTypeId}'"); + throw new InsufficientPermissionException($"Your company has no access to administrate desk type '{deskTypeExists.DeskTypeName}'"); //change deskTypeName if (deskTypeName != null) @@ -249,7 +249,7 @@ public Guid UpdateDeskType(Guid companyId, Guid deskTypeId, string? deskTypeName _context.DeskTypes.Update(deskTypeExists); _context.SaveChanges(); - return deskTypeId; + return deskTypeExists; } public List GetBuildings(Guid userId) diff --git a/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecaseTests.cs b/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecaseTests.cs index 9f93ad43..b6f6b892 100644 --- a/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecaseTests.cs +++ b/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecaseTests.cs @@ -30,7 +30,7 @@ public void UpdateBuilding_WhenBuildingIdDoesNotExist_ShouldThrowEntityNotFoundE // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateBuilding(companyId, buildingId, "Building Name", "Location")); Assert.NotNull(ex); - Assert.That($"There is no building with id '{buildingId}'" == ex.Message); + Assert.That(ex.Message, Is.EqualTo($"There is no building with id '{buildingId}'")); // cleanup context.Database.EnsureDeleted(); @@ -61,7 +61,7 @@ public void UpdateBuilding_WhenBuildingNameDoesAlreadyExist_ShouldThrowArgumentI // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateBuilding(companyId, buildingId, buildingName, null)); Assert.NotNull(ex); - Assert.AreEqual($"There is already a building named '{buildingName}' in company '{companyId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"There is already a building named '{buildingName}' in your company")); // cleanup context.Database.EnsureDeleted(); @@ -71,9 +71,13 @@ public void UpdateBuilding_WhenCompanyIdDoesNotMatchBuilding_ShouldThrowInsuffic { // setup var companyId = Guid.NewGuid(); + var company2Id = Guid.NewGuid(); + var company2 = new Company { CompanyId = company2Id, CompanyName = "testcompany2" }; var buildingId = Guid.NewGuid(); var context = new DataContext(); - var building = new Building { BuildingId = buildingId, CompanyId = Guid.NewGuid(), BuildingName = "testname", Location = "testlocation" }; + var buildingName = "testname"; + var building = new Building { BuildingId = buildingId, CompanyId = company2Id, BuildingName = buildingName, Location = "testlocation" }; + context.Companies.Add(company2); context.Buildings.Add(building); context.SaveChanges(); @@ -86,7 +90,7 @@ public void UpdateBuilding_WhenCompanyIdDoesNotMatchBuilding_ShouldThrowInsuffic // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateBuilding(companyId, buildingId, "Building Name", "Location")); Assert.NotNull(ex); - Assert.That($"'{companyId}' has no access to administrate building '{buildingId}'" == ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Your company has no access to administrate building '{buildingName}'")); // cleanup context.Database.EnsureDeleted(); @@ -116,16 +120,12 @@ public void UpdateBuilding_WhenAllInputIsValid_ShouldUpdateBuilding() var updatedBuildingName = "New Building Name"; var updatedLocation = "New York"; // act - var result = resourceUsecases.UpdateBuilding(companyId, buildingId, updatedBuildingName, updatedLocation); + var updatedBuilding = resourceUsecases.UpdateBuilding(companyId, buildingId, updatedBuildingName, updatedLocation); // assert - Assert.IsNotNull(result); - Assert.AreEqual(buildingId, result); - - var updatedBuilding = context.Buildings.Find(buildingId); Assert.IsNotNull(updatedBuilding); - Assert.AreEqual(updatedBuildingName, updatedBuilding.BuildingName); - Assert.AreEqual(updatedLocation, updatedBuilding.Location); + Assert.That(updatedBuilding.BuildingName, Is.EqualTo(updatedBuildingName)); + Assert.That(updatedBuilding.Location, Is.EqualTo(updatedLocation)); // cleanup context.Database.EnsureDeleted(); @@ -135,9 +135,11 @@ public void UpdateBuilding_WhenOnlyLocationIsProvided_ShouldUpdateBuildingLocati { // setup var companyId = Guid.NewGuid(); + var company = new Company { CompanyId = companyId, CompanyName = "testcompany" }; var buildingId = Guid.NewGuid(); var context = new DataContext(); var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; + context.Companies.Add(company); context.Buildings.Add(building); context.SaveChanges(); @@ -149,13 +151,12 @@ public void UpdateBuilding_WhenOnlyLocationIsProvided_ShouldUpdateBuildingLocati var newLocation = "newlocation"; // act - var buildingIdReturned = resourceUsecases.UpdateBuilding(companyId, buildingId, null, newLocation); + var updatedBuilding = resourceUsecases.UpdateBuilding(companyId, buildingId, null, newLocation); // assert - var updatedBuilding = context.Buildings.SingleOrDefault(b => b.BuildingId == buildingId); Assert.NotNull(updatedBuilding); - Assert.That(updatedBuilding.Location == newLocation); - Assert.That(buildingIdReturned == buildingId); + Assert.That(updatedBuilding.Location, Is.EqualTo(newLocation)); + Assert.That(updatedBuilding.BuildingId, Is.EqualTo(buildingId)); // cleanup context.Database.EnsureDeleted(); @@ -185,14 +186,13 @@ public void UpdateBuilding_WhenOnlyBuildingNameIsProvided_ShouldUpdateBuildingNa var updatedBuildingName = "updatedBuildingName"; // act - var returnedBuildingId = resourceUsecases.UpdateBuilding(companyId, buildingId, updatedBuildingName, null); + var updatedBuilding = resourceUsecases.UpdateBuilding(companyId, buildingId, updatedBuildingName, null); // assert - Assert.AreEqual(buildingId, returnedBuildingId); - var updatedBuilding = context.Buildings.SingleOrDefault(b => b.BuildingId == buildingId); + Assert.That(updatedBuilding.BuildingId, Is.EqualTo(buildingId)); Assert.NotNull(updatedBuilding); - Assert.AreEqual(updatedBuildingName, updatedBuilding.BuildingName); - Assert.AreEqual(location, updatedBuilding.Location); + Assert.That(updatedBuilding.BuildingName, Is.EqualTo(updatedBuildingName)); + Assert.That(updatedBuilding.Location, Is.EqualTo(location)); // cleanup context.Database.EnsureDeleted(); @@ -202,9 +202,11 @@ public void UpdateBuilding_WhenNeitherLocationNorBuildingNameIsProvided_ShouldRe { // setup var companyId = Guid.NewGuid(); + var company = new Company { CompanyId = companyId, CompanyName = "testcompany" }; var buildingId = Guid.NewGuid(); var context = new DataContext(); var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; + context.Companies.Add(company); context.Buildings.Add(building); context.SaveChanges(); @@ -215,10 +217,10 @@ public void UpdateBuilding_WhenNeitherLocationNorBuildingNameIsProvided_ShouldRe var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); // act - var buildingIdReturned = resourceUsecases.UpdateBuilding(companyId, buildingId, null, null); + var updatedBuilding = resourceUsecases.UpdateBuilding(companyId, buildingId, null, null); // assert - Assert.AreEqual(buildingId, buildingIdReturned); + Assert.That(updatedBuilding.BuildingId, Is.EqualTo(buildingId)); // cleanup context.Database.EnsureDeleted(); @@ -228,9 +230,11 @@ public void UpdateBuilding_WhenLocationIsEmpty_ShouldThrowArgumentInvalidExcepti { // setup var companyId = Guid.NewGuid(); + var company = new Company { CompanyId = companyId, CompanyName = "testcompany" }; var buildingId = Guid.NewGuid(); var context = new DataContext(); var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; + context.Companies.Add(company); context.Buildings.Add(building); context.SaveChanges(); @@ -243,7 +247,7 @@ public void UpdateBuilding_WhenLocationIsEmpty_ShouldThrowArgumentInvalidExcepti // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateBuilding(companyId, buildingId, "Building Name", "")); Assert.NotNull(ex); - Assert.That($"Location must not be empty" == ex.Message); + Assert.That(ex.Message, Is.EqualTo("Location must not be empty")); // cleanup context.Database.EnsureDeleted(); @@ -253,9 +257,11 @@ public void UpdateBuilding_WhenBuildingNameIsEmpty_ShouldThrowArgumentInvalidExc { // setup var companyId = Guid.NewGuid(); + var company = new Company { CompanyId = companyId, CompanyName = "testcompany" }; var buildingId = Guid.NewGuid(); var context = new DataContext(); var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; + context.Companies.Add(company); context.Buildings.Add(building); context.SaveChanges(); @@ -268,7 +274,7 @@ public void UpdateBuilding_WhenBuildingNameIsEmpty_ShouldThrowArgumentInvalidExc // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateBuilding(companyId, buildingId, "", "New York")); Assert.NotNull(ex); - Assert.That($"Building name must not be empty" == ex.Message); + Assert.That(ex.Message, Is.EqualTo("Building name must not be empty")); // cleanup context.Database.EnsureDeleted(); @@ -387,7 +393,8 @@ public void UpdateFloor_WhenCompanyIdDoesNotMatchFloor_ShouldThrowInsufficientPe var context = new DataContext(); var building = new Building { BuildingId = buildingId, CompanyId = Guid.NewGuid(), BuildingName = "testname", Location = "testlocation" }; context.Buildings.Add(building); - var floor = new Floor { FloorId = floorId, FloorName = "testfloor", BuildingId = buildingId, Building = building }; + var floorName = "testfloor"; + var floor = new Floor { FloorId = floorId, FloorName = floorName, BuildingId = buildingId, Building = building }; context.Floors.Add(floor); context.SaveChanges(); @@ -400,7 +407,7 @@ public void UpdateFloor_WhenCompanyIdDoesNotMatchFloor_ShouldThrowInsufficientPe // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateFloor(companyId, floorId, "Floor Name", null)); Assert.NotNull(ex); - Assert.That($"'{companyId}' has no access to administrate floor '{floorId}'" == ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Your company has no access to administrate floor '{floorName}'")); // cleanup context.Database.EnsureDeleted(); @@ -474,7 +481,8 @@ public void UpdateFloor_WhenCompanyIdDoesNotMatchBuilding_ShouldThrowInsufficien var floorId = Guid.NewGuid(); var context = new DataContext(); var building = new Building { BuildingId = buildingId, CompanyId = Guid.NewGuid(), BuildingName = "testname", Location = "testlocation" }; - var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = "testname" }; + var floorName = "testname"; + var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = floorName }; context.Buildings.Add(building); context.Floors.Add(floor); context.SaveChanges(); @@ -488,7 +496,7 @@ public void UpdateFloor_WhenCompanyIdDoesNotMatchBuilding_ShouldThrowInsufficien // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateFloor(companyId, floorId, "new name", null)); Assert.NotNull(ex); - Assert.That($"'{companyId}' has no access to administrate floor '{floorId}'" == ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Your company has no access to administrate floor '{floorName}'")); // cleanup context.Database.EnsureDeleted(); @@ -511,7 +519,8 @@ public void UpdateFloor_WhenUpdatedBuildingBelongsToDifferentCompany_ShouldThrow var anotherCompanyId = Guid.NewGuid(); var building2Id = Guid.NewGuid(); - var building2 = new Building { BuildingId = building2Id, CompanyId = anotherCompanyId, BuildingName = "testbuilding2", Location = "testlocation" }; + var building2Name = "testbuilding2"; + var building2 = new Building { BuildingId = building2Id, CompanyId = anotherCompanyId, BuildingName = building2Name, Location = "testlocation" }; context.Buildings.Add(building2); context.SaveChanges(); @@ -524,7 +533,7 @@ public void UpdateFloor_WhenUpdatedBuildingBelongsToDifferentCompany_ShouldThrow // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateFloor(companyId, floorId, null, building2Id)); Assert.NotNull(ex); - Assert.AreEqual($"'{companyId}' has no access to move a floor to building '{building2Id}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Your company has no access to move a floor to building '{building2Name}'")); // cleanup context.Database.EnsureDeleted(); @@ -540,7 +549,8 @@ public void UpdateFloor_WhenUpdatedBuildingNameAlreadyExists_ShouldThrowArgument var floorId = Guid.NewGuid(); var buildingId = Guid.NewGuid(); var floorName = "testfloor"; - var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; + var buildingName = "testname"; + var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = buildingName, Location = "testlocation" }; var floor = new Floor { FloorId = floorId, FloorName = floorName, BuildingId = buildingId, Building = building }; context.Buildings.Add(building); context.Floors.Add(floor); @@ -560,7 +570,7 @@ public void UpdateFloor_WhenUpdatedBuildingNameAlreadyExists_ShouldThrowArgument // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateFloor(companyId, floorId, floorName, null)); Assert.NotNull(ex); - Assert.AreEqual($"There is already a floor named '{floorName}' in building '{buildingId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"There is already a floor named '{floorName}' in building '{buildingName}'")); // cleanup context.Database.EnsureDeleted(); @@ -591,14 +601,13 @@ public void UpdateFloor_WhenAllInputIsValid_ShouldUpdateFloorAndReturnFloorId() var newFloorName = "new name"; // act - var returnedFloorId = resourceUsecases.UpdateFloor(companyId, floorId, newFloorName, building2Id); - var updatedFloor = context.Floors.SingleOrDefault(f => f.FloorId == floorId); + var updatedFloor = resourceUsecases.UpdateFloor(companyId, floorId, newFloorName, building2Id); // assert - Assert.That(floorId == returnedFloorId); + Assert.That(updatedFloor.FloorId, Is.EqualTo(floorId)); Assert.NotNull(updatedFloor); - Assert.That(newFloorName == updatedFloor.FloorName); - Assert.That(building2Id == updatedFloor.BuildingId); + Assert.That(updatedFloor.FloorName, Is.EqualTo(newFloorName)); + Assert.That(updatedFloor.BuildingId, Is.EqualTo(building2Id)); // cleanup context.Database.EnsureDeleted(); @@ -624,8 +633,8 @@ public void UpdateFloor_WhenFloorNameAlreadyExistsInUpdatedBuilding_ShouldThrowA var company2Id = Guid.NewGuid(); var building2Id = Guid.NewGuid(); var floor2Id = Guid.NewGuid(); - - var building2 = new Building { BuildingId = building2Id, CompanyId = companyId, BuildingName = "testbuilding2", Location = "testlocation" }; + var building2Name = "testbuilding2"; + var building2 = new Building { BuildingId = building2Id, CompanyId = companyId, BuildingName = building2Name, Location = "testlocation" }; var floor2 = new Floor { FloorId = floor2Id, FloorName = floorName, BuildingId = building2Id }; context.Buildings.Add(building2); @@ -642,7 +651,7 @@ public void UpdateFloor_WhenFloorNameAlreadyExistsInUpdatedBuilding_ShouldThrowA // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateFloor(companyId, floorId, floorName, building2Id)); Assert.NotNull(ex); - Assert.AreEqual($"You cant move floor '{floorId}' to building '{building2Id}'. In building '{building2Id}' already exists a floor called '{floorName}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"You cant move floor '{floorName}' to building '{building2Name}'. In building '{building2Name}' already exists a floor called '{floorName}'")); // cleanup context.Database.EnsureDeleted(); @@ -671,14 +680,13 @@ public void UpdateFloor_WhenOnlyFloorNameIsProvided_ShouldUpdateFloorNameAndRetu var newFloorName = "newFloorName"; // act - var returnedFloorId = resourceUsecases.UpdateFloor(companyId, floorId, newFloorName, null); - var updatedFloor = context.Floors.SingleOrDefault(f => f.FloorId == floorId); + var updatedFloor = resourceUsecases.UpdateFloor(companyId, floorId, newFloorName, null); // assert - Assert.That(floorId == returnedFloorId); + Assert.That(updatedFloor.FloorId, Is.EqualTo(floorId)); Assert.NotNull(updatedFloor); - Assert.That(buildingId == updatedFloor.BuildingId); - Assert.That(newFloorName == updatedFloor.FloorName); + Assert.That(updatedFloor.BuildingId, Is.EqualTo(buildingId)); + Assert.That(updatedFloor.FloorName, Is.EqualTo(newFloorName)); // cleanup context.Database.EnsureDeleted(); @@ -709,14 +717,13 @@ public void UpdateFloor_WhenOnlyBuildingIdIsProvided_ShouldUpdateFloorBuildingAn var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); // act - var returnedFloorId = resourceUsecases.UpdateFloor(companyId, floorId, null, building2Id); - var updatedFloor = context.Floors.SingleOrDefault(f => f.FloorId == floorId); + var updatedFloor = resourceUsecases.UpdateFloor(companyId, floorId, null, building2Id); // assert - Assert.That(floorId == returnedFloorId); + Assert.That(updatedFloor.FloorId, Is.EqualTo(floorId)); Assert.NotNull(updatedFloor); - Assert.That(building2Id == updatedFloor.BuildingId); - Assert.That(floorName == updatedFloor.FloorName); + Assert.That(updatedFloor.BuildingId, Is.EqualTo(building2Id)); + Assert.That(updatedFloor.FloorName, Is.EqualTo(floorName)); // cleanup context.Database.EnsureDeleted(); @@ -744,14 +751,13 @@ public void UpdateFloor_WhenNeitherFloorNameNorBuildingIdIsProvided_ShouldReturn var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); // act - var returnedFloorId = resourceUsecases.UpdateFloor(companyId, floorId, null, null); - var updatedFloor = context.Floors.SingleOrDefault(f => f.FloorId == floorId); + var updatedFloor = resourceUsecases.UpdateFloor(companyId, floorId, null, null); // assert - Assert.That(floorId == returnedFloorId); + Assert.That(updatedFloor.FloorId, Is.EqualTo(floorId)); Assert.NotNull(updatedFloor); - Assert.That(buildingId == updatedFloor.BuildingId); - Assert.That(floorName == updatedFloor.FloorName); + Assert.That(updatedFloor.BuildingId, Is.EqualTo(buildingId)); + Assert.That(updatedFloor.FloorName, Is.EqualTo(floorName)); // cleanup context.Database.EnsureDeleted(); @@ -794,7 +800,7 @@ public void UpdateRoom_WhenRoomDoesNotExist_ShouldThrowEntityNotFoundException() // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateRoom(companyId, anotherRoomId, "Room Name", floorId)); Assert.NotNull(ex); - Assert.AreEqual($"There is no room with id '{anotherRoomId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"There is no room with id '{anotherRoomId}'")); // cleanup context.Database.EnsureDeleted(); @@ -812,7 +818,8 @@ public void UpdateRoom_WhenCompanyHasInsufficientPermission_ShouldThrowInsuffici var context = new DataContext(); var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = "testfloor" }; - var room = new Room { RoomId = roomId, FloorId = floorId, RoomName = "testroom" }; + var roomName = "testroom"; + var room = new Room { RoomId = roomId, FloorId = floorId, RoomName = roomName }; context.Buildings.Add(building); context.Floors.Add(floor); context.Rooms.Add(room); @@ -827,7 +834,7 @@ public void UpdateRoom_WhenCompanyHasInsufficientPermission_ShouldThrowInsuffici // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateRoom(anotherCompanyId, roomId, "Room Name", floorId)); Assert.NotNull(ex); - Assert.That($"'{anotherCompanyId}' has no access to administrate floor '{floorId}'" == ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Your company has no access to administrate room '{roomName}'")); // cleanup context.Database.EnsureDeleted(); @@ -894,7 +901,7 @@ public void UpdateRoom_WhenUpdatedFloorDoesNotExist_ShouldThrowEntityNotFoundExc // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateRoom(companyId, roomId, roomName, anotherFloorId)); Assert.NotNull(ex); - Assert.AreEqual($"Floor does not exist with id '{anotherFloorId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Floor does not exist with id '{anotherFloorId}'")); // cleanup context.Database.EnsureDeleted(); @@ -914,7 +921,8 @@ public void UpdateRoom_WhenCompanyHasInsufficientPermissionToChangeFloor_ShouldT var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; var anotherBuilding = new Building { BuildingId = anotherBuildingId, CompanyId = anotherCompanyId, BuildingName = "anothertestname", Location = "testlocation" }; var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = "testfloor" }; - var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = "testfloor" }; + var anotherFloorName = "anotherTestFloor"; + var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = anotherFloorName }; var roomName = "testroom"; var room = new Room { RoomId = roomId, FloorId = floorId, RoomName = roomName }; context.Buildings.Add(building); @@ -932,7 +940,7 @@ public void UpdateRoom_WhenCompanyHasInsufficientPermissionToChangeFloor_ShouldT // act+assert var ex = Assert.Throws(() => usecases.UpdateRoom(companyId, roomId, "New Room", anotherFloorId)); Assert.NotNull(ex); - Assert.AreEqual($"'{companyId}' has no access to move a room to floor '{anotherFloorId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Your company has no access to move a room to floor '{anotherFloorName}'")); // cleanup context.Database.EnsureDeleted(); @@ -971,13 +979,12 @@ public void UpdateRoom_WhenProvidedRoomNameAndFloor_ShouldUpdateBothNameAndFloor var updatedRoomName = "updatedRoomName"; // act - var gid = usecases.UpdateRoom(companyId, roomId, updatedRoomName, anotherFloorId); - var updatedRoom = context.Rooms.SingleOrDefault(r => r.RoomId == gid); + var updatedRoom = usecases.UpdateRoom(companyId, roomId, updatedRoomName, anotherFloorId); // assert Assert.NotNull(updatedRoom); - Assert.AreEqual(updatedRoomName, updatedRoom.RoomName); - Assert.AreEqual(anotherFloorId, updatedRoom.FloorId); + Assert.That(updatedRoom.RoomName, Is.EqualTo(updatedRoomName)); + Assert.That(updatedRoom.FloorId, Is.EqualTo(anotherFloorId)); // cleanup context.Database.EnsureDeleted(); @@ -1009,13 +1016,12 @@ public void UpdateRoom_WhenUpdatingOnlyRoomName_ShouldUpdateNameOnly() var updatedRoomName = "updatedRoomName"; // act - var gid = usecases.UpdateRoom(companyId, roomId, updatedRoomName, null); - var updatedRoom = context.Rooms.SingleOrDefault(r => r.RoomId == gid); + var updatedRoom = usecases.UpdateRoom(companyId, roomId, updatedRoomName, null); // assert Assert.NotNull(updatedRoom); - Assert.AreEqual(updatedRoomName, updatedRoom.RoomName); - Assert.AreEqual(floorId, updatedRoom.FloorId); + Assert.That(updatedRoom.RoomName, Is.EqualTo(updatedRoomName)); + Assert.That(updatedRoom.FloorId, Is.EqualTo(floorId)); // cleanup context.Database.EnsureDeleted(); @@ -1031,7 +1037,8 @@ public void UpdateRoom_WhenUpdatingOnlyRoomNameAndRoomNameAlreadyExists_ShouldTh var buildingId = Guid.NewGuid(); var roomId = Guid.NewGuid(); var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; - var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = "testfloor" }; + var floorName = "testfloor"; + var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = floorName }; var roomName = "testroom"; var room = new Room { RoomId = roomId, FloorId = floorId, RoomName = roomName }; context.Buildings.Add(building); @@ -1047,7 +1054,7 @@ public void UpdateRoom_WhenUpdatingOnlyRoomNameAndRoomNameAlreadyExists_ShouldTh // act+assert var ex = Assert.Throws(() => usecases.UpdateRoom(companyId, roomId, roomName, null)); Assert.NotNull(ex); - Assert.AreEqual($"There is already a room named '{roomName}' in floor '{floorId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"There is already a room named '{roomName}' in floor '{floorName}'")); // cleanup context.Database.EnsureDeleted(); @@ -1078,7 +1085,8 @@ public void UpdateRoom_WhenUpdatingRoomNameAndFloorAndRoomNameAlreadyExists_Shou var anotherRoomId = Guid.NewGuid(); var anotherBuilding = new Building { BuildingId = anotherBuildingId, CompanyId = companyId, BuildingName = "anothertestname", Location = "testlocation" }; - var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = "testfloor" }; + var anotherFloorName = "testfloor"; + var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = anotherFloorName }; var anotherRoom = new Room { RoomId = anotherRoomId, FloorId = anotherFloorId, RoomName = roomName }; context.Buildings.Add(anotherBuilding); @@ -1095,7 +1103,7 @@ public void UpdateRoom_WhenUpdatingRoomNameAndFloorAndRoomNameAlreadyExists_Shou // act+assert var ex = Assert.Throws(() => usecases.UpdateRoom(companyId, roomId, roomName, anotherFloorId)); Assert.NotNull(ex); - Assert.AreEqual($"You cant move room '{roomId}' to floor '{anotherFloorId}'. In floor '{anotherFloorId}' already exists a room called '{roomName}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"You cant move room '{roomName}' to floor '{anotherFloorName}'. In floor '{anotherFloorName}' already exists a room called '{roomName}'")); // cleanup context.Database.EnsureDeleted(); @@ -1132,13 +1140,12 @@ public void UpdateRoom_WhenUpdatingOnlyFloor_ShouldUpdateFloorOnly() var usecases = new ResourceUsecases(logger.Object, context, userUsecases.Object); // act - var gid = usecases.UpdateRoom(companyId, roomId, null, anotherFloorId); - var updatedRoom = context.Rooms.SingleOrDefault(r => r.RoomId == gid); + var updatedRoom = usecases.UpdateRoom(companyId, roomId, null, anotherFloorId); // assert Assert.NotNull(updatedRoom); - Assert.AreEqual(roomName, updatedRoom.RoomName); - Assert.AreEqual(anotherFloorId, updatedRoom.FloorId); + Assert.That(updatedRoom.RoomName, Is.EqualTo(roomName)); + Assert.That(updatedRoom.FloorId, Is.EqualTo(anotherFloorId)); // cleanup context.Database.EnsureDeleted(); @@ -1170,13 +1177,12 @@ public void UpdateRoom_WhenUpdatingNothing_ShouldUpdateNothing() var usecases = new ResourceUsecases(logger.Object, context, userUsecases.Object); // act - var gid = usecases.UpdateRoom(companyId, roomId, null, null); - var updatedRoom = context.Rooms.SingleOrDefault(r => r.RoomId == gid); + var updatedRoom = usecases.UpdateRoom(companyId, roomId, null, null); // assert Assert.NotNull(updatedRoom); - Assert.AreEqual(roomName, updatedRoom.RoomName); - Assert.AreEqual(floorId, updatedRoom.FloorId); + Assert.That(updatedRoom.RoomName, Is.EqualTo(roomName)); + Assert.That(updatedRoom.FloorId, Is.EqualTo(floorId)); // cleanup context.Database.EnsureDeleted(); @@ -1205,7 +1211,7 @@ public void UpdateDesk_WhenDeskDoesNotExist_ShouldThrowEntityNotFoundException() // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateDesk(companyId, unknownDeskId, null, null, null)); Assert.NotNull(ex); - Assert.AreEqual($"There is no desk with id '{unknownDeskId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"There is no desk with id '{unknownDeskId}'")); // cleanup context.Database.EnsureDeleted(); @@ -1267,7 +1273,7 @@ public void UpdateDesk_WhenCompanyHasInsufficientPermission_ShouldThrowInsuffici // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateDesk(companyId, anotherDeskId, null, null, null)); Assert.NotNull(ex); - Assert.AreEqual($"'{companyId}' has no access to administrate desk '{anotherDeskId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Your company has no access to administrate desk '{deskName}'")); // cleanup context.Database.EnsureDeleted(); @@ -1329,7 +1335,7 @@ public void UpdateDesk_WhenDeskNameIsEmpty_ShouldThrowArgumentInvalidException() // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateDesk(companyId, deskId, "", null, null)); Assert.NotNull(ex); - Assert.AreEqual($"Desk name must not be empty", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Desk name must not be empty")); // cleanup context.Database.EnsureDeleted(); @@ -1392,7 +1398,7 @@ public void UpdateDesk_WhenRoomDoesNotExist_ShouldThrowEntityNotFoundException() // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateDesk(companyId, deskId, null, unknownRoomId, null)); Assert.NotNull(ex); - Assert.AreEqual($"Room does not exist with id '{unknownRoomId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Room does not exist with id '{unknownRoomId}'")); // cleanup context.Database.EnsureDeleted(); @@ -1433,7 +1439,8 @@ public void UpdateDesk_WhenCompanyHasInsufficientPermissionToChangeRoom_ShouldTh var anotherBuilding = new Building { BuildingId = anotherBuildingId, CompanyId = anotherCompanyId, BuildingName = "anothertestname", Location = "testlocation" }; var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = "anothertestfloor" }; - var anotherRoom = new Room { RoomId = anotherRoomId, FloorId = anotherFloorId, RoomName = "anothertestroom" }; + var anotherRoomName = "anothertestroom"; + var anotherRoom = new Room { RoomId = anotherRoomId, FloorId = anotherFloorId, RoomName = anotherRoomName }; var anotherDeskType = new DeskType { CompanyId = anotherCompanyId, DeskTypeId = anotherDeskTypeId, DeskTypeName = "anotherdesktype" }; var anotherDesk = new Desk { DeskId = anotherDeskId, DeskName = deskName, DeskTypeId = anotherDeskTypeId, RoomId = anotherRoomId }; @@ -1455,7 +1462,7 @@ public void UpdateDesk_WhenCompanyHasInsufficientPermissionToChangeRoom_ShouldTh // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateDesk(companyId, deskId, null, anotherRoomId, null)); Assert.NotNull(ex); - Assert.AreEqual($"'{companyId}' has no access to add a desk to room '{anotherRoomId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Your company has no access to add a desk to room '{anotherRoomName}'")); // cleanup context.Database.EnsureDeleted(); @@ -1518,7 +1525,7 @@ public void UpdateDesk_WhenDeskTypeDoesNotExist_ShouldThrowEntityNotFoundExcepti // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateDesk(companyId, deskId, null, null, unknownDeskTypeId)); Assert.NotNull(ex); - Assert.AreEqual($"DeskType does not exist with id '{unknownDeskTypeId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"DeskType does not exist with id '{unknownDeskTypeId}'")); // cleanup context.Database.EnsureDeleted(); @@ -1560,7 +1567,8 @@ public void UpdateDesk_WhenCompanyHasInsufficientPermissionToChangeDeskType_Shou var anotherBuilding = new Building { BuildingId = anotherBuildingId, CompanyId = anotherCompanyId, BuildingName = "anothertestname", Location = "testlocation" }; var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = "anothertestfloor" }; var anotherRoom = new Room { RoomId = anotherRoomId, FloorId = anotherFloorId, RoomName = "anothertestroom" }; - var anotherDeskType = new DeskType { CompanyId = anotherCompanyId, DeskTypeId = anotherDeskTypeId, DeskTypeName = "anotherdesktype" }; + var anotherDeskTypeName = "anotherdesktype"; + var anotherDeskType = new DeskType { CompanyId = anotherCompanyId, DeskTypeId = anotherDeskTypeId, DeskTypeName = anotherDeskTypeName }; var anotherDesk = new Desk { DeskId = anotherDeskId, DeskName = deskName, DeskTypeId = anotherDeskTypeId, RoomId = anotherRoomId }; context.Buildings.Add(anotherBuilding); @@ -1580,7 +1588,7 @@ public void UpdateDesk_WhenCompanyHasInsufficientPermissionToChangeDeskType_Shou // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateDesk(companyId, deskId, null, null, anotherDeskTypeId)); Assert.NotNull(ex); - Assert.AreEqual($"'{companyId}' has no access to desk type '{anotherDeskTypeId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"Your company has no access to desk type '{anotherDeskTypeName}'")); // cleanup context.Database.EnsureDeleted(); @@ -1641,14 +1649,13 @@ public void UpdateDesk_WhenUpdatingDeskNameAndRoomAndDeskType_ShouldUpdateDeskNa var updatedDeskName = "updatedDeskName"; // act - var guid = resourceUsecases.UpdateDesk(companyId, deskId, updatedDeskName, anotherRoomId, anotherDeskTypeId); - var updatedDesk = context.Desks.SingleOrDefault(d => d.DeskId == guid); + var updatedDesk = resourceUsecases.UpdateDesk(companyId, deskId, updatedDeskName, anotherRoomId, anotherDeskTypeId); // assert Assert.NotNull(updatedDesk); - Assert.AreEqual(updatedDeskName, updatedDesk.DeskName); - Assert.AreEqual(anotherRoomId, updatedDesk.RoomId); - Assert.AreEqual(anotherDeskTypeId, updatedDesk.DeskTypeId); + Assert.That(updatedDesk.DeskName, Is.EqualTo(updatedDeskName)); + Assert.That(updatedDesk.RoomId, Is.EqualTo(anotherRoomId)); + Assert.That(updatedDesk.DeskTypeId, Is.EqualTo(anotherDeskTypeId)); // cleanup context.Database.EnsureDeleted(); @@ -1709,14 +1716,13 @@ public void UpdateDesk_WhenUpdatingOnlyDeskNameAndNameDoesNotExists_ShouldOnlyUp var updatedDeskName = "updatedDeskName"; // act - var guid = resourceUsecases.UpdateDesk(companyId, deskId, updatedDeskName, null, null); - var updatedDesk = context.Desks.SingleOrDefault(d => d.DeskId == guid); + var updatedDesk = resourceUsecases.UpdateDesk(companyId, deskId, updatedDeskName, null, null); // assert Assert.NotNull(updatedDesk); - Assert.AreEqual(updatedDeskName, updatedDesk.DeskName); - Assert.AreEqual(roomId, updatedDesk.RoomId); - Assert.AreEqual(deskTypeId, updatedDesk.DeskTypeId); + Assert.That(updatedDesk.DeskName, Is.EqualTo(updatedDeskName)); + Assert.That(updatedDesk.RoomId, Is.EqualTo(roomId)); + Assert.That(updatedDesk.DeskTypeId, Is.EqualTo(deskTypeId)); // cleanup context.Database.EnsureDeleted(); @@ -1736,7 +1742,8 @@ public void UpdateDesk_WhenUpdatingOnlyDeskNameAndNameDoesAlreadyExists_ShouldTh var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = "testfloor" }; - var room = new Room { RoomId = roomId, FloorId = floorId, RoomName = "testroom" }; + var roomName = "testroom"; + var room = new Room { RoomId = roomId, FloorId = floorId, RoomName = roomName }; var deskType = new DeskType { CompanyId = companyId, DeskTypeId = deskTypeId, DeskTypeName = "testdesktype" }; var deskName = "testdesk"; var desk = new Desk { DeskId = deskId, DeskName = deskName, DeskTypeId = deskTypeId, RoomId = roomId }; @@ -1779,7 +1786,7 @@ public void UpdateDesk_WhenUpdatingOnlyDeskNameAndNameDoesAlreadyExists_ShouldTh // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateDesk(companyId, deskId, updatedDeskName, null, null)); Assert.NotNull(ex); - Assert.AreEqual($"There is already a desk named '{updatedDeskName}' in room '{roomId}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"There is already a desk named '{updatedDeskName}' in room '{roomName}'")); // cleanup context.Database.EnsureDeleted(); @@ -1820,7 +1827,8 @@ public void UpdateDesk_WhenUpdatingOnlyRoomAndDeskNameInOtherRoomAlreadyExists_S var anotherBuilding = new Building { BuildingId = anotherBuildingId, CompanyId = companyId, BuildingName = "anothertestname", Location = "testlocation" }; var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = "anothertestfloor" }; - var anotherRoom = new Room { RoomId = anotherRoomId, FloorId = anotherFloorId, RoomName = "anothertestroom" }; + var anotherRoomName = "anothertestroom"; + var anotherRoom = new Room { RoomId = anotherRoomId, FloorId = anotherFloorId, RoomName = anotherRoomName }; var anotherDeskType = new DeskType { CompanyId = companyId, DeskTypeId = anotherDeskTypeId, DeskTypeName = "anotherdesktype" }; var anotherDesk = new Desk { DeskId = anotherDeskId, DeskName = deskName, DeskTypeId = anotherDeskTypeId, RoomId = anotherRoomId }; @@ -1841,7 +1849,7 @@ public void UpdateDesk_WhenUpdatingOnlyRoomAndDeskNameInOtherRoomAlreadyExists_S // act+assert var ex = Assert.Throws(() => resourceUsecases.UpdateDesk(companyId, deskId, null, anotherRoomId, null)); Assert.NotNull(ex); - Assert.AreEqual($"You cant move desk '{deskId}' to room '{anotherRoomId}'. In room '{anotherRoomId}' already exists a desk called '{deskName}'", ex.Message); + Assert.That(ex.Message, Is.EqualTo($"You cant move desk '{deskName}' to room '{anotherRoomName}'. In room '{anotherRoomName}' already exists a desk called '{deskName}'")); // cleanup context.Database.EnsureDeleted(); @@ -1901,14 +1909,13 @@ public void UpdateDesk_WhenUpdatingOnlyRoomAndDeskNameInOtherRoomDoesNotExists_S var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); // act - var guid = resourceUsecases.UpdateDesk(companyId, deskId, null, anotherRoomId, null); - var updatedDesk = context.Desks.SingleOrDefault(d => d.DeskId == guid); + var updatedDesk = resourceUsecases.UpdateDesk(companyId, deskId, null, anotherRoomId, null); // assert Assert.NotNull(updatedDesk); - Assert.AreEqual(deskName, updatedDesk.DeskName); - Assert.AreEqual(anotherRoomId, updatedDesk.RoomId); - Assert.AreEqual(deskTypeId, updatedDesk.DeskTypeId); + Assert.That(updatedDesk.DeskName, Is.EqualTo(deskName)); + Assert.That(updatedDesk.RoomId, Is.EqualTo(anotherRoomId)); + Assert.That(updatedDesk.DeskTypeId, Is.EqualTo(deskTypeId)); // cleanup context.Database.EnsureDeleted(); @@ -1967,13 +1974,14 @@ public void UpdateDesk_WhenUpdatingOnlyDeskType_ShouldOnlyUpdateDeskType() var resourceLogger = new Mock>(); var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); - // act+assert - var guid = resourceUsecases.UpdateDesk(companyId, deskId, null, null, anotherDeskTypeId); - var updatedDesk = context.Desks.SingleOrDefault(d => d.DeskId == guid); + // act + var updatedDesk = resourceUsecases.UpdateDesk(companyId, deskId, null, null, anotherDeskTypeId); + + // assert Assert.NotNull(updatedDesk); - Assert.AreEqual(deskName, updatedDesk.DeskName); - Assert.AreEqual(roomId, updatedDesk.RoomId); - Assert.AreEqual(anotherDeskTypeId, updatedDesk.DeskTypeId); + Assert.That(updatedDesk.DeskName, Is.EqualTo(deskName)); + Assert.That(updatedDesk.RoomId, Is.EqualTo(roomId)); + Assert.That(updatedDesk.DeskTypeId, Is.EqualTo(anotherDeskTypeId)); // cleanup context.Database.EnsureDeleted(); @@ -2032,13 +2040,327 @@ public void UpdateDesk_WhenUpdatingNothing_ShouldThrowArgumentInvalidException() var resourceLogger = new Mock>(); var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); - // act+assert - var guid = resourceUsecases.UpdateDesk(companyId, deskId, null, null, null); - var updatedDesk = context.Desks.SingleOrDefault(d => d.DeskId == guid); + // act + var updatedDesk = resourceUsecases.UpdateDesk(companyId, deskId, null, null, null); + + //assert Assert.NotNull(updatedDesk); - Assert.AreEqual(deskName, updatedDesk.DeskName); - Assert.AreEqual(roomId, updatedDesk.RoomId); - Assert.AreEqual(deskTypeId, updatedDesk.DeskTypeId); + Assert.That(updatedDesk.DeskName, Is.EqualTo(deskName)); + Assert.That(updatedDesk.RoomId, Is.EqualTo(roomId)); + Assert.That(updatedDesk.DeskTypeId, Is.EqualTo(deskTypeId)); + + // cleanup + context.Database.EnsureDeleted(); + } + [Test] + public void UpdateDeskType_WhenDeskTypeDoesNotExist_ShouldThrowEntityNotFoundException() + { + // setup + var companyId = Guid.NewGuid(); + var floorId = Guid.NewGuid(); + var bui = Guid.NewGuid(); + var roomId = Guid.NewGuid(); + var floor = new Floor { FloorId = floorId, FloorName = "testfloor", BuildingId = Guid.NewGuid() }; + var context = new DataContext(); + context.Floors.Add(floor); + context.SaveChanges(); + + // arrange + var userLogger = new Mock>(); + var userUsecases = new UserUsecases(userLogger.Object, context); + var resourceLogger = new Mock>(); + var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); + var unknownDeskTypeId = Guid.NewGuid(); + + // act+assert + var ex = Assert.Throws(() => resourceUsecases.UpdateDeskType(companyId, unknownDeskTypeId, null)); + Assert.NotNull(ex); + Assert.That(ex.Message, Is.EqualTo($"There is no desk type with id '{unknownDeskTypeId}'")); + + // cleanup + context.Database.EnsureDeleted(); + } + [Test] + public void UpdateDeskType_WhenDeskTypeDoesBelongToDifferentCompany_ShouldThrowInsufficientPermissionException() + { + // setup + var context = new DataContext(); + + var companyId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + var deskTypeName = "testdesktype"; + var deskType = new DeskType { CompanyId = companyId, DeskTypeId = deskTypeId, DeskTypeName = deskTypeName }; + + context.DeskTypes.Add(deskType); + context.SaveChanges(); + + // arrange + var userLogger = new Mock>(); + var userUsecases = new UserUsecases(userLogger.Object, context); + var resourceLogger = new Mock>(); + var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); + var noPermissionCompanyId = Guid.NewGuid(); + + // act+assert + var ex = Assert.Throws(() => resourceUsecases.UpdateDeskType(noPermissionCompanyId, deskTypeId, null)); + Assert.NotNull(ex); + Assert.That(ex.Message, Is.EqualTo($"Your company has no access to administrate desk type '{deskTypeName}'")); + + // cleanup + context.Database.EnsureDeleted(); + } + [Test] + public void UpdateDeskType_WhenDeskTypeNameIsEmpty_ShouldThrowArgumentInvalidException() + { + // setup + var context = new DataContext(); + + var companyId = Guid.NewGuid(); + var buildingId = Guid.NewGuid(); + var floorId = Guid.NewGuid(); + var roomId = Guid.NewGuid(); + var deskId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + + var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; + var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = "testfloor" }; + var room = new Room { RoomId = roomId, FloorId = floorId, RoomName = "testroom" }; + var deskType = new DeskType { CompanyId = companyId, DeskTypeId = deskTypeId, DeskTypeName = "testdesktype" }; + var deskName = "testdesk"; + var desk = new Desk { DeskId = deskId, DeskName = deskName, DeskTypeId = deskTypeId, RoomId = roomId }; + + context.Buildings.Add(building); + context.Floors.Add(floor); + context.Rooms.Add(room); + context.DeskTypes.Add(deskType); + context.Desks.Add(desk); + + + var anotherCompanyId = Guid.NewGuid(); + var anotherBuildingId = Guid.NewGuid(); + var anotherFloorId = Guid.NewGuid(); + var anotherRoomId = Guid.NewGuid(); + var anotherDeskId = Guid.NewGuid(); + var anotherDeskTypeId = Guid.NewGuid(); + + var anotherBuilding = new Building { BuildingId = anotherBuildingId, CompanyId = anotherCompanyId, BuildingName = "anothertestname", Location = "testlocation" }; + var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = "anothertestfloor" }; + var anotherRoom = new Room { RoomId = anotherRoomId, FloorId = anotherFloorId, RoomName = "anothertestroom" }; + var anotherDeskType = new DeskType { CompanyId = anotherCompanyId, DeskTypeId = anotherDeskTypeId, DeskTypeName = "anotherdesktype" }; + var anotherDesk = new Desk { DeskId = anotherDeskId, DeskName = deskName, DeskTypeId = anotherDeskTypeId, RoomId = anotherRoomId }; + + context.Buildings.Add(anotherBuilding); + context.Floors.Add(anotherFloor); + context.Rooms.Add(anotherRoom); + context.DeskTypes.Add(anotherDeskType); + context.Desks.Add(anotherDesk); + + context.SaveChanges(); + + // arrange + var userLogger = new Mock>(); + var userUsecases = new UserUsecases(userLogger.Object, context); + var resourceLogger = new Mock>(); + var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); + + // act+assert + var ex = Assert.Throws(() => resourceUsecases.UpdateDeskType(companyId, deskTypeId, "")); + Assert.NotNull(ex); + Assert.That(ex.Message, Is.EqualTo("Desk type name must not be empty")); + + // cleanup + context.Database.EnsureDeleted(); + } + [Test] + public void UpdateDeskType_WhenDeskTypeNameIsTaken_ShouldThrowArgumentInvalidException() + { + // setup + var context = new DataContext(); + + var companyId = Guid.NewGuid(); + var buildingId = Guid.NewGuid(); + var floorId = Guid.NewGuid(); + var roomId = Guid.NewGuid(); + var deskId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + + var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; + var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = "testfloor" }; + var room = new Room { RoomId = roomId, FloorId = floorId, RoomName = "testroom" }; + var deskType = new DeskType { CompanyId = companyId, DeskTypeId = deskTypeId, DeskTypeName = "testdesktype" }; + var deskName = "testdesk"; + var desk = new Desk { DeskId = deskId, DeskName = deskName, DeskTypeId = deskTypeId, RoomId = roomId }; + + context.Buildings.Add(building); + context.Floors.Add(floor); + context.Rooms.Add(room); + context.DeskTypes.Add(deskType); + context.Desks.Add(desk); + + + var anotherCompanyId = Guid.NewGuid(); + var anotherBuildingId = Guid.NewGuid(); + var anotherFloorId = Guid.NewGuid(); + var anotherRoomId = Guid.NewGuid(); + var anotherDeskId = Guid.NewGuid(); + var anotherDeskTypeId = Guid.NewGuid(); + + var anotherBuilding = new Building { BuildingId = anotherBuildingId, CompanyId = anotherCompanyId, BuildingName = "anothertestname", Location = "testlocation" }; + var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = "anothertestfloor" }; + var anotherRoom = new Room { RoomId = anotherRoomId, FloorId = anotherFloorId, RoomName = "anothertestroom" }; + var anotherDeskTypeName = "anotherdesktype"; + var anotherDeskType = new DeskType { CompanyId = companyId, DeskTypeId = anotherDeskTypeId, DeskTypeName = anotherDeskTypeName }; + var anotherDesk = new Desk { DeskId = anotherDeskId, DeskName = deskName, DeskTypeId = anotherDeskTypeId, RoomId = anotherRoomId }; + + context.Buildings.Add(anotherBuilding); + context.Floors.Add(anotherFloor); + context.Rooms.Add(anotherRoom); + context.DeskTypes.Add(anotherDeskType); + context.Desks.Add(anotherDesk); + + context.SaveChanges(); + + // arrange + var userLogger = new Mock>(); + var userUsecases = new UserUsecases(userLogger.Object, context); + var resourceLogger = new Mock>(); + var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); + + // act+assert + var ex = Assert.Throws(() => resourceUsecases.UpdateDeskType(companyId, deskTypeId, anotherDeskTypeName)); + Assert.NotNull(ex); + Assert.That(ex.Message, Is.EqualTo($"There is already a desktype named '{anotherDeskTypeName}'")); + + // cleanup + context.Database.EnsureDeleted(); + } + [Test] + public void UpdateDeskType_WhenUpdatingDeskTypeName_ShouldUpdateName() + { + // setup + var context = new DataContext(); + + var companyId = Guid.NewGuid(); + var buildingId = Guid.NewGuid(); + var floorId = Guid.NewGuid(); + var roomId = Guid.NewGuid(); + var deskId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + + var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; + var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = "testfloor" }; + var room = new Room { RoomId = roomId, FloorId = floorId, RoomName = "testroom" }; + var deskType = new DeskType { CompanyId = companyId, DeskTypeId = deskTypeId, DeskTypeName = "testdesktype" }; + var deskName = "testdesk"; + var desk = new Desk { DeskId = deskId, DeskName = deskName, DeskTypeId = deskTypeId, RoomId = roomId }; + + context.Buildings.Add(building); + context.Floors.Add(floor); + context.Rooms.Add(room); + context.DeskTypes.Add(deskType); + context.Desks.Add(desk); + + + var anotherCompanyId = Guid.NewGuid(); + var anotherBuildingId = Guid.NewGuid(); + var anotherFloorId = Guid.NewGuid(); + var anotherRoomId = Guid.NewGuid(); + var anotherDeskId = Guid.NewGuid(); + var anotherDeskTypeId = Guid.NewGuid(); + + var anotherBuilding = new Building { BuildingId = anotherBuildingId, CompanyId = anotherCompanyId, BuildingName = "anothertestname", Location = "testlocation" }; + var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = "anothertestfloor" }; + var anotherRoom = new Room { RoomId = anotherRoomId, FloorId = anotherFloorId, RoomName = "anothertestroom" }; + var anotherDeskTypeName = "anotherdesktype"; + var anotherDeskType = new DeskType { CompanyId = companyId, DeskTypeId = anotherDeskTypeId, DeskTypeName = anotherDeskTypeName }; + var anotherDesk = new Desk { DeskId = anotherDeskId, DeskName = deskName, DeskTypeId = anotherDeskTypeId, RoomId = anotherRoomId }; + + context.Buildings.Add(anotherBuilding); + context.Floors.Add(anotherFloor); + context.Rooms.Add(anotherRoom); + context.DeskTypes.Add(anotherDeskType); + context.Desks.Add(anotherDesk); + + context.SaveChanges(); + + // arrange + var userLogger = new Mock>(); + var userUsecases = new UserUsecases(userLogger.Object, context); + var resourceLogger = new Mock>(); + var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); + var deskTypeNameThatDoesNotExistYet = "deskNameThatDoesNotExistYet"; + + // act + var updatedDeskType = resourceUsecases.UpdateDeskType(companyId, deskTypeId, deskTypeNameThatDoesNotExistYet); + + // assert + Assert.NotNull(updatedDeskType); + Assert.That(updatedDeskType.DeskTypeName, Is.EqualTo(deskTypeNameThatDoesNotExistYet)); + + // cleanup + context.Database.EnsureDeleted(); + } + [Test] + public void UpdateDeskType_WhenUpdatingNothing_ShouldUpdateNothing() + { + // setup + var context = new DataContext(); + + var companyId = Guid.NewGuid(); + var buildingId = Guid.NewGuid(); + var floorId = Guid.NewGuid(); + var roomId = Guid.NewGuid(); + var deskId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + + var building = new Building { BuildingId = buildingId, CompanyId = companyId, BuildingName = "testname", Location = "testlocation" }; + var floor = new Floor { FloorId = floorId, BuildingId = buildingId, FloorName = "testfloor" }; + var room = new Room { RoomId = roomId, FloorId = floorId, RoomName = "testroom" }; + var deskType = new DeskType { CompanyId = companyId, DeskTypeId = deskTypeId, DeskTypeName = "testdesktype" }; + var deskName = "testdesk"; + var desk = new Desk { DeskId = deskId, DeskName = deskName, DeskTypeId = deskTypeId, RoomId = roomId }; + + context.Buildings.Add(building); + context.Floors.Add(floor); + context.Rooms.Add(room); + context.DeskTypes.Add(deskType); + context.Desks.Add(desk); + + + var anotherCompanyId = Guid.NewGuid(); + var anotherBuildingId = Guid.NewGuid(); + var anotherFloorId = Guid.NewGuid(); + var anotherRoomId = Guid.NewGuid(); + var anotherDeskId = Guid.NewGuid(); + var anotherDeskTypeId = Guid.NewGuid(); + + var anotherBuilding = new Building { BuildingId = anotherBuildingId, CompanyId = anotherCompanyId, BuildingName = "anothertestname", Location = "testlocation" }; + var anotherFloor = new Floor { FloorId = anotherFloorId, BuildingId = anotherBuildingId, FloorName = "anothertestfloor" }; + var anotherRoom = new Room { RoomId = anotherRoomId, FloorId = anotherFloorId, RoomName = "anothertestroom" }; + var anotherDeskTypeName = "anotherdesktype"; + var anotherDeskType = new DeskType { CompanyId = companyId, DeskTypeId = anotherDeskTypeId, DeskTypeName = anotherDeskTypeName }; + var anotherDesk = new Desk { DeskId = anotherDeskId, DeskName = deskName, DeskTypeId = anotherDeskTypeId, RoomId = anotherRoomId }; + + context.Buildings.Add(anotherBuilding); + context.Floors.Add(anotherFloor); + context.Rooms.Add(anotherRoom); + context.DeskTypes.Add(anotherDeskType); + context.Desks.Add(anotherDesk); + + context.SaveChanges(); + + // arrange + var userLogger = new Mock>(); + var userUsecases = new UserUsecases(userLogger.Object, context); + var resourceLogger = new Mock>(); + var resourceUsecases = new ResourceUsecases(resourceLogger.Object, context, userUsecases); + + // act + var updatedDeskType = resourceUsecases.UpdateDeskType(companyId, anotherDeskTypeId, null); + + // assert + Assert.NotNull(updatedDeskType); + Assert.That(updatedDeskType.DeskTypeName, Is.EqualTo(anotherDeskTypeName)); // cleanup context.Database.EnsureDeleted(); diff --git a/src/deskstar-frontend/components/resources/BuildingResourceEditModal.tsx b/src/deskstar-frontend/components/resources/BuildingResourceEditModal.tsx new file mode 100644 index 00000000..cd7ea7d6 --- /dev/null +++ b/src/deskstar-frontend/components/resources/BuildingResourceEditModal.tsx @@ -0,0 +1,78 @@ +import { Session } from "next-auth"; +import { useSession } from "next-auth/react"; +import React, { useEffect, useState } from "react"; +import { toast } from "react-toastify"; +import { updateBuilding } from "../../lib/api/ResourceService"; +import { IBuilding } from "../../types/building"; +import { ILocation } from "../../types/location"; +import Input from "../forms/Input"; + +const BuildingResourceEditModal = ({ + building, + isOpen, + setState, + updateBuilding, + buildingName, + setBuildingName, + location, + setLocation +}: { + building: IBuilding | undefined; + isOpen: boolean; + setState: Function; + updateBuilding: Function; + setBuildingName: Function; + setLocation: Function; + buildingName: string; + location: string; +}) => { + if (!building) return (<>) + return ( + <> +
+
+ { setState(false); }}> + x + +

Edit Building

+ { + setBuildingName(e.target.value); + console.log(e.target.value); + }} + value={buildingName} + placeholder={building.buildingName} + /> + { + setLocation(e.target.value); + console.log(e.target.value); + }} + value={location} + placeholder={building.location} + /> +
+ +
+
+
+ + ); +}; + +export default BuildingResourceEditModal; \ No newline at end of file diff --git a/src/deskstar-frontend/components/resources/DeskResourceEditModal.tsx b/src/deskstar-frontend/components/resources/DeskResourceEditModal.tsx new file mode 100644 index 00000000..7e37e159 --- /dev/null +++ b/src/deskstar-frontend/components/resources/DeskResourceEditModal.tsx @@ -0,0 +1,233 @@ +import { Session } from "next-auth"; +import React, { useState } from "react"; +import { toast } from "react-toastify"; +import { IDesk } from "../../types/desk"; +import { IRoom } from "../../types/room"; +import Input from "../forms/Input"; +import { getFloors, getRooms } from "../../lib/api/ResourceService"; +import { IBuilding } from "../../types/building"; +import { IDeskType } from "../../types/desktypes"; +import { IFloor } from "../../types/floor"; +import { ILocation } from "../../types/location"; +import FilterListbox from "../FilterListbox"; + +const DeskResourceEditModal = ({ + desk, + isOpen, + setState, + session, + updateDesk, + origBuildings, + origDeskTypes, + deskName, + setDeskName, +}: { + desk: IDesk | undefined; + rooms: IRoom[]; + isOpen: boolean; + setState: Function; + session: Session; + origBuildings: IBuilding[]; + origDeskTypes: IDeskType[]; + updateDesk: Function; + deskName: string; + setDeskName: Function; +}) => { + if (!desk) return (<>) + + const [deskType, setDeskType] = useState(); + const [room, setRoom] = useState(); + const [floor, setFloor] = useState(); + const [building, setBuilding] = useState(); + const [location, setLocation] = useState(); + const uniqueLocation = (ogBuildings: IBuilding[]) => { + const t = new Map(); + ogBuildings.forEach((element) => + t.set(element.location, { locationName: element.location }) + ); + return Array.from(t.values()); + }; + const [locations, setLocations] = useState( + uniqueLocation(origBuildings) + ); + + const [buildings, setBuildings] = useState([]); + const [floors, setFloors] = useState([]); + const [rooms, setRooms] = useState([]); + const [deskTypes, setDeskTypes] = useState(origDeskTypes); + + function clearState() { + setLocation(null); + setBuilding(null); + setFloor(null); + setRoom(null); + } + async function onSelectedLocationChange( + selectedLocation: ILocation | null | undefined + ) { + if (!selectedLocation) { + return; + } + + setLocation(selectedLocation); + let filteredBuildings = origBuildings.filter( + (building) => selectedLocation.locationName === building.location + ); + + setBuildings(filteredBuildings); + setBuilding(null); + setFloor(null); + setRoom(null); + } + + async function onSelectedBuildingChange( + selectedBuilding: IBuilding | null | undefined + ) { + if (!selectedBuilding) { + return; + } + + setBuilding(selectedBuilding); + if (!session) { + return []; + } + const resFloors = await getFloors(session, selectedBuilding.buildingId); + setFloors(resFloors); + + setFloor(null); + setRoom(null); + } + + async function onSelectedFloorChange( + selectedFloor: IFloor | null | undefined + ) { + if (!selectedFloor) { + return; + } + + setFloor(selectedFloor); + if (!session) { + return []; + } + + const resRooms = await getRooms(session, selectedFloor.floorId); + setRooms(resRooms); + setRoom(null); + } + + async function onSelectedDeskTypeChange( + onSelectedDeskType: IDeskType | null | undefined + ) { + if (!onSelectedDeskType) { + return; + } + setDeskType(onSelectedDeskType); + } + return ( + <> +
+
+ { clearState(); setState(false); }}> + x + +

Edit Desk Type

+ { + setDeskName(e.target.value); + console.log(e.target.value); + }} + value={deskName} + placeholder={desk.deskName} + /> + <> +
Change Desk Type
+ onSelectedDeskTypeChange(o)} + getName={(deskType) => + deskType ? deskType.deskTypeName : "No type selected" + } + /> + + +
Location
+ onSelectedLocationChange(o)} + getName={(location) => + location ? location.locationName : "select location" + } + /> + + {location && ( + <> +
Building
+ onSelectedBuildingChange(o)} + getName={(building) => + building ? building.buildingName : "select building" + } + /> + + )} + + {building && ( + <> +
Floor
+ onSelectedFloorChange(o)} + getName={(floor) => + floor ? floor.floorName : "select floor" + } + /> + + )} + + {floor && ( + <> +
Room
+ setRoom(o)} + getName={(room) => (room ? room.roomName : "select room")} + /> + + )} +
+ +
+
+
+ + ); +}; + +export default DeskResourceEditModal; diff --git a/src/deskstar-frontend/components/resources/DeskResourceTable.tsx b/src/deskstar-frontend/components/resources/DeskResourceTable.tsx index ce0ac1c5..1644e8c7 100644 --- a/src/deskstar-frontend/components/resources/DeskResourceTable.tsx +++ b/src/deskstar-frontend/components/resources/DeskResourceTable.tsx @@ -1,6 +1,7 @@ import { IDesk } from "../../types/desk"; import { FaTrashAlt, FaEdit } from "react-icons/fa"; import React from "react"; +import DeskResourceEditModal from "./DeskResourceEditModal"; const DeskResourceTable = ({ desks, @@ -18,6 +19,7 @@ const DeskResourceTable = ({ {/* set size of Desk column */} Desk + Desk Type Room Floor Building @@ -52,6 +54,7 @@ const DeskResourceTableEntry = ({ return ( {desk.deskName} + {desk.deskTyp} {desk.roomName} {desk.floorName} {desk.buildingName} @@ -64,10 +67,11 @@ const DeskResourceTableEntry = ({ )} {onEdit && ( - + )} + )} diff --git a/src/deskstar-frontend/components/resources/DeskTypeResourceEditModal.tsx b/src/deskstar-frontend/components/resources/DeskTypeResourceEditModal.tsx new file mode 100644 index 00000000..2f0ed8a6 --- /dev/null +++ b/src/deskstar-frontend/components/resources/DeskTypeResourceEditModal.tsx @@ -0,0 +1,72 @@ +import { Session } from "next-auth"; +import React, { useState } from "react"; +import { toast } from "react-toastify"; +import { getFloors, getRooms } from "../../lib/api/ResourceService"; +import { IBuilding } from "../../types/building"; +import { IDeskType } from "../../types/desktypes"; +import { IFloor } from "../../types/floor"; +import { ILocation } from "../../types/location"; +import { IRoom } from "../../types/room"; +import FilterListbox from "../FilterListbox"; +import Input from "../forms/Input"; + +const DeskTypeResourceEditModal = ({ + desktype, + isOpen, + setState, + session, + updateDeskType, + deskTypeName, + setDeskTypeName, +}: { + desktype: IDeskType | undefined; + isOpen: boolean; + setState: Function; + session: Session; + updateDeskType: Function; + deskTypeName: string; + setDeskTypeName: Function; +}) => { + if (!desktype) return (<>) + + return ( + <> +
+
+ setState(false)}> + x + +

Edit Desk Type

+ { + setDeskTypeName(e.target.value); + console.log(e.target.value); + }} + value={deskTypeName} + placeholder={desktype.deskTypeName} + /> + + +
+ +
+
+
+ + ); +}; + +export default DeskTypeResourceEditModal; \ No newline at end of file diff --git a/src/deskstar-frontend/components/resources/FloorResourceEditModal.tsx b/src/deskstar-frontend/components/resources/FloorResourceEditModal.tsx new file mode 100644 index 00000000..a02054b0 --- /dev/null +++ b/src/deskstar-frontend/components/resources/FloorResourceEditModal.tsx @@ -0,0 +1,143 @@ +import { Session } from "next-auth"; +import React, { useState } from "react"; +import { toast } from "react-toastify"; +import { IBuilding } from "../../types/building"; +import { ILocation } from "../../types/location"; +import { IFloor } from "../../types/floor"; +import Input from "../forms/Input"; +import FilterListbox from "../FilterListbox"; + +const FloorResourceEditModal = ({ + floor, + origBuildings, + isOpen, + setState, + updateFloor, + floorName, + setFloorName, + session, +}: { + floor: IFloor | undefined; + origBuildings: IBuilding[]; + isOpen: boolean; + setState: Function; + updateFloor: Function; + session: Session; + floorName: string; + setFloorName: Function; +}) => { + if (!floor) return (<>) + + const uniqueLocation = (ogBuildings: IBuilding[]) => { + const t = new Map(); + ogBuildings.forEach((element) => + t.set(element.location, { locationName: element.location }) + ); + return Array.from(t.values()); + }; + const [locations, setLocations] = useState( + uniqueLocation(origBuildings) + ); + const [building, setBuilding] = useState(); + const [location, setLocation] = useState(); + const [buildings, setBuildings] = useState([]); + + async function onSelectedLocationChange( + selectedLocation: ILocation | null | undefined + ) { + if (!selectedLocation) { + return; + } + + setLocation(selectedLocation); + let filteredBuildings = origBuildings.filter( + (building) => selectedLocation.locationName === building.location + ); + + setBuildings(filteredBuildings); + setBuilding(null); + } + + async function onSelectedBuildingChange( + selectedBuilding: IBuilding | null | undefined + ) { + if (!selectedBuilding) { + return; + } + + setBuilding(selectedBuilding); + if (!session) { + return []; + } + } + async function clearState() { + setBuilding(null); + setLocation(null); + } + return ( + <> +
+
+ { clearState(); setState(false); }}> + x + +

Edit Floor

+ { + setFloorName(e.target.value); + console.log(e.target.value); + }} + value={floorName} + placeholder={floor.floorName} + /> +
Select New Building
+
Location
+ onSelectedLocationChange(o)} + getName={(location) => + location ? location.locationName : "select location" + } + /> + + {location && ( + <> +
Building
+ onSelectedBuildingChange(o)} + getName={(building) => + building ? building.buildingName : "select building" + } + /> + + )} +
+ +
+
+
+ + ); +}; + +export default FloorResourceEditModal; \ No newline at end of file diff --git a/src/deskstar-frontend/components/resources/RoomResourceEditModal.tsx b/src/deskstar-frontend/components/resources/RoomResourceEditModal.tsx new file mode 100644 index 00000000..6348c2b2 --- /dev/null +++ b/src/deskstar-frontend/components/resources/RoomResourceEditModal.tsx @@ -0,0 +1,180 @@ +import { Session } from "next-auth"; +import React, { useState } from "react"; +import { toast } from "react-toastify"; +import { getFloors } from "../../lib/api/ResourceService"; +import { IBuilding } from "../../types/building"; +import { IFloor } from "../../types/floor"; +import { ILocation } from "../../types/location"; +import { IRoom } from "../../types/room"; +import FilterListbox from "../FilterListbox"; +import Input from "../forms/Input"; + +const RoomResourceEditModal = ({ + room, + isOpen, + setState, + origBuildings, + updateRoom, + session, + roomName, + setRoomName, +}: { + room: IRoom | undefined; + isOpen: boolean; + setState: Function; + origBuildings: IBuilding[]; + updateRoom: Function; + session: Session; + roomName: string; + setRoomName: Function; +}) => { + if (!room) return (<>) + const uniqueLocation = (ogBuildings: IBuilding[]) => { + const t = new Map(); + ogBuildings.forEach((element) => + t.set(element.location, { locationName: element.location }) + ); + return Array.from(t.values()); + }; + const [locations, setLocations] = useState( + uniqueLocation(origBuildings) + ); + const [building, setBuilding] = useState(); + const [location, setLocation] = useState(); + const [buildings, setBuildings] = useState([]); + const [floor, setFloor] = useState(); + const [floors, setFloors] = useState([]); + function clearState() { + setLocation(null); + setBuilding(null); + setFloor(null); + } + async function onSelectedLocationChange( + selectedLocation: ILocation | null | undefined + ) { + if (!selectedLocation) { + return; + } + + setLocation(selectedLocation); + let filteredBuildings = origBuildings.filter( + (building) => selectedLocation.locationName === building.location + ); + + setBuildings(filteredBuildings); + setBuilding(null); + setFloor(null); + } + + async function onSelectedBuildingChange( + selectedBuilding: IBuilding | null | undefined + ) { + if (!selectedBuilding) { + return; + } + + setBuilding(selectedBuilding); + if (!session) { + return []; + } + const resFloors = await getFloors(session, selectedBuilding.buildingId); + setFloors(resFloors); + + setFloor(null); + } + + async function onSelectedFloorChange( + selectedFloor: IFloor | null | undefined + ) { + if (!selectedFloor) { + return; + } + + setFloor(selectedFloor); + if (!session) { + return []; + } + } + return ( + <> +
+
+ { clearState(); setState(false); }}> + x + +

Edit Room

+
Change Room Name
+ { + setRoomName(e.target.value); + }} + value={roomName} + placeholder="Room Name" + /> + +
Select New Floor
+
Location
+ onSelectedLocationChange(o)} + getName={(location) => + location ? location.locationName : "select location" + } + /> + + {location && ( + <> +
Building
+ onSelectedBuildingChange(o)} + getName={(building) => + building ? building.buildingName : "select building" + } + /> + + )} + + {building && ( + <> +
Floor
+ onSelectedFloorChange(o)} + getName={(floor) => + floor ? floor.floorName : "select floor" + } + /> + + )} +
+ +
+
+
+ + ); +}; + +export default RoomResourceEditModal; \ No newline at end of file diff --git a/src/deskstar-frontend/lib/api/ResourceService.ts b/src/deskstar-frontend/lib/api/ResourceService.ts index e206db51..20cfafd2 100644 --- a/src/deskstar-frontend/lib/api/ResourceService.ts +++ b/src/deskstar-frontend/lib/api/ResourceService.ts @@ -8,10 +8,15 @@ import { CreateDeskDto } from "../../types/models/CreateDeskDto"; import { CreateDeskTypeDto } from "../../types/models/CreateDeskTypeDto"; import { CreateFloorDto } from "../../types/models/CreateFloorDto"; import { CreateRoomDto } from "../../types/models/CreateRoomDto"; +import { UpdateBuildingDto } from "../../types/models/UpdateBuildingDto"; +import { UpdateDeskDto } from "../../types/models/UpdateDeskDto"; +import { UpdateDeskTypeDto } from "../../types/models/UpdateDeskTypeDto"; +import { UpdateFloorDto } from "../../types/models/UpdateFloorDto"; +import { UpdateRoomDto } from "../../types/models/UpdateRoomDto"; import { IRoom } from "../../types/room"; import { BACKEND_URL } from "./constants"; -export interface ICreateResourceResult { +export interface IResourceResult { response: ResourceResponse; message: string; data?: Object; @@ -96,7 +101,7 @@ export async function getDesks( ): Promise { const response = await fetch( BACKEND_URL + - `/resources/rooms/${roomId}/desks?start=${startTime}&end=${endTime}`, + `/resources/rooms/${roomId}/desks?start=${startTime}&end=${endTime}`, { headers: { Authorization: `Bearer ${session.accessToken}`, @@ -142,7 +147,7 @@ export async function getDeskTypes(session: Session): Promise { export async function createBuilding( session: Session, createBuildingDto: CreateBuildingDto -): Promise { +): Promise { const b = JSON.stringify(createBuildingDto); const response = await fetch(BACKEND_URL + "/resources/buildings", { method: "POST", @@ -153,7 +158,7 @@ export async function createBuilding( body: b, }); - let result: ICreateResourceResult; + let result: IResourceResult; const body = await response.text(); if (response.status !== 200) { @@ -171,11 +176,183 @@ export async function createBuilding( return result; } +export async function updateBuilding( + session: Session, + updateBuildingDto: UpdateBuildingDto, + building: IBuilding +): Promise { + const b = JSON.stringify(updateBuildingDto); + const response = await fetch(BACKEND_URL + "/resources/buildings/" + building.buildingId, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session.accessToken}`, + }, + body: b, + }); + let result: IResourceResult; + const body = await response.text(); + + if (response.status !== 200) { + result = { + response: ResourceResponse.Error, + message: body || "An error occured.", + }; + } else { + console.log(body); + result = { + response: ResourceResponse.Success, + data: JSON.parse(body) as IBuilding, + message: `Success! Updated building '${building.buildingName}'`, + }; + } + + return result; +} +export async function updateFloor( + session: Session, + updateFloorDto: UpdateFloorDto, + floor: IFloor +): Promise { + const b = JSON.stringify(updateFloorDto); + const response = await fetch(BACKEND_URL + "/resources/floors/" + floor.floorId, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session.accessToken}`, + }, + body: b, + }); + let result: IResourceResult; + const body = await response.text(); + + if (response.status !== 200) { + result = { + response: ResourceResponse.Error, + message: body || "An error occured.", + }; + } else { + console.log(body); + result = { + response: ResourceResponse.Success, + data: JSON.parse(body) as IFloor, + message: `Success! Updated floor '${floor.floorName}'`, + }; + } + + return result; +} +export async function updateRoom( + session: Session, + updateRoomDto: UpdateRoomDto, + room: IRoom +): Promise { + const b = JSON.stringify(updateRoomDto); + const response = await fetch(BACKEND_URL + "/resources/rooms/" + room.roomId, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session.accessToken}`, + }, + body: b, + }); + let result: IResourceResult; + const body = await response.text(); + + if (response.status !== 200) { + result = { + response: ResourceResponse.Error, + message: body || "An error occured.", + }; + } else { + console.log(body); + const parsed = JSON.parse(body); + const room = parsed as IRoom; + room.building = parsed["buildingName"]; + room.floor = parsed["floorName"]; + result = { + response: ResourceResponse.Success, + data: room, + message: `Success! Updated room '${room.roomName}'`, + }; + } + + return result; +} +export async function updateDesk( + session: Session, + updateDeskDto: UpdateDeskDto, + desk: IDesk +): Promise { + const b = JSON.stringify(updateDeskDto); + const response = await fetch(BACKEND_URL + "/resources/desks/" + desk.deskId, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session.accessToken}`, + }, + body: b, + }); + let result: IResourceResult; + const body = await response.text(); + + if (response.status !== 200) { + result = { + response: ResourceResponse.Error, + message: body || "An error occured.", + }; + } else { + console.log(body); + const parsed = JSON.parse(body); + const desk = parsed as IDesk; + desk.deskTyp = parsed["deskTypeName"]; + result = { + response: ResourceResponse.Success, + data: desk, + message: `Success! Updated desk '${desk.deskName}'`, + }; + } + + return result; +} +export async function updateDeskType( + session: Session, + updateDeskTypeDto: UpdateDeskTypeDto, + deskType: IDeskType +): Promise { + const b = JSON.stringify(updateDeskTypeDto); + const response = await fetch(BACKEND_URL + "/resources/desktypes/" + deskType.deskTypeId, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session.accessToken}`, + }, + body: b, + }); + let result: IResourceResult; + const body = await response.text(); + + if (response.status !== 200) { + result = { + response: ResourceResponse.Error, + message: body || "An error occured.", + }; + } else { + console.log(body); + result = { + response: ResourceResponse.Success, + data: JSON.parse(body) as IDeskType, + message: `Success! Updated desk type '${deskType.deskTypeName}'`, + }; + } + + return result; +} export async function createFloor( session: Session, createFloorDto: CreateFloorDto -): Promise { +): Promise { const b = JSON.stringify(createFloorDto); const response = await fetch(BACKEND_URL + "/resources/floors", { method: "POST", @@ -186,7 +363,7 @@ export async function createFloor( body: b, }); - let result: ICreateResourceResult; + let result: IResourceResult; const body = await response.text(); if (response.status !== 200) { @@ -208,7 +385,7 @@ export async function createFloor( export async function createRoom( session: Session, createRoomDto: CreateRoomDto -): Promise { +): Promise { const b = JSON.stringify(createRoomDto); const response = await fetch(BACKEND_URL + "/resources/rooms", { method: "POST", @@ -219,7 +396,7 @@ export async function createRoom( body: b, }); - let result: ICreateResourceResult; + let result: IResourceResult; const body = await response.text(); if (response.status !== 200) { @@ -241,7 +418,7 @@ export async function createRoom( export async function createDeskType( session: Session, createDeskTypeDto: CreateDeskTypeDto -): Promise { +): Promise { const b = JSON.stringify(createDeskTypeDto); const response = await fetch(BACKEND_URL + "/resources/desktypes", { method: "POST", @@ -252,7 +429,7 @@ export async function createDeskType( body: b, }); - let result: ICreateResourceResult; + let result: IResourceResult; const body = await response.text(); if (response.status !== 200) { @@ -274,7 +451,7 @@ export async function createDeskType( export async function createDesk( session: Session, createDeskDto: CreateDeskDto -): Promise { +): Promise { const b = JSON.stringify(createDeskDto); const response = await fetch(BACKEND_URL + "/resources/desks", { method: "POST", @@ -285,7 +462,7 @@ export async function createDesk( body: b, }); - let result: ICreateResourceResult; + let result: IResourceResult; const body = await response.text(); if (response.status !== 200) { diff --git a/src/deskstar-frontend/pages/resources/index.tsx b/src/deskstar-frontend/pages/resources/index.tsx index 9a47761e..5184aae2 100644 --- a/src/deskstar-frontend/pages/resources/index.tsx +++ b/src/deskstar-frontend/pages/resources/index.tsx @@ -8,10 +8,15 @@ import { toast } from "react-toastify"; import AddResourceModal from "../../components/AddResourceModal"; import DropDownFilter from "../../components/DropDownFilter"; import FilterListbox from "../../components/FilterListbox"; +import BuildingResourceEditModal from "../../components/resources/BuildingResourceEditModal"; import BuildingResourceTable from "../../components/resources/BuildingResourceTable"; +import DeskResourceEditModal from "../../components/resources/DeskResourceEditModal"; import DeskResourceTable from "../../components/resources/DeskResourceTable"; +import DeskTypeResourceEditModal from "../../components/resources/DeskTypeResourceEditModal"; import DeskTypeResourceTable from "../../components/resources/DeskTypeResourceTable"; +import FloorResourceEditModal from "../../components/resources/FloorResourceEditModal"; import FloorResourceTable from "../../components/resources/FloorResourceTable"; +import RoomResourceEditModal from "../../components/resources/RoomResourceEditModal"; import RoomResourceTable from "../../components/resources/RoomResourceTable"; import { getBuildings, @@ -19,7 +24,13 @@ import { getDeskTypes, getFloors, getRooms, + updateBuilding, + updateDesk, + updateDeskType, + updateFloor, + updateRoom, } from "../../lib/api/ResourceService"; +import { UpdateBuildingDto } from "../../types/models/UpdateBuildingDto"; import { IBuilding } from "../../types/building"; import { IDesk } from "../../types/desk"; import { IDeskType } from "../../types/desktypes"; @@ -27,6 +38,10 @@ import { IFloor } from "../../types/floor"; import { ILocation } from "../../types/location"; import { IRoom } from "../../types/room"; import { authOptions } from "../api/auth/[...nextauth]"; +import { UpdateFloorDto } from "../../types/models/UpdateFloorDto"; +import { UpdateRoomDto } from "../../types/models/UpdateRoomDto"; +import { UpdateDeskTypeDto } from "../../types/models/UpdateDeskTypeDto"; +import { UpdateDeskDto } from "../../types/models/UpdateDeskDto"; const ResourceOverview = ({ buildings: origBuildings, @@ -37,6 +52,7 @@ const ResourceOverview = ({ }) => { let { data: session } = useSession(); + const locations: ILocation[] = origBuildings.map((building) => ({ locationName: building.location, })); @@ -47,7 +63,30 @@ const ResourceOverview = ({ const [floors, setFloors] = useState([]); const [rooms, setRooms] = useState([]); const [desks, setDesks] = useState([]); - const [desktypes, setDeskTypes] = useState([]); + const [deskTypes, setDeskTypes] = useState(origDeskTypes); + + const [editDeskType, setEditDeskType] = useState(); + const [isEditDeskTypeModalOpen, setIsEditDeskTypeModalOpen] = useState(false); + + const [editDesk, setEditDesk] = useState(); + const [isEditDeskModalOpen, setIsEditDeskModalOpen] = useState(false); + + const [editRoom, setEditRoom] = useState(); + const [isEditRoomModalOpen, setIsEditRoomModalOpen] = useState(false); + + const [editFloor, setEditFloor] = useState(); + const [isEditFloorModalOpen, setIsEditFloorModalOpen] = useState(false); + + const [editBuilding, setEditBuilding] = useState(); + const [isEditBuildingModalOpen, setIsEditBuildingModalOpen] = useState(false); + + const [deskTypeNameModal, setDeskTypeNameModal] = useState(""); + const [deskNameModal, setDeskNameModal] = useState(""); + const [roomNameModal, setRoomNameModal] = useState(""); + const [floorNameModal, setFloorNameModal] = useState(""); + const [buildingNameModal, setBuildingNameModal] = useState(""); + const [locationModal, setLocationModal] = useState(""); + const resourceOptions = [ "Buildings", @@ -158,10 +197,111 @@ const ResourceOverview = ({ } }, [router, session]); - const onEdit = async (resource: object): Promise => { - //TODO: Implement - toast.success(`Editing resource...`); + const openDeskTypeEditModal = async (deskType: IDeskType): Promise => { + setDeskTypeNameModal(deskType.deskTypeName) + setEditDeskType(deskType); + setIsEditDeskTypeModalOpen(true); + }; + const openDeskEditModal = async (desk: IDesk): Promise => { + setDeskNameModal(desk.deskName); + setEditDesk(desk); + setIsEditDeskModalOpen(true); + }; + const openRoomEditModal = async (room: IRoom): Promise => { + setRoomNameModal(room.roomName); + setEditRoom(room); + setIsEditRoomModalOpen(true); + }; + const openFloorEditModal = async (floor: IFloor): Promise => { + setFloorNameModal(floor.floorName); + setEditFloor(floor); + setIsEditFloorModalOpen(true); + }; + const openBuildingEditModal = async (building: IBuilding): Promise => { + setEditBuilding(building); + setBuildingNameModal(building.buildingName); + setLocationModal(building.location); + setIsEditBuildingModalOpen(true); + }; + const updateBuildingState = async (building: IBuilding): Promise => { + const i = buildings.findIndex((v, i) => v.buildingId == building.buildingId); + buildings[i] = building; + setBuildings(buildings); + }; + const updateFloorState = async (floor: IFloor): Promise => { + const i = floors.findIndex((v, i) => v.floorId == floor.floorId); + floors[i] = floor; + setFloors(floors); }; + const updateRoomState = async (room: IRoom): Promise => { + const i = rooms.findIndex((v, i) => v.roomId == room.roomId); + rooms[i] = room; + setRooms(rooms); + }; + const updateDeskState = async (desk: IDesk): Promise => { + const i = desks.findIndex((v, i) => v.deskId == desk.deskId); + desks[i] = desk; + setDesks(desks); + }; + const updateDeskTypeState = async (deskType: IDeskType): Promise => { + const i = deskTypes.findIndex((v, i) => v.deskTypeId == deskType.deskTypeId); + deskTypes[i] = deskType; + setDeskTypes(deskTypes); + }; + const updateBuildingInService = async (updateBuildingDto: UpdateBuildingDto, selectedBuilding: IBuilding): Promise => { + if (!session) return; + const result = await updateBuilding(session, updateBuildingDto, selectedBuilding); + setIsEditBuildingModalOpen(false); + showMessageToast(result.message); + if (result.message.includes("Success")) { + const updatedBuilding = result.data as (IBuilding); + updateBuildingState(updatedBuilding); + } + }; + + const updateFloorInService = async (updateFloorDto: UpdateFloorDto, selectedFloor: IFloor): Promise => { + if (!session) return; + const result = await updateFloor(session, updateFloorDto, selectedFloor); + setIsEditFloorModalOpen(false); + showMessageToast(result.message); + if (result.message.includes("Success")) { + const updatedFloor = result.data as (IFloor); + updateFloorState(updatedFloor); + } + }; + const updateRoomInService = async (updateRoomDto: UpdateRoomDto, selectedRoom: IRoom): Promise => { + if (!session) return; + const result = await updateRoom(session, updateRoomDto, selectedRoom); + setIsEditRoomModalOpen(false); + showMessageToast(result.message); + if (result.message.includes("Success")) { + const updatedRoom = result.data as (IRoom); + updateRoomState(updatedRoom); + } + }; + const updateDeskInService = async (updateDeskDto: UpdateDeskDto, selectedDesk: IDesk): Promise => { + if (!session) return; + const result = await updateDesk(session, updateDeskDto, selectedDesk); + setIsEditDeskModalOpen(false); + showMessageToast(result.message); + if (result.message.includes("Success")) { + const updatedDesk = result.data as (IDesk); + updateDeskState(updatedDesk); + } + }; + const updateDeskTypeInService = async (updateDeskTypeDto: UpdateDeskTypeDto, selectedDeskType: IDeskType): Promise => { + if (!session) return; + const result = await updateDeskType(session, updateDeskTypeDto, selectedDeskType); + setIsEditDeskTypeModalOpen(false); + showMessageToast(result.message); + if (result.message.includes("Success")) { + const updatedDeskType = result.data as (IDeskType); + updateDeskTypeState(updatedDeskType); + } + }; + const showMessageToast = (message: string): void => { + message.includes("Success") ? toast.success(message) : toast.warn(message); + } const onDelete = async (resource: object): Promise => { //TODO: Implement @@ -172,7 +312,7 @@ const ResourceOverview = ({ if (resourceName == null) return -1; return resourceOptions.findIndex((v, i, obj) => resourceName === v); }; - + if (!session) return (<>) return ( <> {isFetching && ( @@ -204,7 +344,7 @@ const ResourceOverview = ({ href="#create-resource-modal" type="button" className="btn text-black btn-secondary bg-deskstar-green-dark hover:bg-deskstar-green-light border-deskstar-green-dark hover:border-deskstar-green-light ml-2" - onClick={() => {}} + onClick={() => { }} > Add Resource @@ -260,46 +400,50 @@ const ResourceOverview = ({ )} {selectedResourceOption === "Desk types" && ( <> - {origDeskTypes.length > 0 && ( + {deskTypes.length > 0 && ( )} + )} {selectedResourceOption === "Desks" && ( <> {desks.length > 0 && ( )} + )} {selectedResourceOption === "Rooms" && ( <> {rooms.length > 0 && ( )} + )} {selectedResourceOption === "Floors" && ( <> {floors.length > 0 && ( )} + )} @@ -307,11 +451,12 @@ const ResourceOverview = ({ <> {buildings.length > 0 && ( )} + )} diff --git a/src/deskstar-frontend/types/models/UpdateBuildingDto.ts b/src/deskstar-frontend/types/models/UpdateBuildingDto.ts new file mode 100644 index 00000000..c781eb0b --- /dev/null +++ b/src/deskstar-frontend/types/models/UpdateBuildingDto.ts @@ -0,0 +1,4 @@ +export type UpdateBuildingDto = { + buildingName: string | undefined; + location: string | undefined; +}; \ No newline at end of file diff --git a/src/deskstar-frontend/types/models/UpdateDeskDto.ts b/src/deskstar-frontend/types/models/UpdateDeskDto.ts new file mode 100644 index 00000000..901fc77b --- /dev/null +++ b/src/deskstar-frontend/types/models/UpdateDeskDto.ts @@ -0,0 +1,5 @@ +export type UpdateDeskDto = { + deskName: string | undefined; + roomId: string | undefined; + deskTypeId: string | undefined; +}; \ No newline at end of file diff --git a/src/deskstar-frontend/types/models/UpdateDeskTypeDto.ts b/src/deskstar-frontend/types/models/UpdateDeskTypeDto.ts new file mode 100644 index 00000000..82207b48 --- /dev/null +++ b/src/deskstar-frontend/types/models/UpdateDeskTypeDto.ts @@ -0,0 +1,3 @@ +export type UpdateDeskTypeDto = { + deskTypeName: string | undefined; +}; \ No newline at end of file diff --git a/src/deskstar-frontend/types/models/UpdateFloorDto.ts b/src/deskstar-frontend/types/models/UpdateFloorDto.ts new file mode 100644 index 00000000..9b119579 --- /dev/null +++ b/src/deskstar-frontend/types/models/UpdateFloorDto.ts @@ -0,0 +1,4 @@ +export type UpdateFloorDto = { + floorName: string | undefined; + buildingId: string | undefined; +}; \ No newline at end of file diff --git a/src/deskstar-frontend/types/models/UpdateRoomDto.ts b/src/deskstar-frontend/types/models/UpdateRoomDto.ts new file mode 100644 index 00000000..0ad26886 --- /dev/null +++ b/src/deskstar-frontend/types/models/UpdateRoomDto.ts @@ -0,0 +1,4 @@ +export type UpdateRoomDto = { + roomName: string | undefined; + floorId: string | undefined; +}; \ No newline at end of file