2026-08-17 20:58:08 +07:00
|
|
|
using MediatR;
|
2026-08-13 23:10:22 +07:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Mws.Application.Projects;
|
|
|
|
|
|
|
|
|
|
namespace Mws.Api.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/projects/{projectId:guid}/members")]
|
|
|
|
|
[Authorize]
|
2026-08-17 20:58:08 +07:00
|
|
|
public class ProjectMembersController(ISender sender) : ControllerBase
|
2026-08-13 23:10:22 +07:00
|
|
|
{
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<List<ProjectMemberDto>>> GetAll(Guid projectId, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-17 20:58:08 +07:00
|
|
|
return Ok(await sender.Send(new GetProjectMembersQuery(User.GetUserId(), projectId), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<ActionResult<ProjectMemberDto>> Add(Guid projectId, [FromBody] AddMemberRequest request, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-17 20:58:08 +07:00
|
|
|
return Ok(await sender.Send(new AddProjectMemberCommand(User.GetUserId(), projectId, request), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut("{userId:guid}/document-permissions")]
|
|
|
|
|
public async Task<ActionResult<ProjectMemberDto>> UpdateDocumentPermissions(
|
|
|
|
|
Guid projectId, Guid userId, [FromBody] UpdateMemberDocumentPermissionsRequest request, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-17 20:58:08 +07:00
|
|
|
return Ok(await sender.Send(new UpdateMemberDocumentPermissionsCommand(User.GetUserId(), projectId, userId, request), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("{userId:guid}")]
|
|
|
|
|
public async Task<IActionResult> Remove(Guid projectId, Guid userId, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-17 20:58:08 +07:00
|
|
|
await sender.Send(new RemoveProjectMemberCommand(User.GetUserId(), projectId, userId), ct);
|
2026-08-13 23:10:22 +07:00
|
|
|
return NoContent();
|
|
|
|
|
}
|
2026-08-17 20:58:08 +07:00
|
|
|
}
|