From 3c310160ce280d39952dd4d4c8d8b942674b6569 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Sat, 6 Aug 2022 23:59:27 +0200 Subject: refactor: Query for smallest amout of data --- server/src/Endpoints/Internal/Account/GetRoute.cs | 47 ++++++++++++----------- 1 file 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 { - private readonly AppDbContext _context; + private readonly AppDbContext _context; - /// - public GetAccountRoute(AppDbContext context) { - _context = context; - } + public GetAccountRoute(AppDbContext context) { + _context = context; + } - /// - /// Get the logged on user's session data. - /// - /// - /// - [HttpGet("~/_/account")] - public override async Task> 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 - }); - } + /// + /// Get the logged on user's session data. + /// + /// + /// + [HttpGet("~/_/account")] + public override async Task> 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 -- cgit v1.3