1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-16 23:27:30 -05:00

Folder APIs to new tables

This commit is contained in:
Kyle Spearrin
2017-03-18 11:35:41 -04:00
parent d7a1cd1ce3
commit 2b71420818
9 changed files with 84 additions and 76 deletions

View File

@ -1,9 +1,13 @@
using System;
using Bit.Core.Models.Table;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace Bit.Core.Repositories
{
public interface IFolderRepository : IRepository<Folder, Guid>
{
Task<Folder> GetByIdAsync(Guid id, Guid userId);
Task<ICollection<Folder>> GetManyByUserIdAsync(Guid userId);
}
}

View File

@ -1,5 +1,11 @@
using System;
using Bit.Core.Models.Table;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Dapper;
using System.Linq;
namespace Bit.Core.Repositories.SqlServer
{
@ -12,5 +18,29 @@ namespace Bit.Core.Repositories.SqlServer
public FolderRepository(string connectionString)
: base(connectionString)
{ }
public async Task<Folder> GetByIdAsync(Guid id, Guid userId)
{
var folder = await GetByIdAsync(id);
if(folder == null || folder.UserId != userId)
{
return null;
}
return folder;
}
public async Task<ICollection<Folder>> GetManyByUserIdAsync(Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<Folder>(
$"[{Schema}].[Folder_ReadByUserId]",
new { UserId = userId },
commandType: CommandType.StoredProcedure);
return results.ToList();
}
}
}
}