Skip to content

Commit

Permalink
Merge pull request #138 from amosproj/develop
Browse files Browse the repository at this point in the history
Sprint release 8
  • Loading branch information
eddyhakimi authored Dec 14, 2022
2 parents 4ffe5c8 + 98fe9d9 commit 2e5a6a8
Show file tree
Hide file tree
Showing 61 changed files with 2,276 additions and 1,033 deletions.
Binary file added Deliverables/sprint-08/feature-board.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Deliverables/sprint-08/planning-documents.pdf
Binary file not shown.
Binary file modified Documentation/Screenshot/addBooking_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/Screenshot/addBooking_page1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/Screenshot/addBooking_page2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/Screenshot/addBooking_page3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/Screenshot/booking_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/Screenshot/index_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/Screenshot/index_page2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Documentation/Screenshot/searchresult_page.png
Binary file not shown.
Binary file removed Documentation/Screenshot/searchresult_popup_page.png
Binary file not shown.
Binary file modified Documentation/Screenshot/user_page_manage_only_admin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/Screenshot/user_page_request_only_admin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Feature Board: https://github.com/orgs/amosproj/projects/11

Impediments backlog: https://github.com/users/alexKoltman/projects/1
Impediments backlog: https://github.com/orgs/amosproj/projects/12

Product Vision
---------------
Expand Down
98 changes: 69 additions & 29 deletions src/deskstar-backend/Deskstar/Controllers/BookingController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.IdentityModel.Tokens.Jwt;
using Deskstar.Core;
using Deskstar.Models;
using Deskstar.Usecases;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;


namespace Deskstar.Controllers;

Expand All @@ -15,11 +13,13 @@ public class BookingController : ControllerBase
{
private readonly IBookingUsecases _bookingUsecases;
private readonly ILogger<BookingController> _logger;
private readonly IAutoMapperConfiguration _autoMapperConfiguration;

public BookingController(ILogger<BookingController> logger, IBookingUsecases bookingUsecases)
public BookingController(ILogger<BookingController> logger, IBookingUsecases bookingUsecases, IAutoMapperConfiguration autoMapperConfiguration)
{
_logger = logger;
_bookingUsecases = bookingUsecases;
_autoMapperConfiguration = autoMapperConfiguration;
}


Expand All @@ -33,20 +33,17 @@ public BookingController(ILogger<BookingController> logger, IBookingUsecases boo
/// </remarks>
///
/// <response code="200">Returns the booking list</response>
/// <response code="500">Internal Server Error</response>
/// <response code="400">Bad Request</response>
/// <response code="500">Internal Server Error</response>
[HttpGet("range")]
[Authorize]
[ProducesResponseType(typeof(List<RecentBooking>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(List<ExtendedBooking>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[Produces("application/json")]
public IActionResult GetBookingsByDirection(int n = int.MaxValue, int skip = 0, string direction = "DESC", long start = 0, long end = 0)
{
var accessToken = Request.Headers[HeaderNames.Authorization].ToString().Replace("Bearer ", string.Empty);
var handler = new JwtSecurityTokenHandler();
var jwtSecurityToken = handler.ReadJwtToken(accessToken);
var userId = new Guid(jwtSecurityToken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value);
var userId = RequestInteractions.ExtractIdFromRequest(Request);

DateTime startDateTime;
DateTime endDateTime;
Expand Down Expand Up @@ -91,19 +88,10 @@ public IActionResult GetBookingsByDirection(int n = int.MaxValue, int skip = 0,
try
{
var bookings = _bookingUsecases.GetFilteredBookings(userId, n, skip, direction, startDateTime, endDateTime);
var mapped = bookings.Select(
(b) =>
{
RecentBooking rb = new RecentBooking();
rb.Timestamp = b.Timestamp;
rb.StartTime = b.StartTime;
rb.EndTime = b.EndTime;
rb.BuildingName = b.Desk.Room.Floor.Building.BuildingName;
rb.FloorName = b.Desk.Room.Floor.FloorName;
rb.RoomName = b.Desk.Room.RoomName;
rb.DeskName = b.Desk.DeskName;
return rb;
}).ToList();

var mapper = _autoMapperConfiguration.GetConfiguration().CreateMapper();
var mapped = bookings.Select((b) => mapper.Map<Entities.Booking, ExtendedBooking>(b)).ToList();

return Ok(mapped);
}
catch (Exception e)
Expand All @@ -127,15 +115,12 @@ public IActionResult GetBookingsByDirection(int n = int.MaxValue, int skip = 0,
/// <response code="404">User not found</response>
[HttpGet("recent")]
[Authorize]
[ProducesResponseType(typeof(List<RecentBooking>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(List<ExtendedBooking>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[Produces("application/json")]
public IActionResult RecentBookings()
{
var accessToken = Request.Headers[HeaderNames.Authorization].ToString().Replace("Bearer ", string.Empty);
var handler = new JwtSecurityTokenHandler();
var jwtSecurityToken = handler.ReadJwtToken(accessToken);
var userId = new Guid(jwtSecurityToken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value);
var userId = RequestInteractions.ExtractIdFromRequest(Request);
try
{
var bookings = _bookingUsecases.GetRecentBookings(userId);
Expand All @@ -147,4 +132,59 @@ public IActionResult RecentBookings()
}
return NotFound();
}
}


/// <summary>
/// Creates a new Booking for Token-User
/// </summary>
/// <returns>Created Booking in JSON Format</returns>
/// <remarks>
/// Sample request:
/// Post /bookings with JWT Token
/// </remarks>
///
/// <response code="201">Returns the created booking</response>
/// <response code="404">User not found</response>
/// <response code="404">Desk not found</response>
/// <response code="409">Desk is not available at that time</response>
/// <response code="400">Bad Request</response>

[HttpPost]
[Authorize]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[Produces("application/json")]
public IActionResult CreateBooking([FromBody] BookingRequest bookingRequest)
{

if (bookingRequest.StartTime.Equals(DateTime.MinValue) || bookingRequest.EndTime.Equals(DateTime.MinValue) || bookingRequest.DeskId.Equals(Guid.Empty))
{
return BadRequest("Required fields are missing");
}

var userId = RequestInteractions.ExtractIdFromRequest(Request);

//ToDo: require Frontend to Use Universaltime
bookingRequest.StartTime = bookingRequest.StartTime.ToLocalTime();
bookingRequest.EndTime = bookingRequest.EndTime.ToLocalTime();

try
{
_bookingUsecases.CreateBooking(userId, bookingRequest);
return Ok();
}
catch (Exception e)
{
_logger.LogError(e, e.Message);
return e.Message switch
{
"User not found" => NotFound(e.Message),
"Desk not found" => NotFound(e.Message),
"Time slot not available" => Conflict(e.Message),
_ => Problem(statusCode: 500)
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Deskstar.Controllers;
[Produces("text/plain")]
public class HealthCheckController : ControllerBase
{


private readonly ILogger<HealthCheckController> _logger;

public HealthCheckController(ILogger<HealthCheckController> logger)
Expand All @@ -35,7 +33,6 @@ public string Auth()
[Authorize(Policy = "Admin")]
public string Admin()
{

return "you are an admin";
}
}
75 changes: 43 additions & 32 deletions src/deskstar-backend/Deskstar/Controllers/ResourcesController.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System.IdentityModel.Tokens.Jwt;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
using Deskstar.Usecases;
using Deskstar.Models;
using Deskstar.Core;

namespace Deskstar.Controllers;

[ApiController]
[Route("/resources")]
[Produces("text/plain")]
[Produces("application/json")]
public class ResourcesController : ControllerBase
{
private readonly IResourceUsecases _resourceUsecases;
Expand Down Expand Up @@ -39,15 +38,15 @@ public ResourcesController(ILogger<ResourcesController> logger, IResourceUsecase
[Produces("application/json")]
public IActionResult GetAllBuildings()
{
var accessToken = Request.Headers[HeaderNames.Authorization].ToString().Replace("Bearer ", string.Empty);
var handler = new JwtSecurityTokenHandler();
var jwtSecurityToken = handler.ReadJwtToken(accessToken);
var userId =
new Guid(jwtSecurityToken.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value);
var (noFound, buildings) = _resourceUsecases.GetBuildings(userId);
if (!noFound && buildings.Count == 0)
var userId = RequestInteractions.ExtractIdFromRequest(Request);
List<CurrentBuilding> buildings;
try
{
buildings = _resourceUsecases.GetBuildings(userId);
}
catch (ArgumentException e)
{
return Problem(statusCode: 500);
return Problem(statusCode: 500, detail: e.Message);
}

return Ok(buildings.ToList());
Expand Down Expand Up @@ -113,10 +112,14 @@ public IActionResult DeleteBuilding(string buildingId)
[Produces("application/json")]
public IActionResult GetFloorsByBuildingId(string buildingId)
{
var (noFound, floor) = _resourceUsecases.GetFloors(new Guid(buildingId));
if (!noFound && floor.Count == 0)
List<CurrentFloor> floor;
try
{
return Problem(statusCode: 500);
floor = _resourceUsecases.GetFloors(new Guid(buildingId));
}
catch (ArgumentException e)
{
return Problem(statusCode: 500, detail: e.Message);
}

return Ok(floor.ToList());
Expand Down Expand Up @@ -182,10 +185,14 @@ public IActionResult DeleteFloor(string floorId)
[Produces("application/json")]
public IActionResult GetRoomsByFloorId(string floorId)
{
var (noFound, rooms) = _resourceUsecases.GetRooms(new Guid(floorId));
if (!noFound && rooms.Count == 0)
List<CurrentRoom> rooms;
try
{
rooms = _resourceUsecases.GetRooms(new Guid(floorId));
}
catch (ArgumentException e)
{
return Problem(statusCode: 500);
return Problem(statusCode: 500, detail: e.Message);
}

return Ok(rooms.ToList());
Expand Down Expand Up @@ -247,15 +254,21 @@ public IActionResult DeleteRoom(string roomId)
/// <response code="500">Internal Server Error</response>
[HttpGet("rooms/{roomId}/desks")]
[Authorize]
[ProducesResponseType(typeof(List<CurrentRoom>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(List<CurrentDesk>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[Produces("application/json")]
public IActionResult GetDesksByRoomId(string roomId, long start = 0, long end = 0)
{
var (noFound, desks) = _resourceUsecases.GetDesks(new Guid(roomId), new DateTime(start), new DateTime(end));
if (!noFound && desks.Count == 0)
var startDateTime = start == 0 ? DateTime.MinValue : DateTimeOffset.FromUnixTimeMilliseconds(start).DateTime;
var endDateTime = end == 0 ? DateTime.MaxValue : DateTimeOffset.FromUnixTimeMilliseconds(end).DateTime;
List<CurrentDesk> desks;
try
{
desks = _resourceUsecases.GetDesks(new Guid(roomId), startDateTime, endDateTime);
}
catch (ArgumentException e)
{
return Problem(statusCode: 500);
return Problem(statusCode: 500, detail: e.Message);
}

return Ok(desks.ToList());
Expand Down Expand Up @@ -284,15 +297,9 @@ public IActionResult GetDeskDetailsByDeskId(string deskId, long start = 0, long
DateTime endDateTime;
try
{
if (start == 0)
startDateTime = DateTime.Now;
else
startDateTime = DateTimeOffset.FromUnixTimeMilliseconds(start).DateTime;
startDateTime = start == 0 ? DateTime.Now : DateTimeOffset.FromUnixTimeMilliseconds(start).DateTime;

if (end == 0)
endDateTime = DateTime.MaxValue;
else
endDateTime = DateTimeOffset.FromUnixTimeMilliseconds(end).DateTime;
endDateTime = end == 0 ? DateTime.MaxValue : DateTimeOffset.FromUnixTimeMilliseconds(end).DateTime;
if (start > end)
{
(endDateTime, startDateTime) = (startDateTime, endDateTime);
Expand All @@ -309,10 +316,14 @@ public IActionResult GetDeskDetailsByDeskId(string deskId, long start = 0, long
return BadRequest(e.Message);
}

var desk = _resourceUsecases.GetDesk(new Guid(deskId), startDateTime, endDateTime);
if (desk == null)
CurrentDesk desk;
try
{
desk = _resourceUsecases.GetDesk(new Guid(deskId), startDateTime, endDateTime);
}
catch (ArgumentException e)
{
return Problem(statusCode: 500);
return Problem(statusCode: 500, detail: e.Message);
}

return Ok(desk);
Expand Down
Loading

0 comments on commit 2e5a6a8

Please sign in to comment.