-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTenantController.cs
More file actions
214 lines (197 loc) · 8 KB
/
Copy pathTenantController.cs
File metadata and controls
214 lines (197 loc) · 8 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using PayrollEngine.Api.Core;
using PayrollEngine.Data;
using PayrollEngine.Domain.Application.Service;
using ApiObject = PayrollEngine.Api.Model;
namespace PayrollEngine.Backend.Controller;
/// <inheritdoc/>
[ApiControllerName("Tenants")]
[Route("api/tenants")]
[TenantAuthorize]
public class TenantController : Api.Controller.TenantController
{
/// <inheritdoc/>
public TenantController(ITenantService tenantService,
IRegulationService regulationService, IRegulationShareService regulationShareService, IReportService reportService,
IControllerRuntime runtime) :
base(tenantService, regulationService, regulationShareService, reportService, runtime)
{
}
/// <summary>
/// Query tenants
/// </summary>
/// <param name="query">Query parameters</param>
/// <returns>The tenants matching the query</returns>
[HttpGet]
[OkResponse]
[NotFoundResponse]
[UnprocessableEntityResponse]
[ApiOperationId("QueryTenants")]
[SkipTenantAuth]
public async Task<ActionResult> QueryTenantsAsync([FromQuery] Query query) =>
await QueryItemsAsync(query);
/// <summary>
/// Add a new tenant
/// </summary>
/// <remarks>No authorization check</remarks>
/// <param name="tenant">The tenant to add</param>
/// <returns>The newly created tenant</returns>
[HttpPost]
[CreatedResponse]
[NotFoundResponse]
[UnprocessableEntityResponse]
[ApiOperationId("CreateTenant")]
[SkipTenantAuth]
public async Task<ActionResult<ApiObject.Tenant>> CreateTenantAsync(ApiObject.Tenant tenant)
{
// unique tenant by identifier
if (await Service.ExistsAsync(Runtime.DbContext, tenant.Identifier))
{
return BadRequest($"Tenant with identifier {tenant.Identifier} already exists");
}
return await CreateAsync(tenant);
}
/// <summary>
/// Update a tenant
/// </summary>
/// <remarks>No authorization check</remarks>
/// <param name="tenant">The tenant with updated values</param>
/// <returns>The modified tenant</returns>
[HttpPut("{tenantId}")]
[OkResponse]
[NotFoundResponse]
[UnprocessableEntityResponse]
[ApiOperationId("UpdateTenant")]
[SkipTenantAuth]
public async Task<ActionResult<ApiObject.Tenant>> UpdateTenantAsync(ApiObject.Tenant tenant) =>
await UpdateAsync(tenant);
/// <summary>
/// Delete a tenant including all tenant data
/// </summary>
/// <remarks>No authorization check</remarks>
/// <param name="tenantId">The tenant id</param>
[HttpDelete("{tenantId}")]
[ApiOperationId("DeleteTenant")]
[SkipTenantAuth]
public async Task<IActionResult> DeleteTenantAsync(int tenantId) =>
await DeleteAsync(tenantId);
/// <summary>
/// Get a tenant
/// </summary>
/// <remarks>No authorization check</remarks>
/// <param name="tenantId">The tenant id</param>
[HttpGet("{tenantId}")]
[OkResponse]
[NotFoundResponse]
[UnprocessableEntityResponse]
[ApiOperationId("GetTenant")]
[SkipTenantAuth]
public async Task<ActionResult<ApiObject.Tenant>> GetTenantAsync(int tenantId) =>
await GetAsync(tenantId);
/// <summary>
/// Get tenant shared regulations
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="divisionId">The division id</param>
/// <returns>The tenant shared regulations</returns>
[HttpGet("{tenantId}/shared/regulations")]
[OkResponse]
[NotFoundResponse]
[ApiOperationId("GetTenantSharedRegulations")]
public override async Task<ActionResult<IEnumerable<ApiObject.Regulation>>> GetSharedRegulationsAsync(
int tenantId, [FromQuery] int? divisionId) =>
await base.GetSharedRegulationsAsync(tenantId, divisionId);
/// <summary>
/// Get the system script actions
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="functionType">The function type</param>
/// <returns>List of system actions</returns>
[HttpGet("{tenantId}/system/actions")]
[OkResponse]
[ApiOperationId("GetSystemScriptActions")]
[QueryIgnore]
public override async Task<ActionResult<IEnumerable<ApiObject.ActionInfo>>> GetSystemScriptActionsAsync(
int tenantId, FunctionType functionType = FunctionType.All) =>
await base.GetSystemScriptActionsAsync(tenantId, functionType);
/// <summary>
/// Get the system script action properties
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="functionType">The function type</param>
/// <param name="readOnly">Read-only properties (default: true)</param>
/// <returns>List of system actions</returns>
[HttpGet("{tenantId}/system/properties")]
[OkResponse]
[ApiOperationId("GetSystemScriptActionProperties")]
[QueryIgnore]
public override async Task<ActionResult<IEnumerable<ApiObject.ActionInfo>>> GetSystemScriptActionPropertiesAsync(
int tenantId, FunctionType functionType = FunctionType.All, bool readOnly = true) =>
await base.GetSystemScriptActionPropertiesAsync(tenantId, functionType, readOnly);
/// <summary>
/// Execute a report query
/// </summary>
/// <remarks>
/// Request body contains array of case values (optional)
/// Without the request body, this would be a GET method
/// </remarks>
/// <param name="tenantId">The tenant id</param>
/// <param name="methodName">The query method</param>
/// <param name="culture">The data culture</param>
/// <param name="parameters">The query parameters</param>
/// <returns>The resulting data table</returns>
[HttpPost("{tenantId}/queries")]
[OkResponse]
[NotFoundResponse]
[ApiOperationId("ExecuteReportQuery")]
[QueryIgnore]
[ReadSemantic]
public override async Task<ActionResult<DataTable>> ExecuteReportQueryAsync(int tenantId,
[FromQuery] string methodName, [FromQuery] string culture,
[FromBody] Dictionary<string, string> parameters = null) =>
await base.ExecuteReportQueryAsync(tenantId, methodName, culture, parameters);
#region Attributes
/// <summary>
/// Get a tenant attribute
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="attributeName">The attribute name</param>
/// <returns>The attribute value as JSON</returns>
[HttpGet("{tenantId}/attributes/{attributeName}")]
[OkResponse]
[NotFoundResponse]
[UnprocessableEntityResponse]
[ApiOperationId("GetTenantAttribute")]
public virtual async Task<ActionResult<string>> GetTenantAttributeAsync(
int tenantId, string attributeName) =>
await GetAttributeAsync(tenantId, attributeName);
/// <summary>
/// Set a tenant attribute
/// </summary>
/// <param name="tenantId">The tenant id</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("{tenantId}/attributes/{attributeName}")]
[CreatedResponse]
[NotFoundResponse]
[UnprocessableEntityResponse]
[ApiOperationId("SetTenantAttribute")]
public virtual async Task<ActionResult<string>> SetTenantAttributeAsync(
int tenantId, string attributeName, [FromBody] string value) =>
await SetAttributeAsync(tenantId, attributeName, value);
/// <summary>
/// Delete a tenant attribute
/// </summary>
/// <param name="tenantId">The tenant id</param>
/// <param name="attributeName">The attribute name</param>
/// <returns>True if the attribute was deleted</returns>
[HttpDelete("{tenantId}/attributes/{attributeName}")]
[ApiOperationId("DeleteTenantAttribute")]
public virtual async Task<ActionResult<bool>> DeleteTenantAttributeAsync(
int tenantId, string attributeName) =>
await DeleteAttributeAsync(tenantId, attributeName);
#endregion
}