summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-08-06 23:59:27 +0200
committerivarlovlie <git@ivarlovlie.no>2022-08-06 23:59:27 +0200
commit3c310160ce280d39952dd4d4c8d8b942674b6569 (patch)
treecbae931b4753c9c5d624866611626d9ca9a7c6c3 /server/src
parent13153a62c17db7c84d173434cec7eed29e4593b7 (diff)
downloadgreatoffice-3c310160ce280d39952dd4d4c8d8b942674b6569.tar.xz
greatoffice-3c310160ce280d39952dd4d4c8d8b942674b6569.zip
refactor: Query for smallest amout of data
Diffstat (limited to 'server/src')
-rw-r--r--server/src/Endpoints/Internal/Account/GetRoute.cs47
1 files changed, 24 insertions, 23 deletions
diff --git a/server/src/Endpoints/Internal/Account/GetRoute.cs b/server/src/Endpoints/Internal/Account/GetRoute.cs
index 34a3c97..1aa7ecb 100644
--- a/server/src/Endpoints/Internal/Account/GetRoute.cs
+++ b/server/src/Endpoints/Internal/Account/GetRoute.cs
@@ -2,29 +2,30 @@ namespace IOL.GreatOffice.Api.Endpoints.Internal.Account;
public class GetAccountRoute : RouteBaseAsync.WithoutRequest.WithActionResult<LoggedInUserModel>
{
- private readonly AppDbContext _context;
+ private readonly AppDbContext _context;
- /// <inheritdoc />
- public GetAccountRoute(AppDbContext context) {
- _context = context;
- }
+ public GetAccountRoute(AppDbContext context) {
+ _context = context;
+ }
- /// <summary>
- /// Get the logged on user's session data.
- /// </summary>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- [HttpGet("~/_/account")]
- public override async Task<ActionResult<LoggedInUserModel>> HandleAsync(CancellationToken cancellationToken = default) {
- var user = _context.Users.SingleOrDefault(c => c.Id == LoggedInUser.Id);
- if (user != default) {
- return Ok(new LoggedInUserModel {
- Id = LoggedInUser.Id,
- Username = LoggedInUser.Username
- });
- }
+ /// <summary>
+ /// Get the logged on user's session data.
+ /// </summary>
+ /// <param name="cancellationToken"></param>
+ /// <returns></returns>
+ [HttpGet("~/_/account")]
+ public override async Task<ActionResult<LoggedInUserModel>> HandleAsync(CancellationToken cancellationToken = default) {
+ var user = _context.Users
+ .Select(x => new {x.Username, x.Id})
+ .SingleOrDefault(c => c.Id == LoggedInUser.Id);
+ if (user != default) {
+ return Ok(new LoggedInUserModel {
+ Id = LoggedInUser.Id,
+ Username = LoggedInUser.Username
+ });
+ }
- await HttpContext.SignOutAsync();
- return Unauthorized();
- }
-}
+ await HttpContext.SignOutAsync();
+ return Unauthorized();
+ }
+} \ No newline at end of file