-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTaskController.cs
More file actions
138 lines (125 loc) · 4.92 KB
/
Copy pathTaskController.cs
File metadata and controls
138 lines (125 loc) · 4.92 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using PayrollEngine.Api.Core;
using PayrollEngine.Domain.Application.Service;
using PayrollEngine.Domain.Model;
using ApiObject = PayrollEngine.Api.Model;
namespace PayrollEngine.Backend.Controller;
/// <inheritdoc/>
[ApiControllerName("Tasks")]
[Route("api/tenants/{tenantId}/tasks")]
[TenantAuthorize]
public class TaskController : Api.Controller.TaskController
{
/// <inheritdoc/>
public TaskController(ITenantService tenantService, ITaskService taskService,
IUserService userService, IWebhookDispatchService webhookDispatcher, IControllerRuntime runtime) :
base(tenantService, taskService, userService, webhookDispatcher, runtime)
{
}
/// <summary>
/// Query tasks
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="query">Query parameters</param>
/// <returns>The tenant tasks</returns>
[HttpGet]
[OkResponse]
[NotFoundResponse]
[UnprocessableEntityResponse]
[ApiOperationId("QueryTasks")]
public async Task<ActionResult> QueryTasksAsync(int tenantId, [FromQuery] Query query) =>
await QueryItemsAsync(tenantId, query);
/// <summary>
/// Get a task
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="taskId">The id of the task</param>
/// <returns>The tenant task</returns>
[HttpGet("{taskId}")]
[OkResponse]
[NotFoundResponse]
[ApiOperationId("GetTask")]
public async Task<ActionResult<ApiObject.Task>> GetTaskAsync(int tenantId, int taskId) =>
await GetAsync(tenantId, taskId);
/// <summary>
/// Add a new task
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="task">The task to add</param>
/// <returns>The newly created task</returns>
[HttpPost]
[CreatedResponse]
[NotFoundResponse]
[UnprocessableEntityResponse]
[ApiOperationId("CreateTask")]
public async Task<ActionResult<ApiObject.Task>> CreateTaskAsync(int tenantId, ApiObject.Task task) =>
await CreateAsync(tenantId, task);
/// <summary>
/// Update a task
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="task">The task with updated values</param>
/// <returns>The modified task</returns>
[HttpPut("{taskId}")]
[OkResponse]
[NotFoundResponse]
[UnprocessableEntityResponse]
[ApiOperationId("UpdateTask")]
public async Task<ActionResult<ApiObject.Task>> UpdateTaskAsync(int tenantId, ApiObject.Task task) =>
await UpdateAsync(tenantId, task);
/// <summary>
/// Delete a task
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="taskId">The id of the task</param>
[HttpDelete("{taskId}")]
[ApiOperationId("DeleteTask")]
public async Task<IActionResult> DeleteTaskAsync(int tenantId, int taskId) =>
await DeleteAsync(tenantId, taskId);
#region Attributes
/// <summary>
/// Get a task attribute
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="taskId">The id of the task</param>
/// <param name="attributeName">The attribute name</param>
/// <returns>The attribute value as JSON</returns>
[HttpGet("{taskId}/attributes/{attributeName}")]
[OkResponse]
[NotFoundResponse]
[ApiOperationId("GetTaskAttribute")]
public virtual async Task<ActionResult<string>> GetTaskAttributeAsync(
int tenantId, int taskId, string attributeName) =>
await GetAttributeAsync(taskId, attributeName);
/// <summary>
/// Set a task attribute
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="taskId">The id of the task</param>
/// <param name="attributeName">The attribute name</param>
/// <param name="value">The attribute value as JSON</param>
/// <returns>The current attribute value as JSON</returns>
[HttpPost("{taskId}/attributes/{attributeName}")]
[CreatedResponse]
[NotFoundResponse]
[UnprocessableEntityResponse]
[ApiOperationId("SetTaskAttribute")]
public virtual async Task<ActionResult<string>> SetTaskAttributeAsync(
int tenantId, int taskId, string attributeName,
[FromBody] string value) =>
await SetAttributeAsync(taskId, attributeName, value);
/// <summary>
/// Delete a task attribute
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="taskId">The id of the task</param>
/// <param name="attributeName">The attribute name</param>
/// <returns>True if the attribute was deleted</returns>
[HttpDelete("{taskId}/attributes/{attributeName}")]
[ApiOperationId("DeleteTaskAttribute")]
public virtual async Task<ActionResult<bool>> DeleteTaskAttributeAsync(
int tenantId, int taskId, string attributeName) =>
await DeleteAttributeAsync(taskId, attributeName);
#endregion
}