Files
Wino-Mail/Wino.Core/Services/TokenService.cs
Burak Kaan Köse d1d6f12f05 Ground work for Wino Calendar. (#475)
Wino Calendar abstractions.
2024-11-10 23:28:25 +01:00

32 lines
1.1 KiB
C#

using System;
using System.Threading.Tasks;
using Wino.Core.Domain.Entities.Shared;
namespace Wino.Core.Services
{
public interface ITokenService
{
Task<TokenInformation> GetTokenInformationAsync(Guid accountId);
Task SaveTokenInformationAsync(Guid accountId, TokenInformation tokenInformation);
}
public class TokenService : BaseDatabaseService, ITokenService
{
public TokenService(IDatabaseService databaseService) : base(databaseService) { }
public Task<TokenInformation> GetTokenInformationAsync(Guid accountId)
=> Connection.Table<TokenInformation>().FirstOrDefaultAsync(a => a.AccountId == accountId);
public async Task SaveTokenInformationAsync(Guid accountId, TokenInformation tokenInformation)
{
// Delete all tokens for this account.
await Connection.Table<TokenInformation>().DeleteAsync(a => a.AccountId == accountId);
// Save new token info to the account.
tokenInformation.AccountId = accountId;
await Connection.InsertOrReplaceAsync(tokenInformation);
}
}
}