mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 16:42:50 -05:00
stub out API for events
This commit is contained in:
38
src/Core/Models/Api/Response/EventResponseModel.cs
Normal file
38
src/Core/Models/Api/Response/EventResponseModel.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class EventResponseModel : ResponseModel
|
||||
{
|
||||
public EventResponseModel(IEvent ev)
|
||||
: base("event")
|
||||
{
|
||||
if(ev == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(ev));
|
||||
}
|
||||
|
||||
Type = ev.Type;
|
||||
UserId = ev.UserId;
|
||||
OrganizationId = ev.OrganizationId;
|
||||
CipherId = ev.CipherId;
|
||||
CollectionId = ev.CollectionId;
|
||||
GroupId = ev.GroupId;
|
||||
OrganizationUserId = ev.OrganizationUserId;
|
||||
ActingUserId = ev.ActingUserId;
|
||||
Date = ev.Date;
|
||||
}
|
||||
|
||||
public EventType Type { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
public Guid? OrganizationId { get; set; }
|
||||
public Guid? CipherId { get; set; }
|
||||
public Guid? CollectionId { get; set; }
|
||||
public Guid? GroupId { get; set; }
|
||||
public Guid? OrganizationUserId { get; set; }
|
||||
public Guid? ActingUserId { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ namespace Bit.Core.Repositories
|
||||
public interface IEventRepository
|
||||
{
|
||||
Task<ICollection<IEvent>> GetManyByUserAsync(Guid userId, DateTime startDate, DateTime endDate);
|
||||
Task<ICollection<IEvent>> GetManyByOrganizationAsync(Guid organizationId, DateTime startDate, DateTime endDate);
|
||||
Task CreateAsync(IEvent e);
|
||||
Task CreateManyAsync(IList<IEvent> e);
|
||||
}
|
||||
|
@ -25,6 +25,11 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ICollection<IEvent>> GetManyByOrganizationAsync(Guid organizationId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task CreateAsync(IEvent e)
|
||||
{
|
||||
if(!(e is Event ev))
|
||||
|
@ -24,8 +24,7 @@ namespace Bit.Core.Repositories.TableStorage
|
||||
_table = tableClient.GetTableReference("event");
|
||||
}
|
||||
|
||||
public async Task<ICollection<IEvent>> GetManyByUserAsync(Guid userId,
|
||||
DateTime startDate, DateTime endDate)
|
||||
public async Task<ICollection<IEvent>> GetManyByUserAsync(Guid userId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var start = CoreHelpers.DateTimeToTableStorageKey(startDate);
|
||||
var end = CoreHelpers.DateTimeToTableStorageKey(endDate);
|
||||
@ -48,7 +47,38 @@ namespace Bit.Core.Repositories.TableStorage
|
||||
var queryResults = await _table.ExecuteQuerySegmentedAsync(query, continuationToken);
|
||||
continuationToken = queryResults.ContinuationToken;
|
||||
results.AddRange(queryResults.Results);
|
||||
} while(continuationToken != null);
|
||||
}
|
||||
while(continuationToken != null);
|
||||
|
||||
return results.Select(r => r as IEvent).ToList();
|
||||
}
|
||||
|
||||
public async Task<ICollection<IEvent>> GetManyByOrganizationAsync(Guid organizationId,
|
||||
DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var start = CoreHelpers.DateTimeToTableStorageKey(startDate);
|
||||
var end = CoreHelpers.DateTimeToTableStorageKey(endDate);
|
||||
|
||||
var rowFilter = TableQuery.CombineFilters(
|
||||
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, $"{start}_"),
|
||||
TableOperators.And,
|
||||
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, $"{end}`"));
|
||||
|
||||
var filter = TableQuery.CombineFilters(
|
||||
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, $"OrganizationId={organizationId}"),
|
||||
TableOperators.And,
|
||||
rowFilter);
|
||||
|
||||
var query = new TableQuery<EventTableEntity>().Where(filter);
|
||||
var results = new List<EventTableEntity>();
|
||||
TableContinuationToken continuationToken = null;
|
||||
do
|
||||
{
|
||||
var queryResults = await _table.ExecuteQuerySegmentedAsync(query, continuationToken);
|
||||
continuationToken = queryResults.ContinuationToken;
|
||||
results.AddRange(queryResults.Results);
|
||||
}
|
||||
while(continuationToken != null);
|
||||
|
||||
return results.Select(r => r as IEvent).ToList();
|
||||
}
|
||||
|
Reference in New Issue
Block a user