Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 8c33607

Browse files
authored
Merge pull request #18 from trainline/dev
Merge dev into master
2 parents a24e063 + 4ec5e8c commit 8c33607

File tree

30 files changed

+446
-82
lines changed

30 files changed

+446
-82
lines changed

src/NJsonApiCore.Web.MVC5.HelloWorld/Controllers/ArticlesController.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ public IHttpActionResult Get()
2020
md.GetMetaData().Add("response created", DateTime.Now);
2121
md.GetMetaData().Add("response created by", this.GetType());
2222
md.Links.Add("link1", new SimpleLink(new Uri("http://localhost")));
23+
24+
md.Links.Add("link2", new SimpleLink(new Uri("http://localhost")));
25+
26+
var complexLink = new LinkObject(new Uri("http://localhost/complex/"));
27+
complexLink.Meta.Add("linkmeta", "linkmetavalue");
28+
md.Links.Add("complexLink", complexLink);
29+
2330
return Ok(md);
2431
}
2532

@@ -40,7 +47,15 @@ public IHttpActionResult Get(int id)
4047
var md = new TopLevelDocument<Article>(a);
4148
md.GetMetaData().Add("response created", DateTime.Now);
4249
md.GetMetaData().Add("response created by", this.GetType());
50+
4351
md.Links.Add("link1", new SimpleLink(new Uri("http://localhost")));
52+
53+
md.Links.Add("link2", new SimpleLink(new Uri("http://localhost")));
54+
55+
var complexLink = new LinkObject(new Uri("http://localhost/complex/"));
56+
complexLink.Meta.Add("linkmeta", "linkmetavalue");
57+
md.Links.Add("complexLink", complexLink);
58+
4459
return Ok(md);
4560
}
4661

src/NJsonApiCore.Web.MVC5.HelloWorld/Models/Article.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
using NJsonApi.Infrastructure;
2+
using NJsonApi.Serialization.Representations;
23
using System.Collections.Generic;
4+
using System;
35

46
namespace NJsonApi.Web.MVC5.HelloWorld.Models
57
{
6-
public class Article : ObjectMetaDataContainer
8+
public class Article : IObjectMetaDataContainer, IObjectLinkContainer
79
{
10+
private ObjectMetaDataContainer _metaDataContainer = new ObjectMetaDataContainer();
11+
private ObjectLinkContainer _linkContainer = new ObjectLinkContainer();
12+
813
public Article()
914
{
1015
}
@@ -17,7 +22,6 @@ public Article(string title)
1722
PublishedInYears = new List<int>();
1823
Id = StaticPersistentStore.GetNextId();
1924
Title = title;
20-
2125
}
2226

2327
public int Id { get; set; }
@@ -44,5 +48,15 @@ public Article(string title)
4448

4549
// an array of simple types that serializes as an attribute
4650
public List<int> PublishedInYears { get; set; }
51+
52+
public ILinkData GetLinks()
53+
{
54+
return _linkContainer.GetLinks();
55+
}
56+
57+
public MetaData GetMetaData()
58+
{
59+
return _metaDataContainer.GetMetaData();
60+
}
4761
}
4862
}

src/NJsonApiCore.Web.MVC5.HelloWorld/Models/StaticPersistentStore.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NJsonApi.Infrastructure;
2+
using NJsonApi.Serialization.Representations;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -46,6 +47,13 @@ static StaticPersistentStore()
4647
article1.MoreComments.Add(comment3);
4748
article1.MoreComments.Add(comment4);
4849
article1.GetMetaData().Add("article created", DateTime.Now);
50+
51+
article1.GetLinks().Add("simplelink", new SimpleLink(new Uri("http://localhost/simplelink")));
52+
53+
var complexLink = new LinkObject(new Uri("http://localhost/complex/"));
54+
complexLink.Meta.Add("linkmeta", "linkmetavalue");
55+
article1.GetLinks().Add("complexLink", complexLink);
56+
4957
article1.SingleTag = new Tag { Key = "tag key", Value = "single tag value" };
5058
article1.MoreTags.Add(new Tag { Key = "tag key (more)", Value = "tag value 1" });
5159
article1.MoreTags.Add(new Tag { Key = "tag key (more)", Value = "tag value 2" });

src/NJsonApiCore.Web.MVC5/Serialization/LinkBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public LinkBuilder(HttpConfiguration configuration, IApiExplorer descriptionProv
2020
this.descriptionProvider = descriptionProvider;
2121
}
2222

23-
public ILink FindResourceSelfLink(Context context, string resourceId, IResourceMapping resourceMapping)
23+
public ISimpleLink FindResourceSelfLink(Context context, string resourceId, IResourceMapping resourceMapping)
2424
{
2525
var actions = descriptionProvider.From(resourceMapping.Controller);
2626

@@ -34,15 +34,15 @@ public ILink FindResourceSelfLink(Context context, string resourceId, IResourceM
3434
}
3535

3636
// TODO - Move into NJsonApiCore base library from here and .mVC6
37-
public ILink RelationshipRelatedLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
37+
public ISimpleLink RelationshipRelatedLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
3838
{
3939
var selfLink = FindResourceSelfLink(context, resourceId, resourceMapping).Href;
4040
var completeLink = $"{selfLink}/{linkMapping.RelationshipName}";
4141
return new SimpleLink(new Uri(completeLink));
4242
}
4343

4444
// TODO - Move into NJsonApiCore base library from here and .mVC6
45-
public ILink RelationshipSelfLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
45+
public ISimpleLink RelationshipSelfLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
4646
{
4747
var selfLink = FindResourceSelfLink(context, resourceId, resourceMapping).Href;
4848
var completeLink = $"{selfLink}/relationships/{linkMapping.RelationshipName}";

src/NJsonApiCore.Web.MVCCore/Serialization/LinkBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public LinkBuilder(IApiDescriptionGroupCollectionProvider descriptionProvider)
1717
this.descriptionProvider = descriptionProvider;
1818
}
1919

20-
public ILink FindResourceSelfLink(Context context, string resourceId, IResourceMapping resourceMapping)
20+
public ISimpleLink FindResourceSelfLink(Context context, string resourceId, IResourceMapping resourceMapping)
2121
{
2222
var actions = descriptionProvider.From(resourceMapping.Controller).Items;
2323

@@ -31,14 +31,14 @@ public ILink FindResourceSelfLink(Context context, string resourceId, IResourceM
3131
return ToUrl(context, action, values);
3232
}
3333

34-
public ILink RelationshipRelatedLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
34+
public ISimpleLink RelationshipRelatedLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
3535
{
3636
var selfLink = FindResourceSelfLink(context, resourceId, resourceMapping).Href;
3737
var completeLink = $"{selfLink}/{linkMapping.RelationshipName}";
3838
return new SimpleLink(new Uri(completeLink));
3939
}
4040

41-
public ILink RelationshipSelfLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
41+
public ISimpleLink RelationshipSelfLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
4242
{
4343
var selfLink = FindResourceSelfLink(context, resourceId, resourceMapping).Href;
4444
var completeLink = $"{selfLink}/relationships/{linkMapping.RelationshipName}";

src/NJsonApiCore/IResourceMapping.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,5 @@ public interface IResourceMapping
2323
Dictionary<string, object> GetAttributes(object objectGraph, JsonSerializerSettings settings);
2424

2525
Dictionary<string, object> GetValuesFromAttributes(Dictionary<string, object> attributes);
26-
27-
MetaData GetObjectMetadata(object objectGraph);
28-
MetaData GetRelationshipMetadata(object objectGraph);
2926
}
3027
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using NJsonApi.Infrastructure;
2+
3+
namespace NJsonApi.Serialization.Representations
4+
{
5+
public interface IObjectLinkContainer
6+
{
7+
ILinkData GetLinks();
8+
}
9+
10+
public class ObjectLinkContainer : IObjectLinkContainer
11+
{
12+
private ILinkData _linkData = new LinkData();
13+
14+
public ILinkData GetLinks()
15+
{
16+
return _linkData;
17+
}
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using NJsonApi.Serialization.Representations;
2+
using System.Collections.Generic;
3+
4+
namespace NJsonApi.Infrastructure
5+
{
6+
public interface ILinkData : IDictionary<string, ILink>
7+
{
8+
}
9+
10+
public class LinkData : Dictionary<string, ILink>, ILinkData
11+
{
12+
13+
}
14+
}

src/NJsonApiCore/Infrastructure/IMetaDataContainer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using NJsonApi.Infrastructure;
2-
3-
namespace NJsonApi.Infrastructure
1+
namespace NJsonApi.Infrastructure
42
{
53
public interface IObjectMetaDataContainer
64
{

src/NJsonApiCore/NJsonApiCore.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
<Compile Include="Conventions\IResourceTypeConvention.cs" />
6868
<Compile Include="Exceptions\MissingMappingException.cs" />
6969
<Compile Include="IConfiguration.cs" />
70+
<Compile Include="Infrastructure\ILinkContainer.cs" />
71+
<Compile Include="Infrastructure\ILinkData.cs" />
7072
<Compile Include="Infrastructure\IMetaDataContainer.cs" />
7173
<Compile Include="Infrastructure\TopLevelDocument.cs" />
7274
<Compile Include="Infrastructure\CollectionDelta.cs" />

0 commit comments

Comments
 (0)