Skip to content

Commit 5169fac

Browse files
committed
chore: deprecate method
1 parent fc7a3be commit 5169fac

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

JsonApiDotnetCore.sln

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Global
190190
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x64.ActiveCfg = Release|Any CPU
191191
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x64.Build.0 = Release|Any CPU
192192
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x86.ActiveCfg = Release|Any CPU
193-
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x86.Build.0 = Release|Any CPU\
193+
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x86.Build.0 = Release|Any CPU
194194
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
195195
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
196196
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -203,6 +203,7 @@ Global
203203
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x64.Build.0 = Release|Any CPU
204204
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x86.ActiveCfg = Release|Any CPU
205205
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x86.Build.0 = Release|Any CPU
206+
{DF9BFD82-D937-4907-B0B4-64670417115F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
206207
EndGlobalSection
207208
GlobalSection(SolutionProperties) = preSolution
208209
HideSolutionNode = FALSE

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,18 @@ public DefaultEntityRepository(
7878
_resourceDefinition = resourceDefinition;
7979
}
8080

81+
82+
83+
public virtual IQueryable<TEntity> Get()
84+
{
85+
if (_jsonApiContext.QuerySet?.Fields != null && _jsonApiContext.QuerySet.Fields.Count > 0)
86+
return _dbSet.Select(_jsonApiContext.QuerySet?.Fields);
87+
88+
return _dbSet;
89+
}
90+
8191
/// <inheritdoc />
82-
public virtual IQueryable<TEntity> Get()
92+
public virtual IQueryable<TEntity> GetQueryable()
8393
=> _dbSet;
8494

8595
public virtual IQueryable<TEntity> Select(IQueryable<TEntity> entities, List<string> fields)
@@ -130,15 +140,15 @@ public virtual IQueryable<TEntity> Sort(IQueryable<TEntity> entities, List<SortQ
130140
/// <inheritdoc />
131141
public virtual async Task<TEntity> GetAsync(TId id)
132142
{
133-
return await Get().SingleOrDefaultAsync(e => e.Id.Equals(id));
143+
return await GetQueryable().SingleOrDefaultAsync(e => e.Id.Equals(id));
134144
}
135145

136146
/// <inheritdoc />
137147
public virtual async Task<TEntity> GetAndIncludeAsync(TId id, string relationshipName)
138148
{
139149
_logger?.LogDebug($"[JADN] GetAndIncludeAsync({id}, {relationshipName})");
140150

141-
var includedSet = Include(Get(), relationshipName);
151+
var includedSet = Include(GetQueryable(), relationshipName);
142152
var result = await includedSet.SingleOrDefaultAsync(e => e.Id.Equals(id));
143153

144154
return result;

src/JsonApiDotNetCore/Data/IEntityReadRepository.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
34
using System.Threading.Tasks;
@@ -18,6 +19,9 @@ public interface IEntityReadRepository<TEntity, in TId>
1819
/// The base GET query. This is a good place to apply rules that should affect all reads,
1920
/// such as authorization of resources.
2021
/// </summary>
22+
IQueryable<TEntity> GetQueryable();
23+
24+
[Obsolete("This method has been deprecated, use GetQueryable() instead")]
2125
IQueryable<TEntity> Get();
2226

2327
/// <summary>

src/JsonApiDotNetCore/Services/EntityResourceService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public virtual async Task<bool> DeleteAsync(TId id)
9898

9999
public virtual async Task<IEnumerable<TResource>> GetAsync()
100100
{
101-
var entities = _entities.Get();
101+
var entities = _entities.GetQueryable();
102102

103103
entities = ApplySortAndFilterQuery(entities);
104104

@@ -243,7 +243,7 @@ protected virtual IQueryable<TEntity> IncludeRelationships(IQueryable<TEntity> e
243243

244244
private async Task<TResource> GetWithRelationshipsAsync(TId id)
245245
{
246-
var query = _entities.Get().Where(e => e.Id.Equals(id));
246+
var query = _entities.GetQueryable().Where(e => e.Id.Equals(id));
247247

248248
_jsonApiContext.QuerySet.IncludedRelationships.ForEach(r =>
249249
{

test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using GettingStarted.Models;
32
using GettingStarted.ResourceDefinitionExample;
43
using JsonApiDotNetCore.Builders;
@@ -7,7 +6,6 @@
76
using JsonApiDotNetCore.Models;
87
using JsonApiDotNetCore.Services;
98
using Microsoft.Extensions.DependencyInjection;
10-
using Microsoft.Extensions.Logging;
119
using Moq;
1210
using Xunit;
1311

test/JsonApiDotNetCoreExampleTests/Helpers/Repositories/AuthorizedTodoItemsRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public AuthorizedTodoItemsRepository(
2323
_authService = authService;
2424
}
2525

26-
public override IQueryable<TodoItem> Get()
26+
public override IQueryable<TodoItem> GetQueryable()
2727
{
28-
return base.Get().Where(todoItem => todoItem.OwnerId == _authService.CurrentUserId);
28+
return base.GetQueryable().Where(todoItem => todoItem.OwnerId == _authService.CurrentUserId);
2929
}
3030
}
3131
}

0 commit comments

Comments
 (0)