diff --git a/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboard/GetWhiteboardQuery.cs b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboard/GetWhiteboardQuery.cs new file mode 100644 index 0000000..f7bf3e6 --- /dev/null +++ b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboard/GetWhiteboardQuery.cs @@ -0,0 +1,5 @@ +using AipsCore.Application.Abstract.Query; + +namespace AipsCore.Application.Models.Whiteboard.Query.GetWhiteboard; + +public record GetWhiteboardQuery(string WhiteboardId) : IQuery; \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboard/GetWhiteboardQueryHandler.cs b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboard/GetWhiteboardQueryHandler.cs new file mode 100644 index 0000000..af3cc85 --- /dev/null +++ b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboard/GetWhiteboardQueryHandler.cs @@ -0,0 +1,23 @@ +using AipsCore.Application.Abstract.Query; +using AipsCore.Infrastructure.Persistence.Db; +using Microsoft.EntityFrameworkCore; + +namespace AipsCore.Application.Models.Whiteboard.Query.GetWhiteboard; + +public class GetWhiteboardQueryHandler + : IQueryHandler +{ + private readonly AipsDbContext _context; + + public GetWhiteboardQueryHandler(AipsDbContext context) + { + _context = context; + } + + public async Task Handle(GetWhiteboardQuery query, CancellationToken cancellationToken = default) + { + return await _context.Whiteboards + .Where(w => w.Id.ToString() == query.WhiteboardId) + .FirstOrDefaultAsync(cancellationToken); + } +} \ No newline at end of file diff --git a/dotnet/AipsCore/Infrastructure/DI/UserContextRegistrationExtension.cs b/dotnet/AipsCore/Infrastructure/DI/UserContextRegistrationExtension.cs index 76a3e13..adbae92 100644 --- a/dotnet/AipsCore/Infrastructure/DI/UserContextRegistrationExtension.cs +++ b/dotnet/AipsCore/Infrastructure/DI/UserContextRegistrationExtension.cs @@ -64,6 +64,23 @@ public static class UserContextRegistrationExtension IssuerSigningKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(jwtSettings.Key)) }; + + options.Events = new JwtBearerEvents + { + OnMessageReceived = context => + { + var accessToken = context.Request.Query["access_token"]; + var path = context.HttpContext.Request.Path; + + if (!string.IsNullOrEmpty(accessToken) && + path.StartsWithSegments("/hubs")) + { + context.Token = accessToken; + } + + return Task.CompletedTask; + } + }; }); services.AddAuthorization(); diff --git a/dotnet/AipsRT/Properties/launchSettings.json b/dotnet/AipsRT/Properties/launchSettings.json index 5d70556..e76400f 100644 --- a/dotnet/AipsRT/Properties/launchSettings.json +++ b/dotnet/AipsRT/Properties/launchSettings.json @@ -4,7 +4,7 @@ "http": { "commandName": "Project", "dotnetRunMessages": true, - "launchBrowser": true, + "launchBrowser": false, "applicationUrl": "http://localhost:5039", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/dotnet/AipsWebApi/Controllers/WhiteboardController.cs b/dotnet/AipsWebApi/Controllers/WhiteboardController.cs index 44467bd..0bbc8d3 100644 --- a/dotnet/AipsWebApi/Controllers/WhiteboardController.cs +++ b/dotnet/AipsWebApi/Controllers/WhiteboardController.cs @@ -1,6 +1,7 @@ using AipsCore.Application.Abstract; using AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard; using AipsCore.Application.Models.Whiteboard.Query.GetRecentWhiteboards; +using AipsCore.Application.Models.Whiteboard.Query.GetWhiteboard; using AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardHistory; using AipsCore.Application.Models.WhiteboardMembership.Command.CreateWhiteboardMembership; using Microsoft.AspNetCore.Authorization; @@ -22,11 +23,23 @@ public class WhiteboardController : ControllerBase [Authorize] [HttpPost] - public async Task> CreateWhiteboard(CreateWhiteboardCommand command, CancellationToken cancellationToken) + public async Task> CreateWhiteboard(CreateWhiteboardCommand command, CancellationToken cancellationToken) { var whiteboardId = await _dispatcher.Execute(command, cancellationToken); return Ok(whiteboardId.IdValue); } + + [Authorize] + [HttpGet("{whiteboardId}")] + public async Task> GetWhiteboardById([FromRoute] string whiteboardId, CancellationToken cancellationToken) + { + var whiteboard = await _dispatcher.Execute(new GetWhiteboardQuery(whiteboardId), cancellationToken); + if (whiteboard == null) + { + return NotFound(); + } + return Ok(whiteboard); + } [Authorize] [HttpGet("history")] diff --git a/front/src/components/RecentWhiteboardsList.vue b/front/src/components/RecentWhiteboardsList.vue index ef287d0..0b4d38d 100644 --- a/front/src/components/RecentWhiteboardsList.vue +++ b/front/src/components/RecentWhiteboardsList.vue @@ -2,11 +2,11 @@ import { onMounted, computed } from 'vue' import { useRouter } from 'vue-router' -import { useWhiteboardStore } from '@/stores/whiteboards' +import { useWhiteboardsStore } from '@/stores/whiteboards' import RecentWhiteboardsItem from './RecentWhiteboardsItem.vue' const router = useRouter() -const store = useWhiteboardStore() +const store = useWhiteboardsStore() onMounted(() => { if (store.recentWhiteboards.length === 0) store.getRecentWhiteboards() diff --git a/front/src/components/WhiteboardHistoryList.vue b/front/src/components/WhiteboardHistoryList.vue index 08cf636..5097d4a 100644 --- a/front/src/components/WhiteboardHistoryList.vue +++ b/front/src/components/WhiteboardHistoryList.vue @@ -1,11 +1,11 @@