1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00

Added "since" revision date parameter to folder and site "get all" APIs.

This commit is contained in:
Kyle Spearrin 2016-05-04 22:39:23 -04:00
parent 8d57b21f97
commit 9c61cfb5c0
9 changed files with 80 additions and 5 deletions

View File

@ -8,6 +8,7 @@ using System.Security.Claims;
using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Authorization;
using Bit.Api.Models; using Bit.Api.Models;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using Bit.Core.Domains;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -36,9 +37,18 @@ namespace Bit.Api.Controllers
} }
[HttpGet("")] [HttpGet("")]
public async Task<ListResponseModel<FolderResponseModel>> Get() public async Task<ListResponseModel<FolderResponseModel>> Get(DateTime? since = null)
{ {
var folders = await _folderRepository.GetManyByUserIdAsync(User.GetUserId()); ICollection<Folder> folders = null;
if(since.HasValue)
{
folders = await _folderRepository.GetManyByRevisionDateAsync(User.GetUserId(), since.Value);
}
else
{
folders = await _folderRepository.GetManyByUserIdAsync(User.GetUserId());
}
return new ListResponseModel<FolderResponseModel>(folders.Select(f => new FolderResponseModel(f))); return new ListResponseModel<FolderResponseModel>(folders.Select(f => new FolderResponseModel(f)));
} }

View File

@ -42,9 +42,17 @@ namespace Bit.Api.Controllers
} }
[HttpGet("")] [HttpGet("")]
public async Task<ListResponseModel<SiteResponseModel>> Get(string[] expand = null) public async Task<ListResponseModel<SiteResponseModel>> Get(DateTime? since = null, string[] expand = null)
{ {
var sites = await _siteRepository.GetManyByUserIdAsync(User.GetUserId()); ICollection<Site> sites = null;
if(since.HasValue)
{
sites = await _siteRepository.GetManyByRevisionDateAsync(User.GetUserId(), since.Value);
}
else
{
sites = await _siteRepository.GetManyByUserIdAsync(User.GetUserId());
}
var responses = sites.Select(s => new SiteResponseModel(s)).ToList(); var responses = sites.Select(s => new SiteResponseModel(s)).ToList();
await ExpandManyAsync(sites, responses, expand, null); await ExpandManyAsync(sites, responses, expand, null);

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Core.Domains; using Bit.Core.Domains;
@ -8,5 +9,6 @@ namespace Bit.Core.Repositories
{ {
Task<Folder> GetByIdAsync(string id, string userId); Task<Folder> GetByIdAsync(string id, string userId);
Task<ICollection<Folder>> GetManyByUserIdAsync(string userId); Task<ICollection<Folder>> GetManyByUserIdAsync(string userId);
Task<ICollection<Folder>> GetManyByRevisionDateAsync(string userId, DateTime sinceRevisionDate);
} }
} }

View File

@ -9,5 +9,6 @@ namespace Bit.Core.Repositories
{ {
Task<Site> GetByIdAsync(string id, string userId); Task<Site> GetByIdAsync(string id, string userId);
Task<ICollection<Site>> GetManyByUserIdAsync(string userId); Task<ICollection<Site>> GetManyByUserIdAsync(string userId);
Task<ICollection<Site>> GetManyByRevisionDateAsync(string userId, DateTime sinceRevisionDate);
} }
} }

View File

@ -39,5 +39,18 @@ namespace Bit.Core.Repositories.SqlServer
return results.Select(f => f.ToDomain()).ToList(); return results.Select(f => f.ToDomain()).ToList();
} }
} }
public async Task<ICollection<Folder>> GetManyByRevisionDateAsync(string userId, DateTime sinceRevisionDate)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<FolderTableModel>(
$"[{Schema}].[{Table}_ReadByRevisionDate]",
new { UserId = new Guid(userId), SinceRevisionDate = sinceRevisionDate },
commandType: CommandType.StoredProcedure);
return results.Select(f => f.ToDomain()).ToList();
}
}
} }
} }

View File

@ -39,5 +39,18 @@ namespace Bit.Core.Repositories.SqlServer
return results.Select(s => s.ToDomain()).ToList(); return results.Select(s => s.ToDomain()).ToList();
} }
} }
public async Task<ICollection<Site>> GetManyByRevisionDateAsync(string userId, DateTime sinceRevisionDate)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<SiteTableModel>(
$"[{Schema}].[{Table}_ReadByRevisionDate]",
new { UserId = new Guid(userId), SinceRevisionDate = sinceRevisionDate },
commandType: CommandType.StoredProcedure);
return results.Select(f => f.ToDomain()).ToList();
}
}
} }
} }

View File

@ -88,5 +88,7 @@
<Build Include="dbo\Stored Procedures\Folder_Update.sql" /> <Build Include="dbo\Stored Procedures\Folder_Update.sql" />
<Build Include="dbo\Stored Procedures\Cipher_ReadByUserId.sql" /> <Build Include="dbo\Stored Procedures\Cipher_ReadByUserId.sql" />
<Build Include="dbo\Stored Procedures\User_UpdateEmailPassword.sql" /> <Build Include="dbo\Stored Procedures\User_UpdateEmailPassword.sql" />
<Build Include="dbo\Stored Procedures\Folder_ReadByRevisionDate.sql" />
<Build Include="dbo\Stored Procedures\Site_ReadByRevisionDate.sql" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,13 @@
CREATE PROCEDURE [dbo].[Folder_ReadByRevisionDate]
@UserId UNIQUEIDENTIFIER,
@SinceRevisionDate DATETIME
AS
BEGIN
SELECT
*
FROM
[dbo].[FolderView]
WHERE
[UserId] = @UserId
AND [RevisionDate] >= @SinceRevisionDate
END

View File

@ -0,0 +1,13 @@
CREATE PROCEDURE [dbo].[Site_ReadByRevisionDate]
@UserId UNIQUEIDENTIFIER,
@SinceRevisionDate DATETIME
AS
BEGIN
SELECT
*
FROM
[dbo].[SiteView]
WHERE
[UserId] = @UserId
AND [RevisionDate] >= @SinceRevisionDate
END