set up user settings data table and access repository

This commit is contained in:
Kyle Spearrin 2017-02-08 20:39:37 -05:00
parent 230722945e
commit 3ad1e8a3ba
10 changed files with 69 additions and 0 deletions

View file

@ -220,6 +220,7 @@ namespace Bit.Android
.RegisterType<IDeviceApiRepository, DeviceApiRepository>(new ContainerControlledLifetimeManager())
.RegisterType<IAccountsApiRepository, AccountsApiRepository>(new ContainerControlledLifetimeManager())
.RegisterType<ICipherApiRepository, CipherApiRepository>(new ContainerControlledLifetimeManager())
.RegisterType<ISettingsRepository, SettingsRepository>(new ContainerControlledLifetimeManager())
// Other
.RegisterInstance(CrossSettings.Current, new ContainerControlledLifetimeManager())
.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())

View file

@ -12,6 +12,7 @@ namespace Bit.App.Abstractions
Task<IEnumerable<T>> GetAllAsync();
Task UpdateAsync(T obj);
Task InsertAsync(T obj);
Task UpsertAsync(T obj);
Task DeleteAsync(TId id);
Task DeleteAsync(T obj);
}

View file

@ -0,0 +1,10 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Bit.App.Abstractions
{
public interface ISettingsRepository
{
Task<IEnumerable<IEnumerable<string>>> GetEquivablentDomains(string userId);
}
}

View file

@ -37,6 +37,7 @@
<ItemGroup>
<Compile Include="Abstractions\Repositories\IAccountsApiRepository.cs" />
<Compile Include="Abstractions\Repositories\IDeviceApiRepository.cs" />
<Compile Include="Abstractions\Repositories\ISettingsRepository.cs" />
<Compile Include="Abstractions\Services\ITokenService.cs" />
<Compile Include="Abstractions\Services\IHttpService.cs" />
<Compile Include="Abstractions\Services\IDeviceInfoService.cs" />
@ -101,6 +102,7 @@
<Compile Include="Models\Api\LoginDataModel.cs" />
<Compile Include="Models\Cipher.cs" />
<Compile Include="Models\CipherString.cs" />
<Compile Include="Models\Data\SettingsData.cs" />
<Compile Include="Models\Data\FolderData.cs" />
<Compile Include="Abstractions\IDataObject.cs" />
<Compile Include="Models\Data\LoginData.cs" />
@ -149,6 +151,7 @@
<Compile Include="Repositories\DeviceApiRepository.cs" />
<Compile Include="Repositories\CipherApiRepository.cs" />
<Compile Include="Abstractions\Repositories\ICipherApiRepository.cs" />
<Compile Include="Repositories\SettingsRepository.cs" />
<Compile Include="Repositories\LoginApiRepository.cs" />
<Compile Include="Repositories\FolderApiRepository.cs" />
<Compile Include="Repositories\LoginRepository.cs" />

View file

@ -0,0 +1,16 @@
using SQLite;
using Bit.App.Abstractions;
namespace Bit.App.Models.Data
{
[Table("Settings")]
public class SettingsData : IDataObject<string>
{
public SettingsData()
{ }
[PrimaryKey]
public string Id { get; set; }
public string EquivalentDomains { get; set; }
}
}

View file

@ -39,6 +39,11 @@ namespace Bit.App.Repositories
Connection.Update(obj);
return Task.FromResult(0);
}
public virtual Task UpsertAsync(T obj)
{
Connection.InsertOrReplace(obj);
return Task.FromResult(0);
}
public virtual async Task DeleteAsync(T obj)
{

View file

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Bit.App.Abstractions;
using Bit.App.Models.Data;
using Newtonsoft.Json;
namespace Bit.App.Repositories
{
public class SettingsRepository : Repository<SettingsData, string>, ISettingsRepository
{
public SettingsRepository(ISqlService sqlService)
: base(sqlService)
{ }
public Task<IEnumerable<IEnumerable<string>>> GetEquivablentDomains(string userId)
{
var equivalentDomainsJson = Connection.Table<SettingsData>().Where(f => f.Id == userId)
.Select(f => f.EquivalentDomains).FirstOrDefault();
if(string.IsNullOrWhiteSpace(equivalentDomainsJson))
{
return Task.FromResult<IEnumerable<IEnumerable<string>>>(null);
}
var equivalentDomains = JsonConvert.DeserializeObject<IEnumerable<IEnumerable<string>>>(equivalentDomainsJson);
return Task.FromResult(equivalentDomains);
}
}
}

View file

@ -18,6 +18,7 @@ namespace Bit.App.Services
{
_connection.CreateTable<FolderData>();
_connection.CreateTable<LoginData>();
_connection.CreateTable<SettingsData>();
}
}
}

View file

@ -287,6 +287,7 @@ namespace Bit.iOS.Extension
.RegisterType<ILoginRepository, LoginRepository>(new ContainerControlledLifetimeManager())
.RegisterType<ILoginApiRepository, LoginApiRepository>(new ContainerControlledLifetimeManager())
.RegisterType<IConnectApiRepository, ConnectApiRepository>(new ContainerControlledLifetimeManager())
.RegisterType<ISettingsRepository, SettingsRepository>(new ContainerControlledLifetimeManager())
// Other
.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());

View file

@ -276,6 +276,7 @@ namespace Bit.iOS
.RegisterType<IDeviceApiRepository, DeviceApiRepository>(new ContainerControlledLifetimeManager())
.RegisterType<IAccountsApiRepository, AccountsApiRepository>(new ContainerControlledLifetimeManager())
.RegisterType<ICipherApiRepository, CipherApiRepository>(new ContainerControlledLifetimeManager())
.RegisterType<ISettingsRepository, SettingsRepository>(new ContainerControlledLifetimeManager())
// Other
.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())