Skip to content

Commit 2f3b618

Browse files
authored
Merge pull request #109 from Research-Institute/develop
v2.0.5
2 parents 5e442a5 + c1504f3 commit 2f3b618

16 files changed

+438
-16
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
before_script:
77
- psql -c 'create database JsonApiDotNetCoreExample;' -U postgres
88
mono: none
9-
dotnet: 1.0.1
9+
dotnet: 1.0.4 # https://www.microsoft.com/net/download/linux
1010
branches:
1111
only:
1212
- master

Build.ps1

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
22
$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)
33

4-
dotnet restore .\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj
4+
dotnet restore
5+
6+
dotnet test ./test/UnitTests/UnitTests.csproj
7+
dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj
8+
dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
9+
510
dotnet build .\src\JsonApiDotNetCore -c Release
611

712
echo "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"

JsonApiDotnetCore.sln

+15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoEntityFrameworkExample",
2222
EndProject
2323
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoEntityFrameworkTests", "test\NoEntityFrameworkTests\NoEntityFrameworkTests.csproj", "{73DA578D-A63F-4956-83ED-6D7102E09140}"
2424
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "test\UnitTests\UnitTests.csproj", "{6D4BD85A-A262-44C6-8572-FE3A30410BF3}"
26+
EndProject
2527
Global
2628
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2729
Debug|Any CPU = Debug|Any CPU
@@ -80,6 +82,18 @@ Global
8082
{73DA578D-A63F-4956-83ED-6D7102E09140}.Release|x64.Build.0 = Release|Any CPU
8183
{73DA578D-A63F-4956-83ED-6D7102E09140}.Release|x86.ActiveCfg = Release|Any CPU
8284
{73DA578D-A63F-4956-83ED-6D7102E09140}.Release|x86.Build.0 = Release|Any CPU
85+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
86+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
87+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x64.ActiveCfg = Debug|x64
88+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x64.Build.0 = Debug|x64
89+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x86.ActiveCfg = Debug|x86
90+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x86.Build.0 = Debug|x86
91+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
92+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|Any CPU.Build.0 = Release|Any CPU
93+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x64.ActiveCfg = Release|x64
94+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x64.Build.0 = Release|x64
95+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x86.ActiveCfg = Release|x86
96+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x86.Build.0 = Release|x86
8397
EndGlobalSection
8498
GlobalSection(SolutionProperties) = preSolution
8599
HideSolutionNode = FALSE
@@ -90,5 +104,6 @@ Global
90104
{0B959765-40D2-43B5-87EE-FE2FEF9DBED5} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
91105
{570165EC-62B5-4684-A139-8D2A30DD4475} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
92106
{73DA578D-A63F-4956-83ED-6D7102E09140} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
107+
{6D4BD85A-A262-44C6-8572-FE3A30410BF3} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
93108
EndGlobalSection
94109
EndGlobal

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@ A framework for building [json:api](http://jsonapi.org/) compliant web servers.
1010

1111
## Installation And Usage
1212

13-
See the documentation [here](https://research-institute.github.io/json-api-dotnet-core)
13+
See the documentation [here](https://research-institute.github.io/json-api-dotnet-core)
14+
15+
16+
## .Net Core v2 Notes
17+
18+
Branch `feat/core-2` is where I am working on .Net Core 2 compatibility tests and package upgrades.
19+
There are several blockers to be aware of:
20+
21+
- Microsoft.AspNetCore.* packages target the runtime (netcoreapp) instead of netstandard.
22+
This will be fixed in future versions.
23+
- EF bug against netcoreapp2.0 runtime ([EntityFramework#8021](https://github.com/aspnet/EntityFramework/issues/8021))
24+
- Can't run acceptance testing against postgres on preview runtime [pgsql.EntityFrameworkCore.PostgreSQL#171](https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/171#issuecomment-301287257)

appveyor.yml

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
version: '{build}'
22
os: Visual Studio 2017
3+
4+
environment:
5+
POSTGRES_PORT: tcp://localhost:5432
6+
POSTGRES_ENV_POSTGRES_USER: postgres
7+
POSTGRES_ENV_POSTGRES_PASSWORD: Password12!
8+
POSTGRES_ENV_POSTGRES_DB: JsonApiDotNetCoreExample
9+
PGUSER: postgres
10+
PGPASSWORD: Password12!
11+
Data:DefaultConnection: "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=Password12!"
12+
313
pull_requests:
414
do_not_increment_build_number: true
15+
516
branches:
617
only:
718
- master
819
- develop
20+
- unstable
21+
922
nuget:
1023
disable_publish_on_pr: true
24+
25+
init:
26+
- SET PATH=C:\Program Files\PostgreSQL\9.6\bin\;%PATH%
27+
28+
services:
29+
- postgresql
30+
1131
build_script:
32+
- ps: createdb JsonApiDotNetCoreExample
1233
- ps: dotnet --version
1334
- ps: .\Build.ps1
35+
1436
test: off
37+
1538
artifacts:
1639
- path: .\**\artifacts\**\*.nupkg
1740
name: NuGet
@@ -23,10 +46,17 @@ deploy:
2346
skip_symbols: true
2447
on:
2548
branch: develop
49+
- provider: NuGet
50+
server: https://www.myget.org/F/jadnc/api/v2/package
51+
api_key:
52+
secure: 6CeYcZ4Ze+57gxfeuHzqP6ldbUkPtF6pfpVM1Gw/K2jExFrAz763gNAQ++tiacq3
53+
skip_symbols: true
54+
on:
55+
branch: unstable
2656
- provider: NuGet
2757
name: production
2858
api_key:
2959
secure: /fsEOgG4EdtNd6DPmko9h3NxQwx1IGDcFreGTKd2KA56U2KEkpX/L/pCGpCIEf2s
3060
on:
3161
branch: master
32-
appveyor_repo_tag: true
62+
appveyor_repo_tag: true

build.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
#exit if any command fails
44
set -e
55

6-
dotnet restore ./src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
7-
dotnet restore ./src/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj
8-
dotnet restore ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj
9-
dotnet restore ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
6+
dotnet restore
107

8+
dotnet test ./test/UnitTests/UnitTests.csproj
119
dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj
1210
dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj

docs/Errors.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ public void MyMethod() {
2828
public override async Task<IActionResult> PostAsync([FromBody] MyEntity entity)
2929
{
3030
if(_db.IsFull)
31-
return new ObjectResult(new CustomError("507", "Database is full.", "Theres no more room.", "Sorry."));
31+
return Error(new CustomError("507", "Database is full.", "Theres no more room.", "Sorry."));
3232

33+
if(model.Validations.IsValid == false)
34+
return Errors(model.Validations.Select(v => v.GetErrors()));
35+
3336
// ...
3437
}
3538
```

src/JsonApiDotNetCore/Controllers/JsonApiController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public virtual async Task<IActionResult> GetAsync(TId id)
6464
[HttpGet("{id}/relationships/{relationshipName}")]
6565
public virtual async Task<IActionResult> GetRelationshipsAsync(TId id, string relationshipName)
6666
{
67-
var relationship = _resourceService.GetRelationshipAsync(id, relationshipName);
67+
var relationship = _resourceService.GetRelationshipsAsync(id, relationshipName);
6868
if(relationship == null)
6969
return NotFound();
7070

src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs

+35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using JsonApiDotNetCore.Internal;
14
using Microsoft.AspNetCore.Mvc;
25

36
namespace JsonApiDotNetCore.Controllers
@@ -13,5 +16,37 @@ protected IActionResult Forbidden()
1316
{
1417
return new StatusCodeResult(403);
1518
}
19+
20+
protected IActionResult Error(Error error)
21+
{
22+
var errorCollection = new ErrorCollection {
23+
Errors = new List<Error> { error }
24+
};
25+
var result = new ObjectResult(errorCollection);
26+
result.StatusCode = error.StatusCode;
27+
28+
return result;
29+
}
30+
31+
protected IActionResult Errors(ErrorCollection errors)
32+
{
33+
var result = new ObjectResult(errors);
34+
result.StatusCode = GetErrorStatusCode(errors);
35+
36+
return result;
37+
}
38+
39+
private int GetErrorStatusCode(ErrorCollection errors)
40+
{
41+
var statusCodes = errors.Errors
42+
.Select(e => e.StatusCode)
43+
.Distinct()
44+
.ToList();
45+
46+
if(statusCodes.Count == 1)
47+
return statusCodes[0];
48+
49+
return int.Parse(statusCodes.Max().ToString()[0] + "00");
50+
}
1651
}
1752
}

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public DefaultEntityRepository(
4949

5050
public virtual IQueryable<TEntity> Get()
5151
{
52-
return _dbSet.Select(_jsonApiContext.QuerySet?.Fields);
52+
if(_jsonApiContext.QuerySet?.Fields != null && _jsonApiContext.QuerySet.Fields.Any())
53+
return _dbSet.Select(_jsonApiContext.QuerySet?.Fields);
54+
55+
return _dbSet;
5356
}
5457

5558
public virtual IQueryable<TEntity> Filter(IQueryable<TEntity> entities, FilterQuery filterQuery)
@@ -85,9 +88,16 @@ public virtual async Task<TEntity> GetAsync(TId id)
8588

8689
public virtual async Task<TEntity> GetAndIncludeAsync(TId id, string relationshipName)
8790
{
88-
return await Get()
91+
_logger.LogDebug($"[JADN] GetAndIncludeAsync({id}, {relationshipName})");
92+
93+
var result = await Get()
8994
.Include(relationshipName)
90-
.SingleOrDefaultAsync(e => e.Id.Equals(id));
95+
.Where(e => e.Id.Equals(id))
96+
.ToListAsync();
97+
98+
_logger.LogDebug($"[JADN] Found {result.Count} entity");
99+
100+
return result.SingleOrDefault();
91101
}
92102

93103
public virtual async Task<TEntity> CreateAsync(TEntity entity)

src/JsonApiDotNetCore/JsonApiDotNetCore.csproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<VersionPrefix>2.0.4</VersionPrefix>
3+
<VersionPrefix>2.0.5</VersionPrefix>
44
<TargetFrameworks>netstandard1.6</TargetFrameworks>
55
<AssemblyName>JsonApiDotNetCore</AssemblyName>
66
<PackageId>JsonApiDotNetCore</PackageId>
7-
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
87
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
98
</PropertyGroup>
109
<PropertyGroup>

src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public object Deserialize(string requestBody)
3131
return entity;
3232
}
3333

34+
public object Deserialize<TEntity>(string requestBody)
35+
{
36+
return (TEntity)Deserialize(requestBody);
37+
}
38+
3439
public object DeserializeRelationship(string requestBody)
3540
{
3641
var data = JToken.Parse(requestBody)["data"];

test/NoEntityFrameworkTests/appsettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Data": {
3-
"DefaultConnection": "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=postgres"
3+
"DefaultConnection": "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password="
44
},
55
"Logging": {
66
"IncludeScopes": false,

0 commit comments

Comments
 (0)