|
1 | 1 | using AdvancedTodoList.Core.Dtos; |
2 | 2 | using AdvancedTodoList.Core.Pagination; |
3 | 3 | using AdvancedTodoList.Core.Services; |
4 | | -using AdvancedTodoList.Extensions; |
| 4 | +using AdvancedTodoList.WebApp.Extensions; |
5 | 5 | using Microsoft.AspNetCore.Authorization; |
6 | 6 | using Microsoft.AspNetCore.Mvc; |
7 | 7 |
|
8 | | -namespace AdvancedTodoList.Controllers; |
| 8 | +namespace AdvancedTodoList.WebApp.Controllers; |
9 | 9 |
|
10 | 10 | [Authorize] |
11 | 11 | [ApiController] |
12 | 12 | [Route("api/todo/{listId}/invitationLinks")] |
13 | 13 | public class InvitationLinksController(IInvitationLinksService invitationLinksService) : ControllerBase |
14 | 14 | { |
15 | | - private readonly IInvitationLinksService _invitationLinksService = invitationLinksService; |
| 15 | + private readonly IInvitationLinksService _invitationLinksService = invitationLinksService; |
16 | 16 |
|
17 | | - /// <summary> |
18 | | - /// Gets a page with invitation links of the to-do list with the specified ID. |
19 | | - /// </summary> |
20 | | - /// <param name="listId">ID of the to-do list.</param> |
21 | | - /// <param name="paginationParameters">Paginations parameters to apply.</param> |
22 | | - /// <response code="200">Returns invitation links of the to-do list.</response> |
23 | | - /// <response code="401">Authentication failed.</response> |
24 | | - /// <response code="403">User has no permission to perform this action.</response> |
25 | | - /// <response code="404">To-do list was not found.</response> |
26 | | - [HttpGet(Name = nameof(GetInvitationLinksAsync))] |
27 | | - [ProducesResponseType(typeof(Page<InvitationLinkDto>), StatusCodes.Status200OK)] |
28 | | - [ProducesResponseType(StatusCodes.Status401Unauthorized)] |
29 | | - [ProducesResponseType(StatusCodes.Status403Forbidden)] |
30 | | - [ProducesResponseType(StatusCodes.Status404NotFound)] |
31 | | - public async Task<IActionResult> GetInvitationLinksAsync( |
32 | | - [FromRoute] string listId, [FromQuery] PaginationParameters paginationParameters) |
33 | | - { |
34 | | - TodoListContext context = new(listId, User.GetUserId()!); |
35 | | - var result = await _invitationLinksService.GetInvitationLinksAsync(context, paginationParameters); |
36 | | - return result.ToActionResult(); |
37 | | - } |
| 17 | + /// <summary> |
| 18 | + /// Gets a page with invitation links of the to-do list with the specified ID. |
| 19 | + /// </summary> |
| 20 | + /// <param name="listId">ID of the to-do list.</param> |
| 21 | + /// <param name="paginationParameters">Paginations parameters to apply.</param> |
| 22 | + /// <response code="200">Returns invitation links of the to-do list.</response> |
| 23 | + /// <response code="401">Authentication failed.</response> |
| 24 | + /// <response code="403">User has no permission to perform this action.</response> |
| 25 | + /// <response code="404">To-do list was not found.</response> |
| 26 | + [HttpGet(Name = nameof(GetInvitationLinksAsync))] |
| 27 | + [ProducesResponseType(typeof(Page<InvitationLinkDto>), StatusCodes.Status200OK)] |
| 28 | + [ProducesResponseType(StatusCodes.Status401Unauthorized)] |
| 29 | + [ProducesResponseType(StatusCodes.Status403Forbidden)] |
| 30 | + [ProducesResponseType(StatusCodes.Status404NotFound)] |
| 31 | + public async Task<IActionResult> GetInvitationLinksAsync( |
| 32 | + [FromRoute] string listId, [FromQuery] PaginationParameters paginationParameters) |
| 33 | + { |
| 34 | + TodoListContext context = new(listId, User.GetUserId()!); |
| 35 | + var result = await _invitationLinksService.GetInvitationLinksAsync(context, paginationParameters); |
| 36 | + return result.ToActionResult(); |
| 37 | + } |
38 | 38 |
|
39 | | - /// <summary> |
40 | | - /// Creates a new to-do list invitation link. |
41 | | - /// </summary> |
42 | | - /// <param name="listId">ID of the to-do list which will contain the invitation link.</param> |
43 | | - /// <response code="200">Successfully created.</response> |
44 | | - /// <response code="400">Validation failed.</response> |
45 | | - /// <response code="401">Authentication failed.</response> |
46 | | - /// <response code="403">User has no permission to perform this action.</response> |
47 | | - /// <response code="404">To-do list was not found.</response> |
48 | | - [HttpPost] |
49 | | - [ProducesResponseType(typeof(InvitationLinkDto), StatusCodes.Status200OK)] |
50 | | - [ProducesResponseType(StatusCodes.Status400BadRequest)] |
51 | | - [ProducesResponseType(StatusCodes.Status401Unauthorized)] |
52 | | - [ProducesResponseType(StatusCodes.Status403Forbidden)] |
53 | | - [ProducesResponseType(StatusCodes.Status404NotFound)] |
54 | | - public async Task<IActionResult> PostInvitationLinkAsync([FromRoute] string listId) |
55 | | - { |
56 | | - TodoListContext context = new(listId, User.GetUserId()!); |
57 | | - var response = await _invitationLinksService.CreateAsync(context); |
58 | | - return response.ToActionResult(); |
59 | | - } |
| 39 | + /// <summary> |
| 40 | + /// Creates a new to-do list invitation link. |
| 41 | + /// </summary> |
| 42 | + /// <param name="listId">ID of the to-do list which will contain the invitation link.</param> |
| 43 | + /// <response code="200">Successfully created.</response> |
| 44 | + /// <response code="400">Validation failed.</response> |
| 45 | + /// <response code="401">Authentication failed.</response> |
| 46 | + /// <response code="403">User has no permission to perform this action.</response> |
| 47 | + /// <response code="404">To-do list was not found.</response> |
| 48 | + [HttpPost] |
| 49 | + [ProducesResponseType(typeof(InvitationLinkDto), StatusCodes.Status200OK)] |
| 50 | + [ProducesResponseType(StatusCodes.Status400BadRequest)] |
| 51 | + [ProducesResponseType(StatusCodes.Status401Unauthorized)] |
| 52 | + [ProducesResponseType(StatusCodes.Status403Forbidden)] |
| 53 | + [ProducesResponseType(StatusCodes.Status404NotFound)] |
| 54 | + public async Task<IActionResult> PostInvitationLinkAsync([FromRoute] string listId) |
| 55 | + { |
| 56 | + TodoListContext context = new(listId, User.GetUserId()!); |
| 57 | + var response = await _invitationLinksService.CreateAsync(context); |
| 58 | + return response.ToActionResult(); |
| 59 | + } |
60 | 60 |
|
61 | | - /// <summary> |
62 | | - /// Deletes a to-do list invitation link. |
63 | | - /// </summary> |
64 | | - /// <response code="204">Success.</response> |
65 | | - /// <response code="401">Authentication failed.</response> |
66 | | - /// <response code="403">User has no permission to perform this action.</response> |
67 | | - /// <response code="404">To-do list invitation link was not found.</response> |
68 | | - [HttpDelete("{invitationLinkId}")] |
69 | | - [ProducesResponseType(StatusCodes.Status204NoContent)] |
70 | | - [ProducesResponseType(StatusCodes.Status401Unauthorized)] |
71 | | - [ProducesResponseType(StatusCodes.Status403Forbidden)] |
72 | | - [ProducesResponseType(StatusCodes.Status404NotFound)] |
73 | | - public async Task<IActionResult> DeleteInvitationLinkAsync( |
74 | | - [FromRoute] string listId, [FromRoute] int invitationLinkId) |
75 | | - { |
76 | | - TodoListContext context = new(listId, User.GetUserId()!); |
77 | | - var result = await _invitationLinksService.DeleteAsync(context, invitationLinkId); |
78 | | - return result.ToActionResult(); |
79 | | - } |
| 61 | + /// <summary> |
| 62 | + /// Deletes a to-do list invitation link. |
| 63 | + /// </summary> |
| 64 | + /// <response code="204">Success.</response> |
| 65 | + /// <response code="401">Authentication failed.</response> |
| 66 | + /// <response code="403">User has no permission to perform this action.</response> |
| 67 | + /// <response code="404">To-do list invitation link was not found.</response> |
| 68 | + [HttpDelete("{invitationLinkId}")] |
| 69 | + [ProducesResponseType(StatusCodes.Status204NoContent)] |
| 70 | + [ProducesResponseType(StatusCodes.Status401Unauthorized)] |
| 71 | + [ProducesResponseType(StatusCodes.Status403Forbidden)] |
| 72 | + [ProducesResponseType(StatusCodes.Status404NotFound)] |
| 73 | + public async Task<IActionResult> DeleteInvitationLinkAsync( |
| 74 | + [FromRoute] string listId, [FromRoute] int invitationLinkId) |
| 75 | + { |
| 76 | + TodoListContext context = new(listId, User.GetUserId()!); |
| 77 | + var result = await _invitationLinksService.DeleteAsync(context, invitationLinkId); |
| 78 | + return result.ToActionResult(); |
| 79 | + } |
80 | 80 | } |
0 commit comments