-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTodoController.cs
More file actions
80 lines (72 loc) · 2.65 KB
/
TodoController.cs
File metadata and controls
80 lines (72 loc) · 2.65 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Reflection.Metadata.Ecma335;
using System.Security.AccessControl;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.FeatureManagement;
using Microsoft.FeatureManagement.Mvc;
using referenceApp.Api.Infrastructure;
using referenceApp.Api.Models;
using referenceApp.Lib.Todos.CreateNewTodo;
using referenceApp.Lib.Todos.Models;
using referenceApp.Lib.Todos.Queries;
using referenceApp.Lib.Todos.ToggleTodoComplete;
using referenceApp.Api.System;
using referenceApp.Common.Models.System;
namespace referenceApp.Api.Controllers
{
public class TodoController : ApiControllerBase
{
public TodoController(IFeatureManager featureManager, IUserSecurityService userSecurity, ISettingsData settingsData)
: base(featureManager, userSecurity, settingsData)
{
}
[HttpGet]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<List<TodoModel>>> List([FromQuery] int? _limit = null, [FromQuery] int? _page = null)
{
var result = await Mediator.Send(new GetTodosListQuery(_limit, _page));
return new OkObjectResult(result.Todos);
}
[HttpGet("{id}")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<TodoModel>> GetTodo(Guid id)
{
return await Mediator.Send(new FindTodoByIdQuery(id));
}
[HttpPost]
[Produces("application/json")]
[Consumes("application/json")]
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task<TodoModel> CreateNewTask([FromBody] NewTodoModel model)
{
var command = new CreateNewTodoCommand
{
Title = model.Title,
Description = model.Description,
IsUrgent = model.IsUrgent
};
return await Mediator.Send(command);
}
[HttpPut("{id}")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> ToggleIsComplete(string id)
{
await Mediator.Send(new TodoToggleIsCompleteCommand(id));
return new NoContentResult();
}
[HttpDelete("{id}")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK)]
[FeatureGate(FeatureFlags.DeleteTodo)]
public IActionResult Delete(string id)
{
return Ok();
}
}
}