Skip to content

Commit 663048b

Browse files
committed
update readme and add ci scripts
1 parent c590b8a commit 663048b

File tree

5 files changed

+154
-14
lines changed

5 files changed

+154
-14
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: csharp
2+
dist: trusty
3+
sudo: required
4+
mono: none
5+
dotnet: 1.0.0-preview2-1-003177
6+
script:
7+
- ./build.sh

Build.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<#
2+
.SYNOPSIS
3+
You can add this to you build script to ensure that psbuild is available before calling
4+
Invoke-MSBuild. If psbuild is not available locally it will be downloaded automatically.
5+
#>
6+
function EnsurePsbuildInstalled{
7+
[cmdletbinding()]
8+
param(
9+
[string]$psbuildInstallUri = 'https://raw.githubusercontent.com/ligershark/psbuild/master/src/GetPSBuild.ps1'
10+
)
11+
process{
12+
if(-not (Get-Command "Invoke-MsBuild" -errorAction SilentlyContinue)){
13+
'Installing psbuild from [{0}]' -f $psbuildInstallUri | Write-Verbose
14+
(new-object Net.WebClient).DownloadString($psbuildInstallUri) | iex
15+
}
16+
else{
17+
'psbuild already loaded, skipping download' | Write-Verbose
18+
}
19+
20+
# make sure it's loaded and throw if not
21+
if(-not (Get-Command "Invoke-MsBuild" -errorAction SilentlyContinue)){
22+
throw ('Unable to install/load psbuild from [{0}]' -f $psbuildInstallUri)
23+
}
24+
}
25+
}
26+
27+
# Taken from psake https://github.com/psake/psake
28+
29+
<#
30+
.SYNOPSIS
31+
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
32+
to see if an error occcured. If an error is detected then an exception is thrown.
33+
This function allows you to run command-line programs without having to
34+
explicitly check the $lastexitcode variable.
35+
.EXAMPLE
36+
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
37+
#>
38+
function Exec
39+
{
40+
[CmdletBinding()]
41+
param(
42+
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
43+
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
44+
)
45+
& $cmd
46+
if ($lastexitcode -ne 0) {
47+
throw ("Exec: " + $errorMessage)
48+
}
49+
}
50+
51+
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
52+
53+
EnsurePsbuildInstalled
54+
55+
exec { & dotnet restore }
56+
57+
Invoke-MSBuild
58+
59+
$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
60+
$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)
61+
62+
exec { & dotnet test .\test\JsonApiDotNetCoreExampleTests -c Release }
63+
64+
exec { & dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision }

README.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,42 @@
22

33
# Generators
44

5-
- TODO: Document usage of the yeoman jadn generator
5+
You can install the [Yeoman generators](https://github.com/Research-Institute/json-api-dotnet-core-generators)
6+
to make building applications much easier.
67

78
## Usage
89

9-
- Add Middleware
10+
You need to do 3 things:
11+
12+
- Add Middleware and Services
1013
- Define Models
1114
- Define Controllers
1215

16+
I recommend reading the details below, but once you're familiar with the
17+
setup, you can use the Yeoman generator to generate the required classes.
18+
19+
## Middleware and Services
20+
21+
Add the following to your `Startup.ConfigureServices` method.
22+
Replace `AppDbContext` with your DbContext.
23+
24+
```csharp
25+
services.AddJsonApi<AppDbContext>();
26+
```
27+
28+
Add the middleware to the `Startup.Configure` method.
29+
Note that under the hood, this will call `app.UseMvc()`
30+
so there is no need to add that as well.
31+
32+
```csharp
33+
app.UseJsonApi();
34+
```
35+
1336
## Defining Models
1437

1538
Your models should inherit `Identifiable<TId>` where `TId` is the type of the primary key, like so:
1639

17-
```
40+
```csharp
1841
public class Person : Identifiable<Guid>
1942
{
2043
public override Guid Id { get; set; }
@@ -26,7 +49,7 @@ public class Person : Identifiable<Guid>
2649
If you want an attribute on your model to be publicly available,
2750
add the `AttrAttribute` and provide the outbound name.
2851

29-
```
52+
```csharp
3053
public class Person : Identifiable<int>
3154
{
3255
public override int Id { get; set; }
@@ -38,9 +61,10 @@ public class Person : Identifiable<int>
3861

3962
### Relationships
4063

41-
In order for navigation properties to be identified in the model, they should be labeled as virtual.
64+
In order for navigation properties to be identified in the model,
65+
they should be labeled as virtual.
4266

43-
```
67+
```csharp
4468
public class Person : Identifiable<int>
4569
{
4670
public override int Id { get; set; }
@@ -55,7 +79,7 @@ public class Person : Identifiable<int>
5579
Dependent relationships should contain a property in the form `{RelationshipName}Id`.
5680
For example, a `TodoItem` may have an `Owner` and so the Id attribute should be `OwnerId` like so:
5781

58-
```
82+
```csharp
5983
public class TodoItem : Identifiable<int>
6084
{
6185
public override int Id { get; set; }
@@ -73,7 +97,7 @@ public class TodoItem : Identifiable<int>
7397
You need to create controllers that inherit from `JsonApiController<TEntity>` or `JsonApiController<TEntity, TId>`
7498
where `TEntity` is the model that inherits from `Identifiable<TId>`.
7599

76-
```
100+
```csharp
77101
[Route("api/[controller]")]
78102
public class ThingsController : JsonApiController<Thing>
79103
{
@@ -92,7 +116,7 @@ If your model is using a type other than `int` for the primary key,
92116
you should explicitly declare it in the controller
93117
and repository generic type definitions:
94118

95-
```
119+
```csharp
96120
[Route("api/[controller]")]
97121
public class ThingsController : JsonApiController<Thing, Guid>
98122
{
@@ -120,7 +144,7 @@ NOT /todoItems
120144

121145
You can add a namespace to the URL by specifying it in `ConfigureServices`:
122146

123-
```
147+
```csharp
124148
services.AddJsonApi<AppDbContext>(
125149
opt => opt.Namespace = "api/v1");
126150
```
@@ -130,7 +154,7 @@ services.AddJsonApi<AppDbContext>(
130154
If you would like pagination implemented by default, you can specify the page size
131155
when setting up the services:
132156

133-
```
157+
```csharp
134158
services.AddJsonApi<AppDbContext>(
135159
opt => opt.DefaultPageSize = 10);
136160
```
@@ -146,7 +170,6 @@ add to the service collection in `Startup.ConfigureServices` like so:
146170
services.AddScoped<IEntityRepository<MyEntity,Guid>, MyEntityRepository>();
147171
```
148172

149-
150173
## Filtering
151174

152175
You can filter resources by attributes using the `filter` query parameter.
@@ -180,5 +203,3 @@ I am using DotNetCoreDocs to generate sample requests and documentation.
180203
4. `cd ./src/JsonApiDotNetCoreExample`
181204
5. `dotnet run`
182205
6. `open http://localhost:5000/docs`
183-
184-

appveyor.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: '{build}'
2+
pull_requests:
3+
do_not_increment_build_number: true
4+
branches:
5+
only:
6+
- master
7+
nuget:
8+
disable_publish_on_pr: true
9+
build_script:
10+
- ps: .\Build.ps1
11+
test: off
12+
artifacts:
13+
- path: .\artifacts\**\*.nupkg
14+
name: NuGet
15+
deploy:
16+
- provider: NuGet
17+
server: https://www.myget.org/F/research-institute/api/v2/package
18+
api_key:
19+
secure: 6CeYcZ4Ze+57gxfeuHzqP6ldbUkPtF6pfpVM1Gw/K2jExFrAz763gNAQ++tiacq3
20+
skip_symbols: true
21+
on:
22+
branch: master
23+
- provider: NuGet
24+
name: production
25+
api_key:
26+
secure: /fsEOgG4EdtNd6DPmko9h3NxQwx1IGDcFreGTKd2KA56U2KEkpX/L/pCGpCIEf2s
27+
on:
28+
branch: master
29+
appveyor_repo_tag: true

build.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
#exit if any command fails
4+
set -e
5+
6+
artifactsFolder="./artifacts"
7+
8+
if [ -d $artifactsFolder ]; then
9+
rm -R $artifactsFolder
10+
fi
11+
12+
dotnet restore
13+
14+
dotnet test ./test/JsonApiDotNetCoreExampleTests -c Release -f netcoreapp1.0
15+
16+
revision=${TRAVIS_JOB_ID:=1}
17+
revision=$(printf "%04d" $revision)
18+
19+
dotnet pack ./src/JsonApiDotNetCore -c Release -o ./artifacts --version-suffix=$revision

0 commit comments

Comments
 (0)