Skip to content

v2.0.5 #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
before_script:
- psql -c 'create database JsonApiDotNetCoreExample;' -U postgres
mono: none
dotnet: 1.0.1
dotnet: 1.0.4 # https://www.microsoft.com/net/download/linux
branches:
only:
- master
Expand Down
7 changes: 6 additions & 1 deletion Build.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)

dotnet restore .\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj
dotnet restore

dotnet test ./test/UnitTests/UnitTests.csproj
dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj
dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj

dotnet build .\src\JsonApiDotNetCore -c Release

echo "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"
Expand Down
15 changes: 15 additions & 0 deletions JsonApiDotnetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoEntityFrameworkExample",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoEntityFrameworkTests", "test\NoEntityFrameworkTests\NoEntityFrameworkTests.csproj", "{73DA578D-A63F-4956-83ED-6D7102E09140}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "test\UnitTests\UnitTests.csproj", "{6D4BD85A-A262-44C6-8572-FE3A30410BF3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -80,6 +82,18 @@ Global
{73DA578D-A63F-4956-83ED-6D7102E09140}.Release|x64.Build.0 = Release|Any CPU
{73DA578D-A63F-4956-83ED-6D7102E09140}.Release|x86.ActiveCfg = Release|Any CPU
{73DA578D-A63F-4956-83ED-6D7102E09140}.Release|x86.Build.0 = Release|Any CPU
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x64.ActiveCfg = Debug|x64
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x64.Build.0 = Debug|x64
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x86.ActiveCfg = Debug|x86
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Debug|x86.Build.0 = Debug|x86
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|Any CPU.Build.0 = Release|Any CPU
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x64.ActiveCfg = Release|x64
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x64.Build.0 = Release|x64
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x86.ActiveCfg = Release|x86
{6D4BD85A-A262-44C6-8572-FE3A30410BF3}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -90,5 +104,6 @@ Global
{0B959765-40D2-43B5-87EE-FE2FEF9DBED5} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
{570165EC-62B5-4684-A139-8D2A30DD4475} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
{73DA578D-A63F-4956-83ED-6D7102E09140} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
{6D4BD85A-A262-44C6-8572-FE3A30410BF3} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
EndGlobalSection
EndGlobal
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@ A framework for building [json:api](http://jsonapi.org/) compliant web servers.

## Installation And Usage

See the documentation [here](https://research-institute.github.io/json-api-dotnet-core)
See the documentation [here](https://research-institute.github.io/json-api-dotnet-core)


## .Net Core v2 Notes

Branch `feat/core-2` is where I am working on .Net Core 2 compatibility tests and package upgrades.
There are several blockers to be aware of:

- Microsoft.AspNetCore.* packages target the runtime (netcoreapp) instead of netstandard.
This will be fixed in future versions.
- EF bug against netcoreapp2.0 runtime ([EntityFramework#8021](https://github.com/aspnet/EntityFramework/issues/8021))
- 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)
32 changes: 31 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
version: '{build}'
os: Visual Studio 2017

environment:
POSTGRES_PORT: tcp://localhost:5432
POSTGRES_ENV_POSTGRES_USER: postgres
POSTGRES_ENV_POSTGRES_PASSWORD: Password12!
POSTGRES_ENV_POSTGRES_DB: JsonApiDotNetCoreExample
PGUSER: postgres
PGPASSWORD: Password12!
Data:DefaultConnection: "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=Password12!"

pull_requests:
do_not_increment_build_number: true

branches:
only:
- master
- develop
- unstable

nuget:
disable_publish_on_pr: true

init:
- SET PATH=C:\Program Files\PostgreSQL\9.6\bin\;%PATH%

services:
- postgresql

build_script:
- ps: createdb JsonApiDotNetCoreExample
- ps: dotnet --version
- ps: .\Build.ps1

test: off

artifacts:
- path: .\**\artifacts\**\*.nupkg
name: NuGet
Expand All @@ -23,10 +46,17 @@ deploy:
skip_symbols: true
on:
branch: develop
- provider: NuGet
server: https://www.myget.org/F/jadnc/api/v2/package
api_key:
secure: 6CeYcZ4Ze+57gxfeuHzqP6ldbUkPtF6pfpVM1Gw/K2jExFrAz763gNAQ++tiacq3
skip_symbols: true
on:
branch: unstable
- provider: NuGet
name: production
api_key:
secure: /fsEOgG4EdtNd6DPmko9h3NxQwx1IGDcFreGTKd2KA56U2KEkpX/L/pCGpCIEf2s
on:
branch: master
appveyor_repo_tag: true
appveyor_repo_tag: true
6 changes: 2 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#exit if any command fails
set -e

dotnet restore ./src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
dotnet restore ./src/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj
dotnet restore ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj
dotnet restore ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
dotnet restore

dotnet test ./test/UnitTests/UnitTests.csproj
dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj
dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
5 changes: 4 additions & 1 deletion docs/Errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public void MyMethod() {
public override async Task<IActionResult> PostAsync([FromBody] MyEntity entity)
{
if(_db.IsFull)
return new ObjectResult(new CustomError("507", "Database is full.", "Theres no more room.", "Sorry."));
return Error(new CustomError("507", "Database is full.", "Theres no more room.", "Sorry."));

if(model.Validations.IsValid == false)
return Errors(model.Validations.Select(v => v.GetErrors()));

// ...
}
```
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/Controllers/JsonApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public virtual async Task<IActionResult> GetAsync(TId id)
[HttpGet("{id}/relationships/{relationshipName}")]
public virtual async Task<IActionResult> GetRelationshipsAsync(TId id, string relationshipName)
{
var relationship = _resourceService.GetRelationshipAsync(id, relationshipName);
var relationship = _resourceService.GetRelationshipsAsync(id, relationshipName);
if(relationship == null)
return NotFound();

Expand Down
35 changes: 35 additions & 0 deletions src/JsonApiDotNetCore/Controllers/JsonApiControllerMixin.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using JsonApiDotNetCore.Internal;
using Microsoft.AspNetCore.Mvc;

namespace JsonApiDotNetCore.Controllers
Expand All @@ -13,5 +16,37 @@ protected IActionResult Forbidden()
{
return new StatusCodeResult(403);
}

protected IActionResult Error(Error error)
{
var errorCollection = new ErrorCollection {
Errors = new List<Error> { error }
};
var result = new ObjectResult(errorCollection);
result.StatusCode = error.StatusCode;

return result;
}

protected IActionResult Errors(ErrorCollection errors)
{
var result = new ObjectResult(errors);
result.StatusCode = GetErrorStatusCode(errors);

return result;
}

private int GetErrorStatusCode(ErrorCollection errors)
{
var statusCodes = errors.Errors
.Select(e => e.StatusCode)
.Distinct()
.ToList();

if(statusCodes.Count == 1)
return statusCodes[0];

return int.Parse(statusCodes.Max().ToString()[0] + "00");
}
}
}
16 changes: 13 additions & 3 deletions src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public DefaultEntityRepository(

public virtual IQueryable<TEntity> Get()
{
return _dbSet.Select(_jsonApiContext.QuerySet?.Fields);
if(_jsonApiContext.QuerySet?.Fields != null && _jsonApiContext.QuerySet.Fields.Any())
return _dbSet.Select(_jsonApiContext.QuerySet?.Fields);

return _dbSet;
}

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

public virtual async Task<TEntity> GetAndIncludeAsync(TId id, string relationshipName)
{
return await Get()
_logger.LogDebug($"[JADN] GetAndIncludeAsync({id}, {relationshipName})");

var result = await Get()
.Include(relationshipName)
.SingleOrDefaultAsync(e => e.Id.Equals(id));
.Where(e => e.Id.Equals(id))
.ToListAsync();

_logger.LogDebug($"[JADN] Found {result.Count} entity");

return result.SingleOrDefault();
}

public virtual async Task<TEntity> CreateAsync(TEntity entity)
Expand Down
3 changes: 1 addition & 2 deletions src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>2.0.4</VersionPrefix>
<VersionPrefix>2.0.5</VersionPrefix>
<TargetFrameworks>netstandard1.6</TargetFrameworks>
<AssemblyName>JsonApiDotNetCore</AssemblyName>
<PackageId>JsonApiDotNetCore</PackageId>
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
</PropertyGroup>
<PropertyGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public object Deserialize(string requestBody)
return entity;
}

public object Deserialize<TEntity>(string requestBody)
{
return (TEntity)Deserialize(requestBody);
}

public object DeserializeRelationship(string requestBody)
{
var data = JToken.Parse(requestBody)["data"];
Expand Down
2 changes: 1 addition & 1 deletion test/NoEntityFrameworkTests/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Data": {
"DefaultConnection": "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=postgres"
"DefaultConnection": "Host=localhost;Port=5432;Database=JsonApiDotNetCoreExample;User ID=postgres;Password="
},
"Logging": {
"IncludeScopes": false,
Expand Down
Loading