Skip to content

Commit 44eb2c4

Browse files
committed
chore: scaffolded required query parameter service
1 parent 0180c5d commit 44eb2c4

16 files changed

+91
-51
lines changed

src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public static void AddJsonApiInternals(
204204
services.AddScoped<ISparseFieldsService, SparseFieldsService>();
205205
services.AddScoped<ITargetedFields, TargetedFields>();
206206
services.AddScoped<IFieldsExplorer, FieldsExplorer>();
207-
services.AddScoped<IAttributeBehaviourService, AttributeBehaviourService>();
207+
services.AddScoped<IAttributeBehaviourService, OmitNullService>();
208208
services.AddScoped<IFieldsToSerialize, FieldsToSerialize>();
209209

210210
AddServerSerialization(services);
@@ -248,8 +248,8 @@ public static void AddClientSerialization(this IServiceCollection services)
248248

249249
services.AddScoped<IRequestSerializer>(sp =>
250250
{
251-
var resourceObjectBuilder = new ResourceObjectBuilder(sp.GetService<IResourceGraph>(), sp.GetService<IContextEntityProvider>(), sp.GetService<IResourceObjectBuilderSettingsProvider>().Get());
252-
return new RequestSerializer(sp.GetService<IFieldsExplorer>(), sp.GetService<IResourceGraph>(), resourceObjectBuilder);
251+
var resourceObjectBuilder = new ResourceObjectBuilder(sp.GetService<IResourceGraph>(), sp.GetService<IContextEntityProvider>(), sp.GetService<IResourceObjectBuilderSettingsProvider>().Get());
252+
return new RequestSerializer(sp.GetService<IFieldsExplorer>(), sp.GetService<IResourceGraph>(), resourceObjectBuilder);
253253
});
254254

255255
}

src/JsonApiDotNetCore/JsonApiDotNetCore.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@
4646
</ItemGroup>
4747
<ItemGroup>
4848
<Folder Include="Models\JsonApiDocuments\" />
49-
<Folder Include="Query\" />
49+
<Folder Include="QueryParameters\" />
5050
<Folder Include="Internal\Exceptions\" />
5151
<Folder Include="Models\Annotation\" />
5252
<Folder Include="Serialization\Common\" />
5353
<Folder Include="Serialization\Client\" />
5454
<Folder Include="Serialization\Server\" />
5555
<Folder Include="Serialization\Server\Builders\" />
56-
<Folder Include="Query\Contracts\" />
57-
<Folder Include="Query\Common\" />
56+
<Folder Include="QueryParameters\Contracts\" />
57+
<Folder Include="QueryParameters\Common\" />
5858
<Folder Include="Serialization\Server\Contracts\" />
5959
</ItemGroup>
6060
</Project>

src/JsonApiDotNetCore/Query/AttributeBehaviourService.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace JsonApiDotNetCore.Query
4+
{
5+
public abstract class QueryParameterService : IQueryParameterService
6+
{
7+
8+
/// <summary>
9+
/// By default, the name is derived from the implementing type.
10+
/// </summary>
11+
/// <example>
12+
/// The following query param service will match the query displayed in URL
13+
/// `?include=some-relationship`
14+
/// <code>public class IncludeService : QueryParameterService { /* ... */ } </code>
15+
/// </example>
16+
public virtual string Name { get { return GetParameterNameFromType(); } }
17+
18+
/// <inheritdoc/>
19+
public abstract void Parse(string value);
20+
21+
/// <summary>
22+
/// Gets the query parameter name from the implementing class name. Trims "Service"
23+
/// from the name if present.
24+
/// </summary>
25+
private string GetParameterNameFromType() => new Regex("Service$").Replace(GetType().Name, string.Empty);
26+
}
27+
}

src/JsonApiDotNetCore/Query/Contracts/ISparseFieldsService.cs renamed to src/JsonApiDotNetCore/QueryParameters/Contracts/ISparseFieldsService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ public interface ISparseFieldsService
1515
/// <param name="relationship"></param>
1616
/// <returns></returns>
1717
List<AttrAttribute> Get(RelationshipAttribute relationship = null);
18-
void Register(AttrAttribute selected, RelationshipAttribute relationship = null);
1918
}
2019
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace JsonApiDotNetCore.Query
4+
{
5+
public class FilterService : QueryParameterService
6+
{
7+
public override void Parse(string value)
8+
{
9+
throw new NotImplementedException();
10+
}
11+
}
12+
}

src/JsonApiDotNetCore/Query/IncludeService.cs renamed to src/JsonApiDotNetCore/QueryParameters/IncludeService.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using System.Text.RegularExpressions;
43
using JsonApiDotNetCore.Internal;
54
using JsonApiDotNetCore.Internal.Contracts;
65
using JsonApiDotNetCore.Internal.Query;
@@ -10,29 +9,6 @@
109
namespace JsonApiDotNetCore.Query
1110
{
1211

13-
public abstract class QueryParameterService : IQueryParameterService
14-
{
15-
16-
/// <summary>
17-
/// By default, the name is derived from the implementing type.
18-
/// </summary>
19-
/// <example>
20-
/// The following query param service will match the query displayed in URL
21-
/// `?include=some-relationship`
22-
/// <code>public class IncludeService : QueryParameterService { /* ... */ } </code>
23-
/// </example>
24-
public virtual string Name { get { return GetParameterNameFromType(); } }
25-
26-
/// <inheritdoc/>
27-
public abstract void Parse(string value);
28-
29-
/// <summary>
30-
/// Gets the query parameter name from the implementing class name. Trims "Service"
31-
/// from the name if present.
32-
/// </summary>
33-
private string GetParameterNameFromType() => new Regex("Service$").Replace(GetType().Name, string.Empty);
34-
}
35-
3612
public class IncludeService : QueryParameterService, IIncludeService
3713
{
3814
/// todo: make readonly
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace JsonApiDotNetCore.Query
4+
{
5+
public class OmitDefaultService : QueryParameterService
6+
{
7+
public override void Parse(string value)
8+
{
9+
throw new NotImplementedException();
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace JsonApiDotNetCore.Query
4+
{
5+
public class OmitNullService : QueryParameterService
6+
{
7+
public override void Parse(string value)
8+
{
9+
throw new NotImplementedException();
10+
}
11+
}
12+
}

src/JsonApiDotNetCore/Query/PageService.cs renamed to src/JsonApiDotNetCore/QueryParameters/PageService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace JsonApiDotNetCore.Query
66

77
{
8-
public class PageService : IPageQueryService
8+
public class PageService : QueryParameterService, IPageQueryService
99
{
1010
private IJsonApiOptions _options;
1111

@@ -25,6 +25,12 @@ public PageService(IJsonApiOptions options)
2525
public int CurrentPage { get; set; }
2626
/// <inheritdoc/>
2727
public int TotalPages => (TotalRecords == null) ? -1 : (int)Math.Ceiling(decimal.Divide(TotalRecords.Value, PageSize));
28+
29+
public override void Parse(string value)
30+
{
31+
throw new NotImplementedException();
32+
}
33+
2834
/// <inheritdoc/>
2935
public bool ShouldPaginate()
3036
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace JsonApiDotNetCore.Query
4+
{
5+
public class SortService: QueryParameterService
6+
{
7+
public override void Parse(string value)
8+
{
9+
throw new NotImplementedException();
10+
}
11+
}
12+
}

src/JsonApiDotNetCore/Query/SparseFieldsService.cs renamed to src/JsonApiDotNetCore/QueryParameters/SparseFieldsService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace JsonApiDotNetCore.Query
55

66
{
77
/// <inheritdoc/>
8-
public class SparseFieldsService : ISparseFieldsService
8+
public class SparseFieldsService : QueryParameterService, ISparseFieldsService
99
{
1010
/// <summary>
1111
/// The selected fields for the primary resource of this request.
@@ -33,7 +33,8 @@ public List<AttrAttribute> Get(RelationshipAttribute relationship = null)
3333
}
3434

3535
/// <inheritdoc/>
36-
public void Register(AttrAttribute selected, RelationshipAttribute relationship = null)
36+
//public override Parse(AttrAttribute selected, RelationshipAttribute relationship = null)
37+
public override void Parse(string value)
3738
{
3839
if (relationship == null)
3940
{

0 commit comments

Comments
 (0)