diff --git a/dotnet/AipsCore/Application/Models/User/Query/GetMe/GetMeQueryDto.cs b/dotnet/AipsCore/Application/Models/User/Query/GetMe/GetMeQueryDto.cs index 5ace6cb..af838f5 100644 --- a/dotnet/AipsCore/Application/Models/User/Query/GetMe/GetMeQueryDto.cs +++ b/dotnet/AipsCore/Application/Models/User/Query/GetMe/GetMeQueryDto.cs @@ -1,3 +1,3 @@ namespace AipsCore.Application.Models.User.Query.GetMe; -public record GetMeQueryDto(string UserName); \ No newline at end of file +public record GetMeQueryDto(string UserId, string UserName); \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/User/Query/GetMe/GetMeQueryHandler.cs b/dotnet/AipsCore/Application/Models/User/Query/GetMe/GetMeQueryHandler.cs index df77e31..da68d56 100644 --- a/dotnet/AipsCore/Application/Models/User/Query/GetMe/GetMeQueryHandler.cs +++ b/dotnet/AipsCore/Application/Models/User/Query/GetMe/GetMeQueryHandler.cs @@ -32,6 +32,6 @@ public class GetMeQueryHandler : IQueryHandler throw new ValidationException(UserErrors.NotFound(new UserId(userId.IdValue))); } - return new GetMeQueryDto(result.UserName!); + return new GetMeQueryDto(result.Id.ToString(), result.UserName!); } } \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetRecentWhiteboards/GetRecentWhiteboardsQuery.cs b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetRecentWhiteboards/GetRecentWhiteboardsQuery.cs index 1656f2b..9cc7439 100644 --- a/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetRecentWhiteboards/GetRecentWhiteboardsQuery.cs +++ b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetRecentWhiteboards/GetRecentWhiteboardsQuery.cs @@ -2,4 +2,4 @@ using AipsCore.Application.Abstract.Query; namespace AipsCore.Application.Models.Whiteboard.Query.GetRecentWhiteboards; -public record GetRecentWhiteboardsQuery(string UserId): IQuery>; \ No newline at end of file +public record GetRecentWhiteboardsQuery: IQuery>; \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetRecentWhiteboards/GetRecentWhiteboardsQueryHandler.cs b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetRecentWhiteboards/GetRecentWhiteboardsQueryHandler.cs index a58d5b5..0c64e85 100644 --- a/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetRecentWhiteboards/GetRecentWhiteboardsQueryHandler.cs +++ b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetRecentWhiteboards/GetRecentWhiteboardsQueryHandler.cs @@ -1,4 +1,5 @@ using AipsCore.Application.Abstract.Query; +using AipsCore.Application.Abstract.UserContext; using AipsCore.Infrastructure.Persistence.Db; using Microsoft.EntityFrameworkCore; @@ -7,20 +8,24 @@ namespace AipsCore.Application.Models.Whiteboard.Query.GetRecentWhiteboards; public class GetRecentWhiteboardsQueryHandler : IQueryHandler> { private readonly AipsDbContext _context; + private readonly IUserContext _userContext; - public GetRecentWhiteboardsQueryHandler(AipsDbContext context) + public GetRecentWhiteboardsQueryHandler(AipsDbContext context, IUserContext userContext) { _context = context; + _userContext = userContext; } public async Task> Handle(GetRecentWhiteboardsQuery query, CancellationToken cancellationToken = default) { - return await GetQuery(query.UserId).ToListAsync(cancellationToken); + var userId = _userContext.GetCurrentUserId().IdValue; + + return await GetQuery(userId).ToListAsync(cancellationToken); } private IQueryable GetQuery(string userId) { - Guid userIdGuid = Guid.Parse(userId); + var userIdGuid = Guid.Parse(userId); return _context.WhiteboardMemberships .Include(m => m.Whiteboard) diff --git a/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboardHistory/GetWhiteboardHistoryQuery.cs b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboardHistory/GetWhiteboardHistoryQuery.cs new file mode 100644 index 0000000..79b0384 --- /dev/null +++ b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboardHistory/GetWhiteboardHistoryQuery.cs @@ -0,0 +1,5 @@ +using AipsCore.Application.Abstract.Query; + +namespace AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardHistory; + +public record GetWhiteboardHistoryQuery : IQuery>; \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboardHistory/GetWhiteboardHistoryQueryHandler.cs b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboardHistory/GetWhiteboardHistoryQueryHandler.cs new file mode 100644 index 0000000..a93e57a --- /dev/null +++ b/dotnet/AipsCore/Application/Models/Whiteboard/Query/GetWhiteboardHistory/GetWhiteboardHistoryQueryHandler.cs @@ -0,0 +1,28 @@ +using AipsCore.Application.Abstract.Query; +using AipsCore.Application.Abstract.UserContext; +using AipsCore.Infrastructure.Persistence.Db; +using Microsoft.EntityFrameworkCore; + +namespace AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardHistory; + +public class GetWhiteboardHistoryQueryHandler + : IQueryHandler> +{ + private readonly AipsDbContext _context; + private readonly IUserContext _userContext; + + public GetWhiteboardHistoryQueryHandler(AipsDbContext context, IUserContext userContext) + { + _context = context; + _userContext = userContext; + } + + public async Task> Handle(GetWhiteboardHistoryQuery query, CancellationToken cancellationToken = default) + { + var userIdGuid = new Guid(_userContext.GetCurrentUserId().IdValue); + + return await _context.Whiteboards + .Where(w => w.OwnerId == userIdGuid) + .ToListAsync(cancellationToken); + } +} \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/WhiteboardMembership/Command/CreateWhiteboardMembership/CreateWhiteboardMembershipCommand.cs b/dotnet/AipsCore/Application/Models/WhiteboardMembership/Command/CreateWhiteboardMembership/CreateWhiteboardMembershipCommand.cs index 00b0665..ebe3367 100644 --- a/dotnet/AipsCore/Application/Models/WhiteboardMembership/Command/CreateWhiteboardMembership/CreateWhiteboardMembershipCommand.cs +++ b/dotnet/AipsCore/Application/Models/WhiteboardMembership/Command/CreateWhiteboardMembership/CreateWhiteboardMembershipCommand.cs @@ -5,9 +5,7 @@ namespace AipsCore.Application.Models.WhiteboardMembership.Command.CreateWhitebo public record CreateWhiteboardMembershipCommand( string WhiteboardId, - string UserId, bool IsBanned, bool EditingEnabled, - bool CanJoin, - DateTime LastInteractedAt) + bool CanJoin) : ICommand; \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/WhiteboardMembership/Command/CreateWhiteboardMembership/CreateWhiteboardMembershipCommandHandler.cs b/dotnet/AipsCore/Application/Models/WhiteboardMembership/Command/CreateWhiteboardMembership/CreateWhiteboardMembershipCommandHandler.cs index a722f35..a336e36 100644 --- a/dotnet/AipsCore/Application/Models/WhiteboardMembership/Command/CreateWhiteboardMembership/CreateWhiteboardMembershipCommandHandler.cs +++ b/dotnet/AipsCore/Application/Models/WhiteboardMembership/Command/CreateWhiteboardMembership/CreateWhiteboardMembershipCommandHandler.cs @@ -1,4 +1,5 @@ using AipsCore.Application.Abstract.Command; +using AipsCore.Application.Abstract.UserContext; using AipsCore.Domain.Abstract; using AipsCore.Domain.Models.WhiteboardMembership.External; using AipsCore.Domain.Models.WhiteboardMembership.ValueObjects; @@ -8,23 +9,30 @@ namespace AipsCore.Application.Models.WhiteboardMembership.Command.CreateWhitebo public class CreateWhiteboardMembershipCommandHandler : ICommandHandler { private readonly IWhiteboardMembershipRepository _whiteboardMembershipRepository; + private readonly IUserContext _userContext; private readonly IUnitOfWork _unitOfWork; - public CreateWhiteboardMembershipCommandHandler(IWhiteboardMembershipRepository whiteboardMembershipRepository, IUnitOfWork unitOfWork) + public CreateWhiteboardMembershipCommandHandler( + IWhiteboardMembershipRepository whiteboardMembershipRepository, + IUserContext userContext, + IUnitOfWork unitOfWork) { _whiteboardMembershipRepository = whiteboardMembershipRepository; + _userContext = userContext; _unitOfWork = unitOfWork; } public async Task Handle(CreateWhiteboardMembershipCommand command, CancellationToken cancellationToken = default) { + var userId = _userContext.GetCurrentUserId(); + var whiteboardMembership = Domain.Models.WhiteboardMembership.WhiteboardMembership.Create( command.WhiteboardId, - command.UserId, + userId.IdValue, command.IsBanned, command.EditingEnabled, command.CanJoin, - command.LastInteractedAt); + DateTime.UtcNow); await _whiteboardMembershipRepository.SaveAsync(whiteboardMembership, cancellationToken); await _unitOfWork.SaveChangesAsync(cancellationToken); diff --git a/dotnet/AipsWebApi/Controllers/WhiteboardController.cs b/dotnet/AipsWebApi/Controllers/WhiteboardController.cs index af8cd08..44467bd 100644 --- a/dotnet/AipsWebApi/Controllers/WhiteboardController.cs +++ b/dotnet/AipsWebApi/Controllers/WhiteboardController.cs @@ -1,18 +1,16 @@ using AipsCore.Application.Abstract; -using AipsCore.Application.Models.Whiteboard.Command.AddUserToWhiteboard; -using AipsCore.Application.Models.Whiteboard.Command.BanUserFromWhiteboard; using AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard; -using AipsCore.Application.Models.Whiteboard.Command.KickUserFromWhiteboard; -using AipsCore.Application.Models.Whiteboard.Command.UnbanUserFromWhiteboard; using AipsCore.Application.Models.Whiteboard.Query.GetRecentWhiteboards; -using AipsCore.Domain.Models.Whiteboard; +using AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardHistory; +using AipsCore.Application.Models.WhiteboardMembership.Command.CreateWhiteboardMembership; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Whiteboard = AipsCore.Infrastructure.Persistence.Whiteboard.Whiteboard; namespace AipsWebApi.Controllers; [ApiController] -[Route("[controller]")] +[Route("/api/[controller]")] public class WhiteboardController : ControllerBase { private readonly IDispatcher _dispatcher; @@ -29,4 +27,28 @@ public class WhiteboardController : ControllerBase var whiteboardId = await _dispatcher.Execute(command, cancellationToken); return Ok(whiteboardId.IdValue); } + + [Authorize] + [HttpGet("history")] + public async Task>> GetWhiteboardHistory(CancellationToken cancellationToken) + { + var whiteboards = await _dispatcher.Execute(new GetWhiteboardHistoryQuery(), cancellationToken); + return Ok(whiteboards); + } + + [Authorize] + [HttpGet("recent")] + public async Task>> GetRecentWhiteboards(CancellationToken cancellationToken) + { + var whiteboards = await _dispatcher.Execute(new GetRecentWhiteboardsQuery(), cancellationToken); + return Ok(whiteboards); + } + + [Authorize] + [HttpPost("join")] + public async Task JoinWhiteboard(CreateWhiteboardMembershipCommand command, CancellationToken cancellationToken) + { + var result = await _dispatcher.Execute(command, cancellationToken); + return Ok(result); + } } \ No newline at end of file diff --git a/front/bun.lock b/front/bun.lock index 3618a61..9f56676 100644 --- a/front/bun.lock +++ b/front/bun.lock @@ -9,6 +9,7 @@ "@popperjs/core": "^2.11.8", "bootstrap": "^5.3.8", "pinia": "^3.0.4", + "signalr": "^2.4.3", "vue": "^3.5.27", "vue-router": "^5.0.1", }, @@ -547,6 +548,8 @@ "jiti": ["jiti@2.6.1", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ=="], + "jquery": ["jquery@4.0.0", "", {}, "sha512-TXCHVR3Lb6TZdtw1l3RTLf8RBWVGexdxL6AC8/e0xZKEpBflBsjh9/8LXw+dkNFuOyW9B7iB3O1sP7hS0Kiacg=="], + "js-tokens": ["js-tokens@4.0.0", "", {}, "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="], "js-yaml": ["js-yaml@4.1.1", "", { "dependencies": { "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA=="], @@ -739,6 +742,8 @@ "shell-quote": ["shell-quote@1.8.3", "", {}, "sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw=="], + "signalr": ["signalr@2.4.3", "", { "dependencies": { "jquery": ">=1.6.4" } }, "sha512-RbBKFVCZvDgyyxZDeu6Yck9T+diZO07GB0bDiKondUhBY1H8JRQSOq8R0pLkf47ddllQAssYlp7ckQAeom24mw=="], + "sirv": ["sirv@3.0.2", "", { "dependencies": { "@polka/url": "^1.0.0-next.24", "mrmime": "^2.0.0", "totalist": "^3.0.0" } }, "sha512-2wcC/oGxHis/BoHkkPwldgiPSYcpZK3JU28WoMVv55yHJgcZ8rlXvuG9iZggz+sU1d4bRgIGASwyWqjxu3FM0g=="], "source-map-js": ["source-map-js@1.2.1", "", {}, "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA=="], diff --git a/front/src/App.vue b/front/src/App.vue index c6ab3c9..a9c758a 100644 --- a/front/src/App.vue +++ b/front/src/App.vue @@ -1,12 +1,23 @@ +