-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSprintsController.cs
60 lines (50 loc) · 2.17 KB
/
SprintsController.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
54
55
56
57
58
59
60
using BugLab.Business.Commands.Sprints;
using BugLab.Business.Interfaces;
using BugLab.Business.Queries.Sprints;
using BugLab.Data.Extensions;
using BugLab.Shared.Requests.Sprints;
using BugLab.Shared.Responses;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace BugLab.API.Controllers
{
[Route("api/projects/{projectId}/[controller]")]
public class SprintsController : BaseApiController
{
private readonly IAuthService _authService;
public SprintsController(IMediator mediator, IAuthService authService) : base(mediator)
{
_authService = authService;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<SprintForListResponse>>> GetSprints(int projectId, CancellationToken cancellationToken)
{
var sprints = await _mediator.Send(new GetSprintsQuery(projectId), cancellationToken);
return Ok(sprints);
}
[HttpGet("{id}", Name = nameof(GetSprint))]
public async Task<ActionResult<SprintDetailsResponse>> GetSprint(int id, CancellationToken cancellationToken)
{
var sprint = await _mediator.Send(new GetSprintQuery(id), cancellationToken);
return Ok(sprint);
}
[HttpDelete("{id}")]
public async Task<ActionResult<SprintDetailsResponse>> DeleteSprint(int projectId, int id, CancellationToken cancellationToken)
{
await _authService.HasAccessToProject(User.UserId(), projectId);
await _mediator.Send(new DeleteSprintCommand(id), cancellationToken);
return NoContent();
}
[HttpPost]
public async Task<IActionResult> AddSprint(int projectId, AddSprintRequest request, CancellationToken cancellationToken)
{
await _authService.HasAccessToProject(User.UserId(), projectId);
var command = new AddSprintCommand(projectId, request.Title, request.StartDate, request.EndDate);
var id = await _mediator.Send(command, cancellationToken);
return CreatedAtRoute(nameof(GetSprint), new { projectId, id }, id);
}
}
}