excise entity framework from all remaining code

This commit is contained in:
sam 2024-10-28 14:04:55 +01:00
parent d6c3133d52
commit ff92c5f335
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
62 changed files with 402 additions and 1339 deletions

View file

@ -14,14 +14,14 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
using System.Net;
using Catalogger.Backend.Database;
using Catalogger.Backend.Database.Models;
using Microsoft.EntityFrameworkCore;
using Catalogger.Backend.Database.Repositories;
using NodaTime;
namespace Catalogger.Backend.Api.Middleware;
public class AuthenticationMiddleware(DatabaseContext db, IClock clock) : IMiddleware
public class AuthenticationMiddleware(ApiTokenRepository tokenRepository, IClock clock)
: IMiddleware
{
public async Task InvokeAsync(HttpContext ctx, RequestDelegate next)
{
@ -37,9 +37,7 @@ public class AuthenticationMiddleware(DatabaseContext db, IClock clock) : IMiddl
var token = ctx.Request.Headers.Authorization.ToString();
var apiToken = await db.ApiTokens.FirstOrDefaultAsync(t =>
t.DashboardToken == token && t.ExpiresAt > clock.GetCurrentInstant()
);
var apiToken = await tokenRepository.GetAsync(token);
if (apiToken == null)
{
if (requireAuth)