mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-03-27 14:51:44 +01:00
Co-authored-by: Kieran <kieran@harkin.me> Reviewed-on: https://git.v0l.io/Kieran/void.cat/pulls/65
49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using VoidCat.Database;
|
|
using VoidCat.Services.Abstractions;
|
|
|
|
namespace VoidCat.Services.Users;
|
|
|
|
/// <inheritdoc />
|
|
public class PostgresApiKeyStore : IApiKeyStore
|
|
{
|
|
private readonly VoidContext _db;
|
|
|
|
public PostgresApiKeyStore(VoidContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async ValueTask<ApiKey?> Get(Guid id)
|
|
{
|
|
return await _db.ApiKeys
|
|
.AsNoTracking()
|
|
.SingleOrDefaultAsync(a => a.Id == id);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async ValueTask Add(Guid id, ApiKey obj)
|
|
{
|
|
_db.ApiKeys.Add(obj);
|
|
await _db.SaveChangesAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async ValueTask Delete(Guid id)
|
|
{
|
|
await _db.ApiKeys
|
|
.Where(a => a.Id == id)
|
|
.ExecuteDeleteAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async ValueTask<IReadOnlyList<ApiKey>> ListKeys(Guid id)
|
|
{
|
|
return await _db.ApiKeys
|
|
.AsNoTracking()
|
|
.Where(a => a.UserId == id)
|
|
.ToArrayAsync();
|
|
}
|
|
}
|