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:
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user