feat: pivot to social media workflow app
This commit is contained in:
49
backend/Modules/Workspaces/Handlers/GetWorkspaceInvites.cs
Normal file
49
backend/Modules/Workspaces/Handlers/GetWorkspaceInvites.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Socialize.Infrastructure.Security;
|
||||
using Socialize.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Modules.Workspaces.Handlers;
|
||||
|
||||
public record WorkspaceInviteDto(
|
||||
Guid Id,
|
||||
Guid WorkspaceId,
|
||||
string Email,
|
||||
string Role,
|
||||
string Status,
|
||||
DateTimeOffset CreatedAt);
|
||||
|
||||
public class GetWorkspaceInvitesHandler(
|
||||
AppDbContext dbContext,
|
||||
AccessScopeService accessScopeService)
|
||||
: EndpointWithoutRequest<IReadOnlyCollection<WorkspaceInviteDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/workspaces/{workspaceId:guid}/invites");
|
||||
Options(o => o.WithTags("Workspaces"));
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
Guid workspaceId = Route<Guid>("workspaceId");
|
||||
|
||||
if (!accessScopeService.CanManageWorkspace(User, workspaceId))
|
||||
{
|
||||
await SendForbiddenAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
List<WorkspaceInviteDto> invites = await dbContext.WorkspaceInvites
|
||||
.Where(invite => invite.WorkspaceId == workspaceId)
|
||||
.OrderByDescending(invite => invite.CreatedAt)
|
||||
.Select(invite => new WorkspaceInviteDto(
|
||||
invite.Id,
|
||||
invite.WorkspaceId,
|
||||
invite.Email,
|
||||
invite.Role,
|
||||
invite.Status,
|
||||
invite.CreatedAt))
|
||||
.ToListAsync(ct);
|
||||
|
||||
await SendOkAsync(invites, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user