diff --git a/src/deskstar-backend/Deskstar/Controllers/ResourcesController.cs b/src/deskstar-backend/Deskstar/Controllers/ResourcesController.cs index db8dcbe6..7a8bfd63 100644 --- a/src/deskstar-backend/Deskstar/Controllers/ResourcesController.cs +++ b/src/deskstar-backend/Deskstar/Controllers/ResourcesController.cs @@ -3,6 +3,8 @@ using Deskstar.Usecases; using Deskstar.Models; using Deskstar.Core; +using Deskstar.Entities; +using Deskstar.Core.Exceptions; namespace Deskstar.Controllers; @@ -12,12 +14,17 @@ namespace Deskstar.Controllers; public class ResourcesController : ControllerBase { private readonly IResourceUsecases _resourceUsecases; + private readonly IUserUsecases _userUsecases; private readonly ILogger _logger; - public ResourcesController(ILogger logger, IResourceUsecases resourceUsecases) + private readonly AutoMapper.IMapper _mapper; + + public ResourcesController(ILogger logger, IResourceUsecases resourceUsecases, IUserUsecases userUsecases, IAutoMapperConfiguration autoMapperConfiguration) { _logger = logger; _resourceUsecases = resourceUsecases; + _userUsecases = userUsecases; + _mapper = autoMapperConfiguration.GetConfiguration().CreateMapper(); } /// @@ -30,6 +37,7 @@ public ResourcesController(ILogger logger, IResourceUsecase /// /// /// Returns the buildings list + /// Bad Request /// Internal Server Error [HttpGet("buildings")] [Authorize] @@ -60,17 +68,43 @@ public IActionResult GetAllBuildings() /// POST /resources/buildings with JWT-Admin Token /// /// - /// + /// CreateBuildingResponseObject + /// Bad Request + /// Not Found /// Internal Server Error [HttpPost("buildings")] [Authorize(Policy = "Admin")] - [ProducesResponseType(StatusCodes.Status201Created)] - [ProducesResponseType(StatusCodes.Status409Conflict)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] [Produces("application/json")] - public IActionResult CreateBuilding(string buildingId) + public IActionResult CreateBuilding(CreateBuildingDto buildingDto) { - return Problem(statusCode: 501); + var adminId = RequestInteractions.ExtractIdFromRequest(Request); + + try + { + var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId; + var building = _resourceUsecases.CreateBuilding(buildingDto.BuildingName, buildingDto.Location, companyId); + var resultBuilding = _mapper.Map(building); + return Ok(resultBuilding); + } + catch (EntityNotFoundException e) + { + _logger.LogError(e, e.Message); + return NotFound(e.Message); + } + catch (Exception e) when (e is ArgumentInvalidException or ArgumentNullException or FormatException or OverflowException) + { + _logger.LogError(e, e.Message); + return BadRequest(e.Message); + } + catch (Exception e) + { + _logger.LogError(e, e.Message); + return Problem(statusCode: 500); + } } /// @@ -81,8 +115,8 @@ public IActionResult CreateBuilding(string buildingId) /// DELETE /resources/buildings/3de7afbf-0289-4ba6-bada-a34353c5548a with JWT-Admin Token /// /// - /// - /// Internal Server Error + /// Bad Request + /// Not Implemented [HttpDelete("buildings/{buildingId}")] [Authorize(Policy = "Admin")] [ProducesResponseType(StatusCodes.Status205ResetContent)] @@ -104,6 +138,7 @@ public IActionResult DeleteBuilding(string buildingId) /// /// /// Returns the floor list + /// Bad Request /// Internal Server Error [HttpGet("buildings/{buildingId}/floors")] [Authorize] @@ -133,8 +168,9 @@ public IActionResult GetFloorsByBuildingId(string buildingId) /// POST /resources/floors with JWT-Admin Token /// /// - /// - /// + /// CreateFloorResponseObject + /// Bad Request + /// Not Found /// Internal Server Error [HttpPost("floors")] [Authorize(Policy = "Admin")] @@ -142,9 +178,32 @@ public IActionResult GetFloorsByBuildingId(string buildingId) [ProducesResponseType(StatusCodes.Status409Conflict)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] [Produces("application/json")] - public IActionResult CreateFloor(CurrentFloor newFloor) + public IActionResult CreateFloor(CreateFloorDto floorDto) { - return Problem(statusCode: 501); + var adminId = RequestInteractions.ExtractIdFromRequest(Request); + + try + { + var buildingId = new Guid(floorDto.BuildingId); + var floor = _resourceUsecases.CreateFloor(floorDto.FloorName, buildingId); + var resultFloor = _mapper.Map(floor); + return Ok(resultFloor); + } + catch (EntityNotFoundException e) + { + _logger.LogError(e, e.Message); + return NotFound(e.Message); + } + catch (Exception e) when (e is ArgumentInvalidException or ArgumentNullException or FormatException or OverflowException) + { + _logger.LogError(e, e.Message); + return BadRequest(e.Message); + } + catch (Exception e) + { + _logger.LogError(e, e.Message); + return Problem(statusCode: 500); + } } /// @@ -155,8 +214,8 @@ public IActionResult CreateFloor(CurrentFloor newFloor) /// DELETE /resources/floors/3de7afbf-0289-4ba6-bada-a34353c5548a with JWT-Admin Token /// /// - /// - /// Internal Server Error + /// Bad Request + /// Not Impelemented [HttpDelete("floors/{floorId}")] [Authorize(Policy = "Admin")] [ProducesResponseType(StatusCodes.Status205ResetContent)] @@ -177,6 +236,7 @@ public IActionResult DeleteFloor(string floorId) /// /// /// Returns the rooms list + /// Bad Request /// Internal Server Error [HttpGet("floors/{floorId}/rooms")] [Authorize] @@ -206,18 +266,43 @@ public IActionResult GetRoomsByFloorId(string floorId) /// POST /resources/rooms with JWT-Admin Token /// /// - /// - /// + /// CreateRoomResponseObject + /// Bad Request + /// Not Found /// Internal Server Error [HttpPost("rooms")] [Authorize(Policy = "Admin")] - [ProducesResponseType(StatusCodes.Status201Created)] - [ProducesResponseType(StatusCodes.Status409Conflict)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] [Produces("application/json")] - public IActionResult CreateRoom(CurrentRoom newRoom) + public IActionResult CreateRoom(CreateRoomDto roomDto) { - return Problem(statusCode: 501); + var adminId = RequestInteractions.ExtractIdFromRequest(Request); + + try + { + var floorId = new Guid(roomDto.FloorId); + var room = _resourceUsecases.CreateRoom(roomDto.RoomName, floorId); + var resultRoom = _mapper.Map(room); + return Ok(resultRoom); + } + catch (EntityNotFoundException e) + { + _logger.LogError(e, e.Message); + return NotFound(e.Message); + } + catch (Exception e) when (e is ArgumentInvalidException or ArgumentNullException or FormatException or OverflowException) + { + _logger.LogError(e, e.Message); + return BadRequest(e.Message); + } + catch (Exception e) + { + _logger.LogError(e, e.Message); + return Problem(statusCode: 500); + } } /// @@ -228,8 +313,8 @@ public IActionResult CreateRoom(CurrentRoom newRoom) /// DELETE /resources/rooms/3de7afbf-0289-4ba6-bada-a34353c5548a with JWT-Admin Token /// /// - /// - /// Internal Server Error + /// Bad Request + /// Not Implemented [HttpDelete("rooms/{roomId}")] [Authorize(Policy = "Admin")] [ProducesResponseType(StatusCodes.Status205ResetContent)] @@ -251,6 +336,7 @@ public IActionResult DeleteRoom(string roomId) /// /// /// Returns the desks list + /// Bad Request /// Internal Server Error [HttpGet("rooms/{roomId}/desks")] [Authorize] @@ -285,6 +371,7 @@ public IActionResult GetDesksByRoomId(string roomId, long start = 0, long end = /// /// /// Returns the buildings list + /// Bad Request /// Internal Server Error [HttpGet("desks/{deskId}")] [Authorize] @@ -337,18 +424,44 @@ public IActionResult GetDeskDetailsByDeskId(string deskId, long start = 0, long /// POST /resources/desks with JWT-Admin Token /// /// - /// - /// + /// CreateDeskResponseObject + /// Bad Request + /// Not Found /// Internal Server Error [HttpPost("desks")] [Authorize(Policy = "Admin")] - [ProducesResponseType(StatusCodes.Status201Created)] - [ProducesResponseType(StatusCodes.Status409Conflict)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] [Produces("application/json")] - public IActionResult CreateDesk(CurrentDesk newDesk) + public IActionResult CreateDesk(CreateDeskDto deskDto) { - return Problem(statusCode: 501); + var adminId = RequestInteractions.ExtractIdFromRequest(Request); + + try + { + var deskTypeId = new Guid(deskDto.DeskTypeId); + var roomId = new Guid(deskDto.RoomId); + var desk = _resourceUsecases.CreateDesk(deskDto.DeskName, deskTypeId, roomId); + var resultDesk = _mapper.Map(desk); + return Ok(resultDesk); + } + catch (EntityNotFoundException e) + { + _logger.LogError(e, e.Message); + return NotFound(e.Message); + } + catch (Exception e) when (e is ArgumentInvalidException or ArgumentNullException or FormatException or OverflowException) + { + _logger.LogError(e, e.Message); + return BadRequest(e.Message); + } + catch (Exception e) + { + _logger.LogError(e, e.Message); + return Problem(statusCode: 500); + } } /// @@ -359,8 +472,8 @@ public IActionResult CreateDesk(CurrentDesk newDesk) /// DELETE /resources/desks/3de7afbf-0289-4ba6-bada-a34353c5548a with JWT-Admin Token /// /// - /// - /// Internal Server Error + /// Bad Request + /// Not Implemented [HttpDelete("desks/{deskId}")] [Authorize(Policy = "Admin")] [ProducesResponseType(StatusCodes.Status205ResetContent)] @@ -370,4 +483,71 @@ public IActionResult DeleteDesk(string deskId) { return Problem(statusCode: 501); } + + /// + /// Creates a new DeskType. + /// + /// + /// Sample request: + /// POST /resources/desktypes with JWT-Admin Token + /// + /// + /// CreateDeskTypeResponseObject + /// Bad Request + /// Internal Server Error + [HttpPost("desktypes")] + [Authorize(Policy = "Admin")] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [Produces("application/json")] + public IActionResult CreateDeskType(CreateDeskTypeDto deskTypeDto) + { + var adminId = RequestInteractions.ExtractIdFromRequest(Request); + try + { + var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId; + var deskType = _resourceUsecases.CreateDeskType(deskTypeDto.DeskTypeName, companyId); + var resultDeskType = _mapper.Map(deskType); + return Ok(resultDeskType); + } + catch (Exception e) + { + _logger.LogError(e, e.Message); + return Problem(statusCode: 500); + } + } + /// + /// Return a list of desk types + /// + /// + /// Sample request: + /// Get /resources/desktypes with JWT-Admin Token + /// + /// + /// List + /// Bad Request + /// Internal Server Error + [HttpGet("desktypes")] + [Authorize(Policy = "Admin")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [Produces("application/json")] + public IActionResult ReadDeskTypes() + { + var adminId = RequestInteractions.ExtractIdFromRequest(Request); + + try + { + var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId; + var entities = _resourceUsecases.GetDeskTypes(companyId); + var deskTypes = entities.Select(desktype => _mapper.Map(desktype)).ToList(); + return Ok(deskTypes); + } + catch (Exception e) + { + _logger.LogError(e, e.Message); + return Problem(statusCode: 500); + } + } } \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/AutoMapperConfiguration.cs b/src/deskstar-backend/Deskstar/Models/AutoMapperConfiguration.cs index 7b0d3725..4d7ace30 100644 --- a/src/deskstar-backend/Deskstar/Models/AutoMapperConfiguration.cs +++ b/src/deskstar-backend/Deskstar/Models/AutoMapperConfiguration.cs @@ -15,6 +15,13 @@ public MapperConfiguration GetConfiguration() { 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; } diff --git a/src/deskstar-backend/Deskstar/Models/CreateResources/CreateBuildingDto.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateBuildingDto.cs new file mode 100644 index 00000000..6b411466 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateBuildingDto.cs @@ -0,0 +1,12 @@ +using System.ComponentModel.DataAnnotations; + +namespace Deskstar.Models; + +public class CreateBuildingDto +{ + [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/CreateResources/CreateBuildingResponseObject.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateBuildingResponseObject.cs new file mode 100644 index 00000000..35be874b --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateBuildingResponseObject.cs @@ -0,0 +1,17 @@ +using AutoMapper; + +namespace Deskstar.Models; + +public class CreateBuildingResponseObject +{ + public CreateBuildingResponseObject() { } + + 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!; +} diff --git a/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskDto.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskDto.cs new file mode 100644 index 00000000..97675a92 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskDto.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace Deskstar.Models; + +public class CreateDeskDto +{ + [Required] + public string RoomId { get; set; } = null!; + + [Required] + public string DeskName { get; set; } = null!; + + [Required] + public string DeskTypeId { get; set; } = null!; +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskResponseObject.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskResponseObject.cs new file mode 100644 index 00000000..d1d4bcd7 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskResponseObject.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using AutoMapper; + +namespace Deskstar.Models; + +public class CreateDeskResponseObject +{ + public CreateDeskResponseObject() { } + + public static void createMappings(IMapperConfigurationExpression cfg) + { + cfg.CreateMap(); + } + + [Required] + public string DeskId { get; set; } = null!; + + [Required] + public string DeskName { get; set; } = null!; +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskTypeDto.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskTypeDto.cs new file mode 100644 index 00000000..ea838b2e --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskTypeDto.cs @@ -0,0 +1,12 @@ +using System.ComponentModel.DataAnnotations; + +namespace Deskstar.Models; + +public class CreateDeskTypeDto +{ + public CreateDeskTypeDto() { } + + [Required] + public string DeskTypeName { get; set; } = null!; + +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskTypeResponseObject.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskTypeResponseObject.cs new file mode 100644 index 00000000..0ac38f56 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateDeskTypeResponseObject.cs @@ -0,0 +1,21 @@ +using System.ComponentModel.DataAnnotations; +using AutoMapper; + +namespace Deskstar.Models; + +public class CreateDeskTypeResponseObject +{ + public CreateDeskTypeResponseObject() { } + + 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/CreateResources/CreateFloorDto.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateFloorDto.cs new file mode 100644 index 00000000..a0b6f9e1 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateFloorDto.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace Deskstar.Models; + +public class CreateFloorDto +{ + public CreateFloorDto() { } + + [Required] + public string BuildingId { get; set; } = null!; + + [Required] + public string FloorName { get; set; } = null!; +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/CreateResources/CreateFloorResponseObject.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateFloorResponseObject.cs new file mode 100644 index 00000000..071956e9 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateFloorResponseObject.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using AutoMapper; + +namespace Deskstar.Models; + +public class CreateFloorResponseObject +{ + public CreateFloorResponseObject() { } + + public static void createMappings(IMapperConfigurationExpression cfg) + { + cfg.CreateMap(); + } + + [Required] + public Guid FloorId { get; set; } + + [Required] + public string FloorName { get; set; } = null!; +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/CreateResources/CreateRoomDto.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateRoomDto.cs new file mode 100644 index 00000000..91dc4093 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateRoomDto.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace Deskstar.Models; + +public class CreateRoomDto +{ + public CreateRoomDto() { } + + [Required] + public string FloorId { get; set; } = null!; + + [Required] + public string RoomName { get; set; } = null!; +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/CreateResources/CreateRoomResponseObject.cs b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateRoomResponseObject.cs new file mode 100644 index 00000000..b7a97d81 --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/CreateResources/CreateRoomResponseObject.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using AutoMapper; + +namespace Deskstar.Models; + +public class CreateRoomResponseObject +{ + public CreateRoomResponseObject() { } + + public static void createMappings(IMapperConfigurationExpression cfg) + { + cfg.CreateMap(); + } + + [Required] + public Guid RoomId { get; set; } + + [Required] + public string RoomName { get; set; } = null!; +} \ No newline at end of file diff --git a/src/deskstar-backend/Deskstar/Models/CurrentFloor.cs b/src/deskstar-backend/Deskstar/Models/CurrentFloor.cs index 4e280b81..fc1a84d6 100644 --- a/src/deskstar-backend/Deskstar/Models/CurrentFloor.cs +++ b/src/deskstar-backend/Deskstar/Models/CurrentFloor.cs @@ -5,7 +5,7 @@ namespace Deskstar.Models; public class CurrentFloor { [Required] - public string FloorID { get; set; } = null!; + public string FloorId { get; set; } = null!; [Required] public string FloorName { get; set; } = null!; diff --git a/src/deskstar-backend/Deskstar/Models/DeskTypeDto.cs b/src/deskstar-backend/Deskstar/Models/DeskTypeDto.cs new file mode 100644 index 00000000..263554ff --- /dev/null +++ b/src/deskstar-backend/Deskstar/Models/DeskTypeDto.cs @@ -0,0 +1,23 @@ +using AutoMapper; + +namespace Deskstar.Models; + +public class DeskTypeDto +{ + public static readonly UserProfileDto Null = new UserProfileDto(); + + public DeskTypeDto() + { + + } + + public static void createMappings(IMapperConfigurationExpression cfg) + { + cfg.CreateMap(); + cfg.CreateMap(); + } + + public Guid DeskTypeId { get; set; } + public string DeskTypeName { get; set; } = null!; + public Guid CompanyId { get; set; } +} \ 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 748df4ef..8742dd9b 100644 --- a/src/deskstar-backend/Deskstar/Usecases/ResourceUsecases.cs +++ b/src/deskstar-backend/Deskstar/Usecases/ResourceUsecases.cs @@ -1,3 +1,4 @@ +using Deskstar.Core.Exceptions; using Deskstar.DataAccess; using Deskstar.Entities; using Deskstar.Models; @@ -6,11 +7,18 @@ namespace Deskstar.Usecases; public interface IResourceUsecases { + public List GetDeskTypes(Guid companyId); public List GetBuildings(Guid userId); public List GetFloors(Guid buildingId); public List GetRooms(Guid floorId); public List GetDesks(Guid roomId, DateTime start, DateTime end); public CurrentDesk GetDesk(Guid deskId, DateTime startDateTime, DateTime endDateTime); + + public Desk CreateDesk(string deskName, Guid deskTypeId, Guid roomId); + public DeskType CreateDeskType(string deskTypeName, Guid companyId); + public Room CreateRoom(string roomName, Guid floorId); + public Floor CreateFloor(string floorName, Guid buildingId); + public Building CreateBuilding(string buildingName, string location, Guid companyId); } public class ResourceUsecases : IResourceUsecases @@ -18,15 +26,18 @@ public class ResourceUsecases : IResourceUsecases private readonly DataContext _context; private readonly ILogger _logger; - public ResourceUsecases(ILogger logger, DataContext context) + private readonly IUserUsecases _userUsecases; + + public ResourceUsecases(ILogger logger, DataContext context, IUserUsecases userUsecases) { _logger = logger; _context = context; + _userUsecases = userUsecases; } public List GetBuildings(Guid userId) { - + IQueryable databaseBuildings; try { @@ -64,7 +75,7 @@ public List GetFloors(Guid buildingId) if (databaseFloors.ToList().Count == 0) { var databaseBuilding = _context.Buildings.First(building => building.BuildingId == buildingId); - if( databaseBuilding== null) throw new ArgumentException($"There is no Building with id '{buildingId}'"); + if (databaseBuilding == null) throw new ArgumentException($"There is no Building with id '{buildingId}'"); } } catch (Exception e) when (e is FormatException or ArgumentNullException or OverflowException) @@ -83,7 +94,7 @@ public List GetFloors(Guid buildingId) { BuildingName = f.Building.BuildingName, FloorName = f.FloorName, - FloorID = f.FloorId.ToString() + FloorId = f.FloorId.ToString() }); return mapFloorsToCurrentFloors.ToList(); @@ -126,7 +137,7 @@ public List GetDesks(Guid roomId, DateTime start, DateTime end) if (databaseDesks.ToList().Count == 0) { var databaseRoom = _context.Rooms.First(room => room.RoomId == roomId); - if( databaseRoom== null) throw new ArgumentException($"There is no Room with id '{roomId}'"); + if (databaseRoom == null) throw new ArgumentException($"There is no Room with id '{roomId}'"); } mapDesksToCurrentDesks = databaseDesks.Select(desk => new CurrentDesk { @@ -205,4 +216,148 @@ public CurrentDesk GetDesk(Guid deskId, DateTime startDateTime, DateTime endDate return mapDeskToCurrentDesk; } + + public List GetDeskTypes(Guid companyId) + { + return _context.DeskTypes.Where(d => d.CompanyId == companyId).ToList(); + } + + public Desk CreateDesk(string deskName, Guid deskTypeId, Guid roomId) + { + var desktype = _context.DeskTypes.SingleOrDefault(dt => dt.DeskTypeId == deskTypeId); + if (desktype == null) + throw new EntityNotFoundException($"There is no desk type with id '{deskTypeId}'"); + + var room = _context.Rooms.SingleOrDefault(r => r.RoomId == roomId); + if (room == null) + throw new EntityNotFoundException($"There is no room with id '{roomId}'"); + + if (deskName == "") + throw new ArgumentInvalidException($"'{deskName}' is not a valid name of a desk"); + var deskNameExists = _context.Desks.SingleOrDefault(d => d.RoomId == roomId && d.DeskName == deskName) != null; + if (deskNameExists) + throw new ArgumentInvalidException($"In this room there is already a desk named '{deskName}'"); + + var deskId = Guid.NewGuid(); + var desk = new Desk + { + DeskId = deskId, + DeskName = deskName, + DeskTypeId = deskTypeId, + RoomId = roomId + }; + + _context.Desks.Add(desk); + _context.SaveChanges(); + + return desk; + } + + public DeskType CreateDeskType(string deskTypeName, Guid companyId) + { + var company = _context.Companies.SingleOrDefault(c => c.CompanyId == companyId); + if (company == null) + throw new EntityNotFoundException($"There is no company with id '{companyId}'"); + + if (deskTypeName == "") + throw new ArgumentInvalidException($"'{deskTypeName}' is not a valid name for a desk type'"); + var deskTypeExists = _context.DeskTypes.SingleOrDefault(dt => dt.CompanyId == companyId && dt.DeskTypeName == deskTypeName) != null; + if (deskTypeExists) + throw new ArgumentInvalidException($"There is already a deskType called '{deskTypeName}'"); + + var deskTypeId = Guid.NewGuid(); + var deskType = new DeskType + { + DeskTypeId = deskTypeId, + DeskTypeName = deskTypeName, + CompanyId = companyId + }; + + _context.DeskTypes.Add(deskType); + _context.SaveChanges(); + + return deskType; + } + + public Room CreateRoom(string roomName, Guid floorId) + { + var floor = _context.Floors.SingleOrDefault(f => f.FloorId == floorId); + if (floor == null) + throw new EntityNotFoundException($"There is no floor with id '{floorId}'"); + + if (roomName == "") + throw new ArgumentInvalidException($"'{roomName}' is not a valid name for a room'"); + var roomNameExists = _context.Rooms.SingleOrDefault(r => r.FloorId == floorId && r.RoomName == roomName) != null; + if (roomNameExists) + throw new ArgumentInvalidException($"There is already a room called '{roomName}'"); + + var roomId = Guid.NewGuid(); + var room = new Room + { + RoomId = roomId, + RoomName = roomName, + FloorId = floorId + }; + + _context.Rooms.Add(room); + _context.SaveChanges(); + + return room; + } + + public Floor CreateFloor(string floorName, Guid buildingId) + { + var building = _context.Buildings.SingleOrDefault(b => b.BuildingId == buildingId); + if (building == null) + throw new EntityNotFoundException($"There is no building with id 'buildingId'"); + + if (floorName == "") + throw new ArgumentInvalidException($"'{floorName}' is not a valid name for a floor"); + var floorNameExists = _context.Floors.SingleOrDefault(f => f.BuildingId == buildingId && f.FloorName == floorName) != null; + if (floorNameExists) + throw new ArgumentInvalidException($"There is already a floor called '{floorName}'"); + + var floorId = Guid.NewGuid(); + var floor = new Floor + { + FloorId = floorId, + FloorName = floorName, + BuildingId = buildingId + }; + + _context.Floors.Add(floor); + _context.SaveChanges(); + + return floor; + } + + public Building CreateBuilding(string buildingName, string location, Guid companyId) + { + var company = _context.Companies.SingleOrDefault(c => c.CompanyId == companyId); + if (company == null) + throw new EntityNotFoundException($"There is no company with id '{companyId}'"); + + if (location == "") + throw new ArgumentInvalidException($"'{location}' is not a valid name for a building'"); + + if (buildingName == "") + throw new ArgumentInvalidException($"'{buildingName}' is not a valid name for a building'"); + var buildingExists = _context.Buildings.SingleOrDefault(b => b.CompanyId == companyId && b.BuildingName == buildingName) != null; + if (buildingExists) + throw new ArgumentInvalidException($"There is already a building with the name '{buildingName}'"); + + var buildingId = Guid.NewGuid(); + var building = new Building + { + BuildingId = buildingId, + BuildingName = buildingName, + Location = location, + CompanyId = companyId + }; + + _context.Buildings.Add(building); + _context.SaveChanges(); + + return building; + } } \ No newline at end of file diff --git a/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecaseTests.cs b/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecaseTests.cs index 3a2bc0ed..a901d596 100644 --- a/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecaseTests.cs +++ b/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecaseTests.cs @@ -1,4 +1,5 @@ -using Deskstar.DataAccess; +using Deskstar.Core.Exceptions; +using Deskstar.DataAccess; using Deskstar.Entities; using Deskstar.Usecases; using Microsoft.AspNetCore.Identity; @@ -39,7 +40,7 @@ public void GetBuildings_WhenNoBuildingFound_ShouldReturnAEmptyList() //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); //act @@ -65,7 +66,7 @@ public void GetBuildings_WhenOneBuildingFound_ShouldReturnAException() //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); var callId = Guid.NewGuid(); //act @@ -116,7 +117,7 @@ public void GetFloors_WhenNoFloorFound_ShouldReturnAEmptyList() //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); //act @@ -142,9 +143,9 @@ public void GetFloors_WhenBuildingNotExsits_ShouldReturnAException() //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); var callId = Guid.NewGuid(); - + //act try { @@ -218,7 +219,7 @@ public void GetDesks_WhenNoDeskFound_ShouldReturnAEmptyList() //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); //act @@ -246,7 +247,7 @@ public void GetDesks_WhenOneDeskFound_ShouldReturnAException() //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); var callId = Guid.NewGuid(); //act @@ -293,7 +294,7 @@ public void GetDesks_WhenDeskIsFound_StartBevoreEndIn_ShouldReturnACurrentsDeskL //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); //act @@ -325,7 +326,7 @@ public void GetDesks_WhenDeskIsFound_StartBevoreEndIn_ShouldReturnACurrentsDeskL //cleanup db.Database.EnsureDeleted(); } - + [Test] public void GetDesks_WhenDeskIsFound_StartInEndBevore_ShouldReturnACurrentsDeskList() { @@ -353,7 +354,7 @@ public void GetDesks_WhenDeskIsFound_StartInEndBevore_ShouldReturnACurrentsDeskL //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); //act @@ -385,7 +386,7 @@ public void GetDesks_WhenDeskIsFound_StartInEndBevore_ShouldReturnACurrentsDeskL //cleanup db.Database.EnsureDeleted(); } - + [Test] public void GetDesks_WhenDeskIsFound_SameStartAndEndTime_ShouldReturnACurrentsDeskList() { @@ -413,7 +414,7 @@ public void GetDesks_WhenDeskIsFound_SameStartAndEndTime_ShouldReturnACurrentsDe //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); //act @@ -462,7 +463,7 @@ public void GetDesk_WhenDeskNotFound_ShouldThrowAnException() //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); var callId = Guid.NewGuid(); //act @@ -508,7 +509,7 @@ public void GetDesk_WhenDeskIsFound_ShouldReturnCurrentDeskObject() //arrange var logger = new Mock>(); - var usecases = new ResourceUsecases(logger.Object, db); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); //act @@ -536,6 +537,563 @@ public void GetDesk_WhenDeskIsFound_ShouldReturnCurrentDeskObject() db.Database.EnsureDeleted(); } + [Test] + public void GetDeskTypes_WhenDeskTypeIsFound_ShouldReturnDeskTypes() + { + //setup + using var db = new DataContext(); + + var companyId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + SetupMockData(db, deskTypeId: deskTypeId, companyId: companyId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + + + //act + var result = usecases.GetDeskTypes(companyId); + + //assert + Assert.That(result, Is.Not.Empty); + Assert.That(result[0].DeskTypeId == deskTypeId); + Assert.That(result[0].CompanyId == companyId); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void GetDeskTypes_WhenCompanyHasNoDeskTypes_ShouldReturnEmptyList() + { + //setup + using var db = new DataContext(); + + var companyId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + SetupMockData(db, deskTypeId: deskTypeId, companyId: companyId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + + + //act + var result = usecases.GetDeskTypes(new Guid()); + + //assert + Assert.That(result, Is.Empty); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateDesk_WhenValidDeskTypeAndRoomId_ShouldAddDeskAndReturnItsGuid() + { + //setup + using var db = new DataContext(); + + var companyId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + var roomId = Guid.NewGuid(); + SetupMockData(db, deskTypeId: deskTypeId, companyId: companyId, roomId: roomId); + + db.SaveChanges(); + + //arrange + var deskName = "validDeskName"; + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + + + //act + var result = usecases.CreateDesk(deskName, deskTypeId, roomId); + + //assert + Assert.That(result != null); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateDesk_WhenDuplicatedNameIsProvided_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + + var companyId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + var roomId = Guid.NewGuid(); + SetupMockData(db, deskTypeId: deskTypeId, companyId: companyId, roomId: roomId); + + db.SaveChanges(); + + //arrange + var duplicated = "Desk1"; + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + + //act+assert + Assert.Throws(() => usecases.CreateDesk(duplicated, deskTypeId, roomId)); + + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateDesk_WhenNoNameIsProvided_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + + var companyId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + var roomId = Guid.NewGuid(); + SetupMockData(db, deskTypeId: deskTypeId, companyId: companyId, roomId: roomId); + + db.SaveChanges(); + + //arrange + var noDeskName = ""; + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + + //act+assert + Assert.Throws(() => usecases.CreateDesk(noDeskName, deskTypeId, roomId)); + + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateDesk_WhenInvalidDeskType_ShouldThrowEntityNotFoundException() + { + //setup + using var db = new DataContext(); + + var companyId = Guid.NewGuid(); + var invalidDeskTypeId = Guid.NewGuid(); + var roomId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId, roomId: roomId); + + db.SaveChanges(); + + //arrange + var deskName = "validDeskName"; + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + + //act+assert + Assert.Throws(() => usecases.CreateDesk(deskName, invalidDeskTypeId, roomId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateDesk_WhenInvalidRoomId_ShouldThrowEntityNotFoundException() + { + //setup + using var db = new DataContext(); + + var companyId = Guid.NewGuid(); + var deskTypeId = Guid.NewGuid(); + var invalidRoomId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId, deskTypeId: deskTypeId); + + db.SaveChanges(); + + //arrange + var deskName = "validDeskName"; + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + + //act+assert + Assert.Throws(() => usecases.CreateDesk(deskName, deskTypeId, invalidRoomId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateDeskType_WhenInvalidCompanyIdIsProvided_ShouldThrowEntitiyNotFoundException() + { + //setup + using var db = new DataContext(); + SetupMockData(db); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var deskTypeName = "validDeskName"; + var invalidCompanyId = Guid.NewGuid(); + + //act+assert + Assert.Throws(() => usecases.CreateDeskType(deskTypeName, invalidCompanyId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateDeskType_WhenNoDeskTypeNameIsProvided_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var noDeskTypeName = ""; + + //act+assert + Assert.Throws(() => usecases.CreateDeskType(noDeskTypeName, companyId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateDeskType_WhenDeskTypeAlreadyExists_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var duplicateName = "Typ1"; + + //act+assert + Assert.Throws(() => usecases.CreateDeskType(duplicateName, companyId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateDeskType_WhenValidArgumentsProvided_ShouldCreateDeskType() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var deskTypeName = "ValidName"; + + //act+assert + Assert.DoesNotThrow(() => usecases.CreateDeskType(deskTypeName, companyId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateRoom_WhenInvalidFloorIdIsProvided_ShouldThrowEntitiyNotFoundException() + { + //setup + using var db = new DataContext(); + SetupMockData(db); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var roomName = "validRoomName"; + var invalidFloorId = Guid.NewGuid(); + + //act+assert + Assert.Throws(() => usecases.CreateRoom(roomName, invalidFloorId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateRoom_WhenNoRoomNameIsProvided_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + var floorId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId, floorId: floorId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var noRoomName = ""; + + //act+assert + Assert.Throws(() => usecases.CreateRoom(noRoomName, floorId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateRoom_WhenRoomNameAlreadyExists_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + var floorId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId, floorId: floorId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var duplicateName = "Raum1"; + + //act+assert + Assert.Throws(() => usecases.CreateRoom(duplicateName, floorId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateRoom_WhenValidArgumentsProvided_ShouldCreateRoom() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + var floorId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId, floorId: floorId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var roomName = "ValidName"; + + //act+assert + Assert.DoesNotThrow(() => usecases.CreateRoom(roomName, floorId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateFloor_WhenInvalidBuildingIdIsProvided_ShouldThrowEntitiyNotFoundException() + { + //setup + using var db = new DataContext(); + SetupMockData(db); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var floorName = "validName"; + var invalidBuildingId = Guid.NewGuid(); + + //act+assert + Assert.Throws(() => usecases.CreateFloor(floorName, invalidBuildingId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateFloor_WhenNoFloorNameIsProvided_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + var buildingId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId, buildingId: buildingId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var noFloorName = ""; + + //act+assert + Assert.Throws(() => usecases.CreateFloor(noFloorName, buildingId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateFloor_WhenFloorNameAlreadyExists_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + var buildingId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId, buildingId: buildingId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var duplicateName = "Stockwerk1"; + + //act+assert + Assert.Throws(() => usecases.CreateFloor(duplicateName, buildingId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateFloor_WhenValidArgumentsProvided_ShouldCreateFloor() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + var buildingId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId, buildingId: buildingId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var floorName = "ValidName"; + + //act+assert + Assert.DoesNotThrow(() => usecases.CreateFloor(floorName, buildingId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateBuilding_WhenInvalidCompanyIdIsProvided_ShouldThrowEntitiyNotFoundException() + { + //setup + using var db = new DataContext(); + SetupMockData(db); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var buildingName = "validName"; + var location = "validLocation"; + var invalidCompanyId = Guid.NewGuid(); + + //act+assert + Assert.Throws(() => usecases.CreateBuilding(buildingName, location, invalidCompanyId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateBuilding_WhenNoLocationIsProvided_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var buildingName = "validName"; + var noLocation = ""; + + //act+assert + Assert.Throws(() => usecases.CreateBuilding(buildingName, noLocation, companyId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateBuilding_WhenNoBuildingNameIsProvided_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var noBuildingName = ""; + var location = "validLocation"; + + //act+assert + Assert.Throws(() => usecases.CreateBuilding(noBuildingName, location, companyId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateBuilding_WhenBuildingNameAlreadyExists_ShouldThrowArgumentInvalidException() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var duplicateName = "Gebäude1"; + var location = "validLocation"; + + //act+assert + Assert.Throws(() => usecases.CreateBuilding(duplicateName, location, companyId)); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] + public void CreateBuilding_WhenValidArgumentsProvided_ShouldCreateBuilding() + { + //setup + using var db = new DataContext(); + var companyId = Guid.NewGuid(); + SetupMockData(db, companyId: companyId); + + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + var buildingName = "validName"; + var location = "validLocation"; + + //act+assert + Assert.DoesNotThrow(() => usecases.CreateBuilding(buildingName, location, companyId)); + + //cleanup + db.Database.EnsureDeleted(); + } + + private UserUsecases SetupUserUsecases(DataContext db) + { + var logger = new Mock>(); + var userUsecases = new UserUsecases(logger.Object, db); + + return userUsecases; + } + private void SetupMockData(DataContext moqDb, Guid companyId = new(), Guid userId = new(), Guid buildingId = new(), Guid floorId = new(), Guid roomId = new(), Guid deskTypeId = new(), Guid deskId = new()) { diff --git a/src/deskstar-frontend/components/AddResourceModal.tsx b/src/deskstar-frontend/components/AddResourceModal.tsx new file mode 100644 index 00000000..97738c98 --- /dev/null +++ b/src/deskstar-frontend/components/AddResourceModal.tsx @@ -0,0 +1,451 @@ +import { useSession } from "next-auth/react"; +import { useState } from "react"; +import { createBuilding, createDesk, createDeskType, createFloor, createRoom, getDeskTypes, 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 AddResourceModal = ({ buildings: origBuildings, deskTypes: origDeskTypes, }: { buildings: IBuilding[]; deskTypes: IDeskType[] }) => { + let { data: session } = useSession(); + + const resourceTypes: string[] = ["Building", "Floor", "Room", "Desk", "DeskType"]; + const [selectedResourceType, setSelectedResourceType] = useState("Desk"); + const [isLoading, setIsLoading] = useState(false); + + const [buildingName, setBuildingName] = useState(""); + const [locationName, setLocationName] = useState(""); + const [floorName, setFloorName] = useState(""); + const [roomName, setRoomName] = useState(""); + const [deskName, setDeskName] = useState(""); + const [deskTypeName, setDeskTypeName] = useState(""); + + 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); + + 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; + } + + console.log("floor: ") + console.log(selectedFloor); + 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); + } + + async function addBuilding() { + if (!session) + return; + if (!buildingName) { + alert("please enter a building name"); + return; + } + if ((!locationName || (locationName === "")) && !location) { + alert("please choose or enter a location"); + return; + } + + setIsLoading(true); + console.log(locationName); + let res = await createBuilding(session, { buildingName: buildingName, location: location ? location.locationName : locationName }); + alert(res.message); + origBuildings.push(res.data as IBuilding); + setBuildings([...buildings, res.data as IBuilding]); + const tmp = new Map(); + [...locations, { locationName: (res.data as IBuilding).location }].forEach((element) => tmp.set(element.locationName, { locationName: element.locationName })); + setLocations(Array.from(tmp.values())); + console.log(""); + setIsLoading(false); + } + + async function addFloor() { + if (!session) + return; + if (!floorName) { + alert("please enter a floor name"); + return; + } + if (!location) { + alert("please choose a location"); + return; + } + if (!building) { + alert("please choose a building"); + return; + } + + setIsLoading(true); + let res = await createFloor(session, { buildingId: building.buildingId, floorName: floorName }); + alert(res.message); + setFloors([...floors, res.data as IFloor]) + setIsLoading(false); + } + + async function addRoom() { + if (!session) + return; + if (!roomName) { + alert("please enter a room name"); + return; + } + if (!location) { + alert("please choose a location"); + return; + } + if (!building) { + alert("please choose a building"); + return; + } + if (!floor) { + alert("please choose a floor"); + return; + } + + setIsLoading(true); + let res = await createRoom(session, { floorId: floor.floorId, roomName: roomName }); + alert(res.message); + setRooms([...rooms, res.data as IRoom]) + setIsLoading(false); + } + + async function addDeskType() { + if (!session) + return; + if (!deskTypeName) { + alert("please enter a desk type name"); + return; + } + + setIsLoading(true); + let res = await createDeskType(session, { deskTypeName: deskTypeName }); + alert(res.message); + setDeskTypes([...deskTypes, res.data as IDeskType]) + setIsLoading(false); + } + + async function addDesk() { + if (!session) + return; + if (deskName === "") { + alert("please enter a desk name"); + return; + } + if (!deskType) { + alert("please choose a desk type"); + return; + } + if (!location) { + alert("please choose a location"); + return; + } + if (!building) { + alert("please choose a building"); + return; + } + if (!floor) { + alert("please choose a floor"); + return; + } + if (!room) { + alert("please choose a room"); + return; + } + + setIsLoading(true); + let res = await createDesk(session, { deskName: deskName, deskTypeId: deskType.deskTypeId, roomId: room?.roomId }); + alert(res.message); + setIsLoading(false); + } + + return <> +
+
+ + x + +

Add Resources

+ +
Resource Type
+ +
+ {resourceTypes.map((type: string) => ( + + ))} +
+ + { + selectedResourceType === "Building" && <> + { setBuildingName(e.target.value) }} value={buildingName} placeholder="Building Name" /> + { setLocationName(e.target.value); setLocation(null); }} value={locationName} placeholder="New Location" /> + +
Existing Location
+ { onSelectedLocationChange(o); setLocationName("") }} + getName={(location) => + location ? location.locationName : "select location" + } + /> + + addBuilding()}> + Confirm + + + } + { + selectedResourceType === "Floor" && <> + { setFloorName(e.target.value) }} value={floorName} placeholder="Floor Name" /> + +
Location
+ onSelectedLocationChange(o)} + getName={(location) => + location ? location.locationName : "select location" + } + /> + + {location && <> +
Building
+ onSelectedBuildingChange(o)} + getName={(building) => + building ? building.buildingName : "select building" + } + /> + + } + addFloor()}> + Confirm + + + } + { + selectedResourceType === "Room" && <> + { setRoomName(e.target.value) }} value={roomName} placeholder="Room Name" /> + +
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" + } + /> + + } + addRoom()}> + Confirm + + + } + + + {selectedResourceType === "Desk" && <> + { setDeskName(e.target.value) }} value={deskName} placeholder="Desk Name" /> + <> +
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" + } + /> + } + addDesk()}> + Confirm + + } + + { + selectedResourceType === "DeskType" && <> + { setDeskTypeName(e.target.value) }} value={deskTypeName} placeholder="Desk Type Name" /> + addDeskType()}> + Confirm + + + } + { + isLoading && +
+ +
+ } + { + !isLoading && +
+ } +
+
+ ; + +} + +export default AddResourceModal; + diff --git a/src/deskstar-frontend/components/Filterbar.tsx b/src/deskstar-frontend/components/Filterbar.tsx index 8b468e3e..bb5d8de1 100644 --- a/src/deskstar-frontend/components/Filterbar.tsx +++ b/src/deskstar-frontend/components/Filterbar.tsx @@ -97,7 +97,7 @@ export default function Filterbar({ return; } - const rooms = await getRooms(session, selectedFloor.floorID); + const rooms = await getRooms(session, selectedFloor.floorId); setRooms(rooms); setSelectedRoom(null); @@ -123,11 +123,6 @@ export default function Filterbar({ const filteredDesks = desks.filter((desk) => desk.bookings.length === 0); - let deskTypes = filteredDesks.map((desk) => ({ - typeId: desk.deskTyp, - typeName: desk.deskTyp, - })); - setDeskTypes(deskTypes); setSelectedDeskType(null); // Equals all there @@ -143,7 +138,7 @@ export default function Filterbar({ } const filteredDesks = desks.filter( - (desk) => desk.deskTyp === selectedDeskType.typeName + (desk) => desk.deskTyp === selectedDeskType.deskTypeName ); setFilteredDesks(filteredDesks); @@ -179,7 +174,7 @@ export default function Filterbar({ selectedItem={selectedFloor} setSelectedItem={setSelectedFloor} getName={(floor) => floor?.floorName ?? "Kein Stockwerk ausgewählt"} - getKey={(floor) => floor?.floorID} + getKey={(floor) => floor?.floorId} /> )} @@ -199,9 +194,9 @@ export default function Filterbar({ selectedItem={selectedDeskType} setSelectedItem={setSelectedDeskType} getName={(deskType) => - deskType?.typeName ?? "Kein Schreibtischtyp ausgewählt" + deskType?.deskTypeName ?? "Kein Schreibtischtyp ausgewählt" } - getKey={(deskType) => deskType.typeId} + getKey={(deskType) => deskType.deskTypeId} allOption={true} /> )} diff --git a/src/deskstar-frontend/deskTypes.js b/src/deskstar-frontend/deskTypes.js index 25460b79..f4ab4cb5 100644 --- a/src/deskstar-frontend/deskTypes.js +++ b/src/deskstar-frontend/deskTypes.js @@ -1,10 +1,10 @@ export const deskTypes = [ { - typeId: "1", - typeName: "Standard", + deskTypeId: "1", + deskTypeName: "Standard", }, { - typeId: "2", - typeName: "Height Adjustable", + deskTypeId: "2", + deskTypeName: "Height Adjustable", } ] \ 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 342cb730..d8b47bf3 100644 --- a/src/deskstar-frontend/lib/api/ResourceService.ts +++ b/src/deskstar-frontend/lib/api/ResourceService.ts @@ -1,12 +1,25 @@ import { Session } from "next-auth"; import { IBuilding } from "../../types/building"; import { IDesk } from "../../types/desk"; +import { IDeskType } from "../../types/desktypes"; import { IFloor } from "../../types/floor"; +import { CreateBuildingDto } from "../../types/models/CreateBuildingDto"; +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 { IRoom } from "../../types/room"; import { BACKEND_URL } from "./constants"; -export async function getLocations() { - // const response = await fetch(BACKEND_URL + "/resources/locations"); +export interface ICreateResourceResult { + response: ResourceResponse; + message: string; + data?: Object; +} + +export enum ResourceResponse { + Error, + Success, } export async function getBuildings(session: Session): Promise { @@ -18,7 +31,7 @@ export async function getBuildings(session: Session): Promise { if (response.status !== 200) { console.log(response.status); - console.log( "Error fetching buildings"); + console.log("Error fetching buildings"); return []; } @@ -89,7 +102,7 @@ export async function getDesks( }, } ); - + if (response.status !== 200) { console.log(response.status); console.log("Error fetching desks"); @@ -97,6 +110,201 @@ export async function getDesks( } const data = await response.json(); - + return data; } + +export async function getDeskTypes( + session: Session, +): Promise { + const response = await fetch( + BACKEND_URL + `/resources/desktypes`, + { + headers: { + Authorization: `Bearer ${session.accessToken}`, + }, + } + ); + + if (response.status !== 200) { + console.log(response.status); + console.log("Error fetching desks"); + return []; + } + + + const data = await response.json(); + const resDeskTypes = data.map((e: any) => { + return { + deskTypeId: e["deskTypeId"], + deskTypeName: e["deskTypeName"] + } + }); + + return resDeskTypes; +} + +export async function createBuilding( + session: Session, + createBuildingDto: CreateBuildingDto, +): Promise { + const b = JSON.stringify(createBuildingDto); + const response = await fetch(BACKEND_URL + "/resources/buildings", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session.accessToken}`, + }, + body: b, + }); + + let result: ICreateResourceResult; + const body = await response.text(); + + if (response.status !== 200) { + result = { + response: ResourceResponse.Error, + message: body || "An error occured.", + }; + } else { + result = { + response: ResourceResponse.Success, + data: JSON.parse(body) as IBuilding, + message: `Success! Created building '${createBuildingDto.buildingName}'` + } + } + + return result; +} + +export async function createFloor( + session: Session, + createFloorDto: CreateFloorDto, +): Promise { + const b = JSON.stringify(createFloorDto); + const response = await fetch(BACKEND_URL + "/resources/floors", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session.accessToken}`, + }, + body: b, + }); + + let result: ICreateResourceResult; + const body = await response.text(); + + if (response.status !== 200) { + result = { + response: ResourceResponse.Error, + message: body || "An error occured.", + }; + } else { + result = { + response: ResourceResponse.Success, + data: JSON.parse(body) as IFloor, + message: `Success! Created floor '${createFloorDto.floorName}'` + } + } + + return result; +} + +export async function createRoom( + session: Session, + createRoomDto: CreateRoomDto, +): Promise { + const b = JSON.stringify(createRoomDto); + const response = await fetch(BACKEND_URL + "/resources/rooms", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session.accessToken}`, + }, + body: b, + }); + + let result: ICreateResourceResult; + const body = await response.text(); + + if (response.status !== 200) { + result = { + response: ResourceResponse.Error, + message: body || "An error occured.", + }; + } else { + result = { + response: ResourceResponse.Success, + data: JSON.parse(body) as IRoom, + message: `Success! Created room '${createRoomDto.roomName}'` + } + } + + return result; +} + +export async function createDeskType( + session: Session, + createDeskTypeDto: CreateDeskTypeDto, +): Promise { + const b = JSON.stringify(createDeskTypeDto); + const response = await fetch(BACKEND_URL + "/resources/desktypes", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session.accessToken}`, + }, + body: b, + }); + + let result: ICreateResourceResult; + const body = await response.text(); + + if (response.status !== 200) { + result = { + response: ResourceResponse.Error, + message: body || "An error occured.", + }; + } else { + result = { + response: ResourceResponse.Success, + data: JSON.parse(body) as IDeskType, + message: `Success! Created type '${createDeskTypeDto.deskTypeName}'` + } + } + + return result; +} + +export async function createDesk( + session: Session, + createDeskDto: CreateDeskDto, +): Promise { + const b = JSON.stringify(createDeskDto); + const response = await fetch(BACKEND_URL + "/resources/desks", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${session.accessToken}`, + }, + body: b, + }); + + let result: ICreateResourceResult; + const body = await response.text(); + + if (response.status !== 200) { + result = { + response: ResourceResponse.Error, + message: body || "An error occured.", + }; + } else { + result = { + response: ResourceResponse.Success, + data: JSON.parse(body) as IDesk, + message: `Success! Created desk '${createDeskDto.deskName}'` + } + } + + return result; +} \ No newline at end of file diff --git a/src/deskstar-frontend/pages/resources/index.tsx b/src/deskstar-frontend/pages/resources/index.tsx index 1828969f..3717b2bf 100644 --- a/src/deskstar-frontend/pages/resources/index.tsx +++ b/src/deskstar-frontend/pages/resources/index.tsx @@ -1,28 +1,33 @@ -import Head from "next/head"; +import { GetServerSideProps } from "next"; +import { unstable_getServerSession } from "next-auth"; import { useSession } from "next-auth/react"; +import Head from "next/head"; import { useRouter } from "next/router"; -import { useState, useEffect } from "react"; -import { authOptions } from "../api/auth/[...nextauth]"; -import { unstable_getServerSession } from "next-auth"; -import ResourceManagementTable from "../../components/ResourceManagementTable"; +import { useEffect, useState } from "react"; +import AddResourceModal from "../../components/AddResourceModal"; import DropDownFilter from "../../components/DropDownFilter"; -import { IDesk } from "../../types/desk"; -import { IRoom } from "../../types/room"; -import { IBuilding } from "../../types/building"; -import { ILocation } from "../../types/location"; -import { IFloor } from "../../types/floor"; +import ResourceManagementTable from "../../components/ResourceManagementTable"; import { getBuildings, getDesks, + getDeskTypes, getFloors, - getRooms, + getRooms } from "../../lib/api/ResourceService"; -import { GetServerSideProps } from "next"; +import { IBuilding } from "../../types/building"; +import { IDesk } from "../../types/desk"; +import { IDeskType } from "../../types/desktypes"; +import { IFloor } from "../../types/floor"; +import { ILocation } from "../../types/location"; +import { IRoom } from "../../types/room"; +import { authOptions } from "../api/auth/[...nextauth]"; const ResourceOverview = ({ buildings: origBuildings, + deskTypes: origDeskTypes, }: { buildings: IBuilding[]; + deskTypes: IDeskType[]; }) => { let { data: session } = useSession(); @@ -70,7 +75,7 @@ const ResourceOverview = ({ return []; } - const resRooms = await getRooms(session, floor.floorID); + const resRooms = await getRooms(session, floor.floorId); return resRooms; }) ); @@ -131,13 +136,15 @@ const ResourceOverview = ({

Resources Overview

- + + +
{ if (session) { const buildings = await getBuildings(session); - + const deskTypes = await getDeskTypes(session); return { props: { buildings, + deskTypes }, }; } @@ -235,6 +243,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { return { props: { buildings: [], + deskTypes: [], }, }; }; diff --git a/src/deskstar-frontend/types/desktypes.ts b/src/deskstar-frontend/types/desktypes.ts index 2fdcf6df..cfc57c85 100644 --- a/src/deskstar-frontend/types/desktypes.ts +++ b/src/deskstar-frontend/types/desktypes.ts @@ -1,4 +1,4 @@ export interface IDeskType { - typeId: string; - typeName: string + deskTypeId: string; + deskTypeName: string }; \ No newline at end of file diff --git a/src/deskstar-frontend/types/floor.ts b/src/deskstar-frontend/types/floor.ts index 0546a171..97d6e564 100644 --- a/src/deskstar-frontend/types/floor.ts +++ b/src/deskstar-frontend/types/floor.ts @@ -1,4 +1,4 @@ export interface IFloor { - floorID: string; + floorId: string; floorName: string; } diff --git a/src/deskstar-frontend/types/models/CreateBuildingDto.ts b/src/deskstar-frontend/types/models/CreateBuildingDto.ts new file mode 100644 index 00000000..c248be8a --- /dev/null +++ b/src/deskstar-frontend/types/models/CreateBuildingDto.ts @@ -0,0 +1,4 @@ +export type CreateBuildingDto = { + buildingName: string; + location: string; +}; \ No newline at end of file diff --git a/src/deskstar-frontend/types/models/CreateDeskDto.ts b/src/deskstar-frontend/types/models/CreateDeskDto.ts new file mode 100644 index 00000000..e122257b --- /dev/null +++ b/src/deskstar-frontend/types/models/CreateDeskDto.ts @@ -0,0 +1,5 @@ +export type CreateDeskDto = { + roomId: string; + deskName: string; + deskTypeId: string; +}; \ No newline at end of file diff --git a/src/deskstar-frontend/types/models/CreateDeskTypeDto.ts b/src/deskstar-frontend/types/models/CreateDeskTypeDto.ts new file mode 100644 index 00000000..4e4cfda8 --- /dev/null +++ b/src/deskstar-frontend/types/models/CreateDeskTypeDto.ts @@ -0,0 +1,3 @@ +export type CreateDeskTypeDto = { + deskTypeName: string; +}; \ No newline at end of file diff --git a/src/deskstar-frontend/types/models/CreateFloorDto.ts b/src/deskstar-frontend/types/models/CreateFloorDto.ts new file mode 100644 index 00000000..7698767f --- /dev/null +++ b/src/deskstar-frontend/types/models/CreateFloorDto.ts @@ -0,0 +1,4 @@ +export type CreateFloorDto = { + buildingId: string; + floorName: string; + }; \ No newline at end of file diff --git a/src/deskstar-frontend/types/models/CreateRoomDto.ts b/src/deskstar-frontend/types/models/CreateRoomDto.ts new file mode 100644 index 00000000..9ee9cd7b --- /dev/null +++ b/src/deskstar-frontend/types/models/CreateRoomDto.ts @@ -0,0 +1,4 @@ +export type CreateRoomDto = { + floorId: string; + roomName: string; +}; \ No newline at end of file diff --git a/src/deskstar-frontend/types/models/index.d.ts b/src/deskstar-frontend/types/models/index.d.ts new file mode 100644 index 00000000..e69de29b