-
-
Notifications
You must be signed in to change notification settings - Fork 507
Expand file tree
/
Copy pathSavedViewRepository.cs
More file actions
60 lines (48 loc) · 2.59 KB
/
SavedViewRepository.cs
File metadata and controls
60 lines (48 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Exceptionless.Core.Models;
using Exceptionless.Core.Repositories.Configuration;
using Foundatio.Repositories;
using Foundatio.Repositories.Models;
using Nest;
namespace Exceptionless.Core.Repositories;
public class SavedViewRepository : RepositoryOwnedByOrganization<SavedView>, ISavedViewRepository
{
public SavedViewRepository(ExceptionlessElasticConfiguration configuration, AppOptions options)
: base(configuration.SavedViews, null!, options)
{
}
public Task<FindResults<SavedView>> GetByViewAsync(string organizationId, string view, CommandOptionsDescriptor<SavedView>? options = null)
{
var filter = Query<SavedView>.Term(e => e.OrganizationId, organizationId)
&& Query<SavedView>.Term(e => e.View, view);
return FindAsync(q => q.ElasticFilter(filter).SortAscending(e => e.Name.Suffix("keyword")), options);
}
public Task<FindResults<SavedView>> GetByViewForUserAsync(string organizationId, string view, string userId, CommandOptionsDescriptor<SavedView>? options = null)
{
var filter = Query<SavedView>.Term(e => e.OrganizationId, organizationId)
&& Query<SavedView>.Term(e => e.View, view)
&& (!Query<SavedView>.Exists(e => e.Field(f => f.UserId))
|| Query<SavedView>.Term(e => e.UserId, userId));
return FindAsync(q => q.ElasticFilter(filter).SortAscending(e => e.Name.Suffix("keyword")), options);
}
public Task<FindResults<SavedView>> GetByOrganizationForUserAsync(string organizationId, string userId, CommandOptionsDescriptor<SavedView>? options = null)
{
var filter = Query<SavedView>.Term(e => e.OrganizationId, organizationId)
&& (!Query<SavedView>.Exists(e => e.Field(f => f.UserId))
|| Query<SavedView>.Term(e => e.UserId, userId));
return FindAsync(q => q.ElasticFilter(filter).SortAscending(e => e.Name.Suffix("keyword")), options);
}
public async Task<long> RemovePrivateByUserIdAsync(string organizationId, string userId)
{
var filter = Query<SavedView>.Term(e => e.OrganizationId, organizationId)
&& Query<SavedView>.Term(e => e.UserId, userId);
var results = await FindAsync(q => q.ElasticFilter(filter), o => o.PageLimit(1000));
if (results.Total == 0)
return 0;
await RemoveAsync(results.Documents);
return results.Total;
}
public async Task<long> CountByOrganizationIdAsync(string organizationId)
{
return await CountAsync(q => q.Organization(organizationId));
}
}