For getting whiteboard info
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
using AipsCore.Application.Abstract.Query;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Query.GetWhiteboard;
|
||||
|
||||
public record GetWhiteboardQuery(string WhiteboardId) : IQuery<Infrastructure.Persistence.Whiteboard.Whiteboard?>;
|
||||
@@ -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<GetWhiteboardQuery, Infrastructure.Persistence.Whiteboard.Whiteboard?>
|
||||
{
|
||||
private readonly AipsDbContext _context;
|
||||
|
||||
public GetWhiteboardQueryHandler(AipsDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Infrastructure.Persistence.Whiteboard.Whiteboard?> Handle(GetWhiteboardQuery query, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.Whiteboards
|
||||
.Where(w => w.Id.ToString() == query.WhiteboardId)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -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,12 +23,24 @@ public class WhiteboardController : ControllerBase
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<int>> CreateWhiteboard(CreateWhiteboardCommand command, CancellationToken cancellationToken)
|
||||
public async Task<ActionResult<string>> CreateWhiteboard(CreateWhiteboardCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var whiteboardId = await _dispatcher.Execute(command, cancellationToken);
|
||||
return Ok(whiteboardId.IdValue);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("{whiteboardId}")]
|
||||
public async Task<ActionResult<Whiteboard>> 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")]
|
||||
public async Task<ActionResult<ICollection<Whiteboard>>> GetWhiteboardHistory(CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user