-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProjectUsersController.cs
53 lines (44 loc) · 1.81 KB
/
ProjectUsersController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using BugLab.Business.Commands.Projects;
using BugLab.Business.Interfaces;
using BugLab.Business.Queries.Projects;
using BugLab.Data.Extensions;
using BugLab.Shared.Responses;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace BugLab.API.Controllers
{
[Route("api/projects/{projectId}/[controller]")]
public class ProjectUsersController : BaseApiController
{
private readonly IAuthService _authService;
public ProjectUsersController(IMediator mediator, IAuthService authService) : base(mediator)
{
_authService = authService;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<UserResponse>>> GetProjectUsers(int projectId, CancellationToken cancellationToken)
{
var users = await _mediator.Send(new GetProjectUsersQuery(projectId), cancellationToken);
return Ok(users);
}
[HttpPost]
public async Task<IActionResult> AddUsersToProject(int projectId, [FromQuery] IEnumerable<string> userIds, CancellationToken cancellationToken)
{
if (!userIds.Any()) return NoContent();
await _authService.HasAccessToProject(User.UserId(), projectId);
await _mediator.Send(new AddProjectUsersCommand(projectId, userIds), cancellationToken);
return NoContent();
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteProjectUser(int projectId, string id, CancellationToken cancellationToken)
{
await _authService.HasAccessToProject(User.UserId(), projectId);
await _mediator.Send(new DeleteProjectUserCommand(projectId, id), cancellationToken);
return NoContent();
}
}
}