From 1d1b7b8716c9214d20bf720b9213959340422064 Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 13 Jun 2020 19:44:01 +0200 Subject: [PATCH] Migrate GetSystemByToken --- PluralKit.API/Services/TokenAuthService.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/PluralKit.API/Services/TokenAuthService.cs b/PluralKit.API/Services/TokenAuthService.cs index 0b041013..36c6defe 100644 --- a/PluralKit.API/Services/TokenAuthService.cs +++ b/PluralKit.API/Services/TokenAuthService.cs @@ -1,5 +1,8 @@ using System.Linq; using System.Threading.Tasks; + +using Dapper; + using Microsoft.AspNetCore.Http; using PluralKit.Core; @@ -10,11 +13,11 @@ namespace PluralKit.API { public PKSystem CurrentSystem { get; set; } - private IDataStore _data; + private readonly IDatabase _db; - public TokenAuthService(IDataStore data) + public TokenAuthService(IDatabase db) { - _data = data; + _db = db; } public async Task InvokeAsync(HttpContext context, RequestDelegate next) @@ -22,7 +25,7 @@ namespace PluralKit.API var token = context.Request.Headers["Authorization"].FirstOrDefault(); if (token != null) { - CurrentSystem = await _data.GetSystemByToken(token); + CurrentSystem = await _db.Execute(c => c.QueryFirstOrDefaultAsync("select * from systems where token = @token", new { token })); } await next.Invoke(context);