This commit is contained in:
Veljko Tosic
2026-02-16 18:18:58 +01:00
parent 5d148db4da
commit f2e38f0b09
9 changed files with 84 additions and 18 deletions

View File

@@ -1,3 +1,3 @@
namespace AipsCore.Application.Models.User.Query.GetMe; namespace AipsCore.Application.Models.User.Query.GetMe;
public record GetMeQueryDto(string UserName); public record GetMeQueryDto(string UserId, string UserName);

View File

@@ -32,6 +32,6 @@ public class GetMeQueryHandler : IQueryHandler<GetMeQuery, GetMeQueryDto>
throw new ValidationException(UserErrors.NotFound(new UserId(userId.IdValue))); throw new ValidationException(UserErrors.NotFound(new UserId(userId.IdValue)));
} }
return new GetMeQueryDto(result.UserName!); return new GetMeQueryDto(result.Id.ToString(), result.UserName!);
} }
} }

View File

@@ -2,4 +2,4 @@ using AipsCore.Application.Abstract.Query;
namespace AipsCore.Application.Models.Whiteboard.Query.GetRecentWhiteboards; namespace AipsCore.Application.Models.Whiteboard.Query.GetRecentWhiteboards;
public record GetRecentWhiteboardsQuery(string UserId): IQuery<ICollection<Infrastructure.Persistence.Whiteboard.Whiteboard>>; public record GetRecentWhiteboardsQuery: IQuery<ICollection<Infrastructure.Persistence.Whiteboard.Whiteboard>>;

View File

@@ -1,4 +1,5 @@
using AipsCore.Application.Abstract.Query; using AipsCore.Application.Abstract.Query;
using AipsCore.Application.Abstract.UserContext;
using AipsCore.Infrastructure.Persistence.Db; using AipsCore.Infrastructure.Persistence.Db;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@@ -7,20 +8,24 @@ namespace AipsCore.Application.Models.Whiteboard.Query.GetRecentWhiteboards;
public class GetRecentWhiteboardsQueryHandler : IQueryHandler<GetRecentWhiteboardsQuery, ICollection<Infrastructure.Persistence.Whiteboard.Whiteboard>> public class GetRecentWhiteboardsQueryHandler : IQueryHandler<GetRecentWhiteboardsQuery, ICollection<Infrastructure.Persistence.Whiteboard.Whiteboard>>
{ {
private readonly AipsDbContext _context; private readonly AipsDbContext _context;
private readonly IUserContext _userContext;
public GetRecentWhiteboardsQueryHandler(AipsDbContext context) public GetRecentWhiteboardsQueryHandler(AipsDbContext context, IUserContext userContext)
{ {
_context = context; _context = context;
_userContext = userContext;
} }
public async Task<ICollection<Infrastructure.Persistence.Whiteboard.Whiteboard>> Handle(GetRecentWhiteboardsQuery query, CancellationToken cancellationToken = default) public async Task<ICollection<Infrastructure.Persistence.Whiteboard.Whiteboard>> 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<Infrastructure.Persistence.Whiteboard.Whiteboard> GetQuery(string userId) private IQueryable<Infrastructure.Persistence.Whiteboard.Whiteboard> GetQuery(string userId)
{ {
Guid userIdGuid = Guid.Parse(userId); var userIdGuid = Guid.Parse(userId);
return _context.WhiteboardMemberships return _context.WhiteboardMemberships
.Include(m => m.Whiteboard) .Include(m => m.Whiteboard)

View File

@@ -0,0 +1,5 @@
using AipsCore.Application.Abstract.Query;
namespace AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardHistory;
public record GetWhiteboardHistoryQuery : IQuery<ICollection<Infrastructure.Persistence.Whiteboard.Whiteboard>>;

View File

@@ -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<GetWhiteboardHistoryQuery, ICollection<Infrastructure.Persistence.Whiteboard.Whiteboard>>
{
private readonly AipsDbContext _context;
private readonly IUserContext _userContext;
public GetWhiteboardHistoryQueryHandler(AipsDbContext context, IUserContext userContext)
{
_context = context;
_userContext = userContext;
}
public async Task<ICollection<Infrastructure.Persistence.Whiteboard.Whiteboard>> Handle(GetWhiteboardHistoryQuery query, CancellationToken cancellationToken = default)
{
var userIdGuid = new Guid(_userContext.GetCurrentUserId().IdValue);
return await _context.Whiteboards
.Where(w => w.OwnerId == userIdGuid)
.ToListAsync(cancellationToken);
}
}

View File

@@ -5,9 +5,7 @@ namespace AipsCore.Application.Models.WhiteboardMembership.Command.CreateWhitebo
public record CreateWhiteboardMembershipCommand( public record CreateWhiteboardMembershipCommand(
string WhiteboardId, string WhiteboardId,
string UserId,
bool IsBanned, bool IsBanned,
bool EditingEnabled, bool EditingEnabled,
bool CanJoin, bool CanJoin)
DateTime LastInteractedAt)
: ICommand<WhiteboardMembershipId>; : ICommand<WhiteboardMembershipId>;

View File

@@ -1,4 +1,5 @@
using AipsCore.Application.Abstract.Command; using AipsCore.Application.Abstract.Command;
using AipsCore.Application.Abstract.UserContext;
using AipsCore.Domain.Abstract; using AipsCore.Domain.Abstract;
using AipsCore.Domain.Models.WhiteboardMembership.External; using AipsCore.Domain.Models.WhiteboardMembership.External;
using AipsCore.Domain.Models.WhiteboardMembership.ValueObjects; using AipsCore.Domain.Models.WhiteboardMembership.ValueObjects;
@@ -8,23 +9,30 @@ namespace AipsCore.Application.Models.WhiteboardMembership.Command.CreateWhitebo
public class CreateWhiteboardMembershipCommandHandler : ICommandHandler<CreateWhiteboardMembershipCommand, WhiteboardMembershipId> public class CreateWhiteboardMembershipCommandHandler : ICommandHandler<CreateWhiteboardMembershipCommand, WhiteboardMembershipId>
{ {
private readonly IWhiteboardMembershipRepository _whiteboardMembershipRepository; private readonly IWhiteboardMembershipRepository _whiteboardMembershipRepository;
private readonly IUserContext _userContext;
private readonly IUnitOfWork _unitOfWork; private readonly IUnitOfWork _unitOfWork;
public CreateWhiteboardMembershipCommandHandler(IWhiteboardMembershipRepository whiteboardMembershipRepository, IUnitOfWork unitOfWork) public CreateWhiteboardMembershipCommandHandler(
IWhiteboardMembershipRepository whiteboardMembershipRepository,
IUserContext userContext,
IUnitOfWork unitOfWork)
{ {
_whiteboardMembershipRepository = whiteboardMembershipRepository; _whiteboardMembershipRepository = whiteboardMembershipRepository;
_userContext = userContext;
_unitOfWork = unitOfWork; _unitOfWork = unitOfWork;
} }
public async Task<WhiteboardMembershipId> Handle(CreateWhiteboardMembershipCommand command, CancellationToken cancellationToken = default) public async Task<WhiteboardMembershipId> Handle(CreateWhiteboardMembershipCommand command, CancellationToken cancellationToken = default)
{ {
var userId = _userContext.GetCurrentUserId();
var whiteboardMembership = Domain.Models.WhiteboardMembership.WhiteboardMembership.Create( var whiteboardMembership = Domain.Models.WhiteboardMembership.WhiteboardMembership.Create(
command.WhiteboardId, command.WhiteboardId,
command.UserId, userId.IdValue,
command.IsBanned, command.IsBanned,
command.EditingEnabled, command.EditingEnabled,
command.CanJoin, command.CanJoin,
command.LastInteractedAt); DateTime.UtcNow);
await _whiteboardMembershipRepository.SaveAsync(whiteboardMembership, cancellationToken); await _whiteboardMembershipRepository.SaveAsync(whiteboardMembership, cancellationToken);
await _unitOfWork.SaveChangesAsync(cancellationToken); await _unitOfWork.SaveChangesAsync(cancellationToken);

View File

@@ -1,18 +1,16 @@
using AipsCore.Application.Abstract; 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.CreateWhiteboard;
using AipsCore.Application.Models.Whiteboard.Command.KickUserFromWhiteboard;
using AipsCore.Application.Models.Whiteboard.Command.UnbanUserFromWhiteboard;
using AipsCore.Application.Models.Whiteboard.Query.GetRecentWhiteboards; 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.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Whiteboard = AipsCore.Infrastructure.Persistence.Whiteboard.Whiteboard;
namespace AipsWebApi.Controllers; namespace AipsWebApi.Controllers;
[ApiController] [ApiController]
[Route("[controller]")] [Route("/api/[controller]")]
public class WhiteboardController : ControllerBase public class WhiteboardController : ControllerBase
{ {
private readonly IDispatcher _dispatcher; private readonly IDispatcher _dispatcher;
@@ -29,4 +27,28 @@ public class WhiteboardController : ControllerBase
var whiteboardId = await _dispatcher.Execute(command, cancellationToken); var whiteboardId = await _dispatcher.Execute(command, cancellationToken);
return Ok(whiteboardId.IdValue); return Ok(whiteboardId.IdValue);
} }
[Authorize]
[HttpGet("history")]
public async Task<ActionResult<ICollection<Whiteboard>>> GetWhiteboardHistory(CancellationToken cancellationToken)
{
var whiteboards = await _dispatcher.Execute(new GetWhiteboardHistoryQuery(), cancellationToken);
return Ok(whiteboards);
}
[Authorize]
[HttpGet("recent")]
public async Task<ActionResult<ICollection<Whiteboard>>> GetRecentWhiteboards(CancellationToken cancellationToken)
{
var whiteboards = await _dispatcher.Execute(new GetRecentWhiteboardsQuery(), cancellationToken);
return Ok(whiteboards);
}
[Authorize]
[HttpPost("join")]
public async Task<ActionResult> JoinWhiteboard(CreateWhiteboardMembershipCommand command, CancellationToken cancellationToken)
{
var result = await _dispatcher.Execute(command, cancellationToken);
return Ok(result);
}
} }