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