Newsbot.Collector/Newsbot.Collector.Database/Repositories/RefreshTokenTable.cs
James Tombleson 4cacc03fb8
Some checks failed
continuous-integration/drone/pr Build is failing
Getting things setup to support token refresh
2023-07-10 22:41:39 -07:00

42 lines
1013 B
C#

using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
namespace Newsbot.Collector.Database.Repositories;
public class RefreshTokenTable : IRefreshTokenRepository
{
private readonly DatabaseContext _context;
public RefreshTokenTable(string connectionString)
{
_context = new DatabaseContext(connectionString);
}
public RefreshTokenTable(DatabaseContext context)
{
_context = context;
}
public void Add(RefreshTokenEntity entity)
{
_context.RefreshTokens.Add(entity);
_context.SaveChanges();
}
public RefreshTokenEntity? Get(string token)
{
return _context.RefreshTokens.SingleOrDefault(x => x.Token == token);
}
public void UpdateTokenIsUsed(string token)
{
var entity = Get(token);
if (entity is null)
{
return;
}
entity.Used = true;
_context.RefreshTokens.Update(entity);
_context.SaveChanges();
}
}