mirror of
https://github.com/bitwarden/mobile
synced 2025-12-27 13:43:32 +00:00
add collection syncing
This commit is contained in:
15
src/App/Repositories/BaseRepository.cs
Normal file
15
src/App/Repositories/BaseRepository.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Bit.App.Abstractions;
|
||||
using SQLite;
|
||||
|
||||
namespace Bit.App.Repositories
|
||||
{
|
||||
public abstract class BaseRepository
|
||||
{
|
||||
public BaseRepository(ISqlService sqlService)
|
||||
{
|
||||
Connection = sqlService.GetConnection();
|
||||
}
|
||||
|
||||
protected SQLiteConnection Connection { get; private set; }
|
||||
}
|
||||
}
|
||||
40
src/App/Repositories/CipherCollectionRepository.cs
Normal file
40
src/App/Repositories/CipherCollectionRepository.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Threading.Tasks;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Models.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.App.Repositories
|
||||
{
|
||||
public class CipherCollectionRepository : BaseRepository, ICipherCollectionRepository
|
||||
{
|
||||
public CipherCollectionRepository(ISqlService sqlService)
|
||||
: base(sqlService)
|
||||
{ }
|
||||
|
||||
public Task<IEnumerable<CipherCollectionData>> GetAllByUserIdAsync(string userId)
|
||||
{
|
||||
var cipherCollections = Connection.Table<CipherCollectionData>().Where(f => f.UserId == userId)
|
||||
.Cast<CipherCollectionData>();
|
||||
return Task.FromResult(cipherCollections);
|
||||
}
|
||||
|
||||
public virtual Task InsertAsync(CipherCollectionData obj)
|
||||
{
|
||||
Connection.Insert(obj);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public virtual Task DeleteAsync(CipherCollectionData obj)
|
||||
{
|
||||
Connection.Delete<CipherCollectionData>(obj.Id);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public virtual Task DeleteByUserIdAsync(string userId)
|
||||
{
|
||||
Connection.Execute("DELETE FROM CipherCollection WHERE UserId = ?", userId);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/App/Repositories/CollectionRepository.cs
Normal file
21
src/App/Repositories/CollectionRepository.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Models.Data;
|
||||
|
||||
namespace Bit.App.Repositories
|
||||
{
|
||||
public class CollectionRepository : Repository<CollectionData, string>, ICollectionRepository
|
||||
{
|
||||
public CollectionRepository(ISqlService sqlService)
|
||||
: base(sqlService)
|
||||
{ }
|
||||
|
||||
public Task<IEnumerable<CollectionData>> GetAllByUserIdAsync(string userId)
|
||||
{
|
||||
var folders = Connection.Table<CollectionData>().Where(f => f.UserId == userId).Cast<CollectionData>();
|
||||
return Task.FromResult(folders);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,16 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.App.Abstractions;
|
||||
using SQLite;
|
||||
|
||||
namespace Bit.App.Repositories
|
||||
{
|
||||
public abstract class Repository<T, TId> : IRepository<T, TId>
|
||||
public abstract class Repository<T, TId> : BaseRepository, IRepository<T, TId>
|
||||
where TId : IEquatable<TId>
|
||||
where T : class, IDataObject<TId>, new()
|
||||
{
|
||||
public Repository(ISqlService sqlService)
|
||||
{
|
||||
Connection = sqlService.GetConnection();
|
||||
}
|
||||
|
||||
protected SQLiteConnection Connection { get; private set; }
|
||||
: base(sqlService)
|
||||
{ }
|
||||
|
||||
public virtual Task<T> GetByIdAsync(TId id)
|
||||
{
|
||||
@@ -39,6 +35,7 @@ namespace Bit.App.Repositories
|
||||
Connection.Update(obj);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public virtual Task UpsertAsync(T obj)
|
||||
{
|
||||
Connection.InsertOrReplace(obj);
|
||||
|
||||
Reference in New Issue
Block a user