aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/src/Endpoints/V1/ApiTokens/GetTokensRoute.cs
diff options
context:
space:
mode:
Diffstat (limited to 'code/api/src/Endpoints/V1/ApiTokens/GetTokensRoute.cs')
-rw-r--r--code/api/src/Endpoints/V1/ApiTokens/GetTokensRoute.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/code/api/src/Endpoints/V1/ApiTokens/GetTokensRoute.cs b/code/api/src/Endpoints/V1/ApiTokens/GetTokensRoute.cs
new file mode 100644
index 0000000..ee46b34
--- /dev/null
+++ b/code/api/src/Endpoints/V1/ApiTokens/GetTokensRoute.cs
@@ -0,0 +1,36 @@
+namespace IOL.GreatOffice.Api.Endpoints.V1.ApiTokens;
+
+public class GetTokensRoute : RouteBaseSync.WithoutRequest.WithResult<ActionResult<List<GetTokensRoute.ResponseModel>>>
+{
+ private readonly MainAppDatabase _database;
+
+ public GetTokensRoute(MainAppDatabase database) {
+ _database = database;
+ }
+
+ public class ResponseModel
+ {
+ public DateTime ExpiryDate { get; set; }
+ public bool AllowRead { get; set; }
+ public bool AllowCreate { get; set; }
+ public bool AllowUpdate { get; set; }
+ public bool AllowDelete { get; set; }
+ public bool HasExpired => ExpiryDate < AppDateTime.UtcNow;
+ }
+
+ /// <summary>
+ /// Get all tokens, both active and inactive.
+ /// </summary>
+ /// <returns>A list of tokens</returns>
+ [ApiVersion(ApiSpecV1.VERSION_STRING)]
+ [HttpGet("~/v{version:apiVersion}/api-tokens")]
+ public override ActionResult<List<ResponseModel>> Handle() {
+ return Ok(_database.AccessTokens.Where(c => c.User.Id == LoggedInUser.Id).Select(c => new ResponseModel() {
+ AllowCreate = c.AllowCreate,
+ AllowRead = c.AllowRead,
+ AllowDelete = c.AllowDelete,
+ AllowUpdate = c.AllowUpdate,
+ ExpiryDate = c.ExpiryDate
+ }));
+ }
+} \ No newline at end of file