Skip to content

Commit

Permalink
Merge pull request #12 from ethankershaw/ethankershaw/fix-11
Browse files Browse the repository at this point in the history
Bump to latest Carter and resolve implementation differences
  • Loading branch information
ritasker authored Aug 8, 2024
2 parents dc6e5c6 + c9d16fd commit 1ca2d2e
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 254 deletions.
61 changes: 53 additions & 8 deletions Carter.SirenNegotiator.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 17
VisualStudioVersion = 17.10.34928.147
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter.SirenNegotiator", "src\Carter.SirenNegotiator.csproj", "{9851A51A-30F8-42F1-921B-058FB6CF1812}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Carter.SirenNegotiator", "src\Carter.SirenNegotiator.csproj", "{9851A51A-30F8-42F1-921B-058FB6CF1812}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter.SirenNegotiator.Sample", "sample\Carter.SirenNegotiator.Sample.csproj", "{7284EA4C-65F1-40B6-9444-074014D794CA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Carter.SirenNegotiator.Sample", "sample\Carter.SirenNegotiator.Sample.csproj", "{7284EA4C-65F1-40B6-9444-074014D794CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carter", "dependances\Carter\src\Carter.csproj", "{905D58FC-4E5F-431F-875D-ECDD3B4620A1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Carter", "dependances\Carter\src\Carter\Carter.csproj", "{905D58FC-4E5F-431F-875D-ECDD3B4620A1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Carter.Analyzers", "dependances\Carter\src\Carter.Analyzers\Carter.Analyzers.csproj", "{4316FB9B-92B1-477C-AE27-72CA44103EDB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarterSample", "dependances\Carter\samples\CarterSample\CarterSample.csproj", "{B0B4A850-BE1E-4334-8A27-7B4C235DC781}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ValidatorOnlyProject", "dependances\Carter\samples\ValidatorOnlyProject\ValidatorOnlyProject.csproj", "{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -18,9 +24,6 @@ Global
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9851A51A-30F8-42F1-921B-058FB6CF1812}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9851A51A-30F8-42F1-921B-058FB6CF1812}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand Down Expand Up @@ -58,5 +61,47 @@ Global
{905D58FC-4E5F-431F-875D-ECDD3B4620A1}.Release|x64.Build.0 = Release|Any CPU
{905D58FC-4E5F-431F-875D-ECDD3B4620A1}.Release|x86.ActiveCfg = Release|Any CPU
{905D58FC-4E5F-431F-875D-ECDD3B4620A1}.Release|x86.Build.0 = Release|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Debug|x64.ActiveCfg = Debug|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Debug|x64.Build.0 = Debug|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Debug|x86.ActiveCfg = Debug|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Debug|x86.Build.0 = Debug|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Release|Any CPU.Build.0 = Release|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Release|x64.ActiveCfg = Release|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Release|x64.Build.0 = Release|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Release|x86.ActiveCfg = Release|Any CPU
{4316FB9B-92B1-477C-AE27-72CA44103EDB}.Release|x86.Build.0 = Release|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Debug|x64.ActiveCfg = Debug|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Debug|x64.Build.0 = Debug|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Debug|x86.ActiveCfg = Debug|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Debug|x86.Build.0 = Debug|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Release|Any CPU.Build.0 = Release|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Release|x64.ActiveCfg = Release|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Release|x64.Build.0 = Release|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Release|x86.ActiveCfg = Release|Any CPU
{B0B4A850-BE1E-4334-8A27-7B4C235DC781}.Release|x86.Build.0 = Release|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Debug|x64.ActiveCfg = Debug|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Debug|x64.Build.0 = Debug|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Debug|x86.ActiveCfg = Debug|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Debug|x86.Build.0 = Debug|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Release|Any CPU.Build.0 = Release|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Release|x64.ActiveCfg = Release|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Release|x64.Build.0 = Release|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Release|x86.ActiveCfg = Release|Any CPU
{FEB0F9D7-F8E8-41D8-BD81-1722D31A5DB4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DB4AAC23-679F-4641-9016-97AD11427530}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion dependances/Carter
Submodule Carter updated 149 files
8 changes: 2 additions & 6 deletions sample/Carter.SirenNegotiator.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>Carter.SirenNegotiator.Sample</AssemblyName>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Carter.SirenNegotiator.csproj" />
</ItemGroup>
Expand Down
13 changes: 6 additions & 7 deletions sample/Features/Actors/Actor.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace CarterSample.Features.Actors
namespace Carter.SirenNegotiator.Sample.Features.Actors;

public class Actor
{
public class Actor
{
public string Name { get; set; }
public int Id { get; set; }
public int Age { get; set; }
}
public string Name { get; set; }
public int Id { get; set; }
public int Age { get; set; }
}
57 changes: 28 additions & 29 deletions sample/Features/Actors/ActorProvider.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
namespace CarterSample.Features.Actors
namespace Carter.SirenNegotiator.Sample.Features.Actors;

using System.Collections.Generic;
using System.Linq;

public class ActorProvider : IActorProvider
{
using System.Collections.Generic;
using System.Linq;
private static IList<Actor> database = new[] { new Actor { Name = "Brad Pitt", Id = 1, Age = 51 }, new Actor { Name = "Jason Statham", Id = 2, Age = 43 } };

public class ActorProvider : IActorProvider
public IEnumerable<Actor> Get()
{
private static IList<Actor> database = new[] { new Actor { Name = "Brad Pitt", Id = 1, Age = 51 }, new Actor { Name = "Jason Statham", Id = 2, Age = 43 } };

public IEnumerable<Actor> Get()
{
return database;
}
return database;
}

public Actor Get(int id)
{
return database.First(x => x.Id == id);
}
public Actor Get(int id)
{
return database.First(x => x.Id == id);
}

public void Add(Actor actor)
{
actor.Id = database.Max(x => x.Id) + 1;
database.Add(actor);
}
public void Add(Actor actor)
{
actor.Id = database.Max(x => x.Id) + 1;
database.Add(actor);
}

public void Update(Actor actor)
{
var actorRef = database.First(x => x.Id == actor.Id);
actorRef.Age = actor.Age;
actorRef.Name = actor.Name;
}
public void Update(Actor actor)
{
var actorRef = database.First(x => x.Id == actor.Id);
actorRef.Age = actor.Age;
actorRef.Name = actor.Name;
}

public void Delete(Actor actor)
{
database.Remove(actor);
}
public void Delete(Actor actor)
{
database.Remove(actor);
}
}
97 changes: 48 additions & 49 deletions sample/Features/Actors/ActorResponseGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
namespace CarterSample.Features.Actors
namespace Carter.SirenNegotiator.Sample.Features.Actors;

using System;
using System.Collections.Generic;
using System.Linq;
using Carter.SirenNegotiator;
using Action = Carter.SirenNegotiator.Action;

public class ActorResponseGenerator : ISirenResponseGenerator
{
using System;
using System.Collections.Generic;
using System.Linq;
using Carter.SirenNegotiator;
using Action = Carter.SirenNegotiator.Action;
public bool CanHandle(Type type)
{
var listType = typeof(IEnumerable<Actor>);
var classType = typeof(Actor);
return classType.IsAssignableFrom(type) || listType.IsAssignableFrom(type);
}

public class ActorResponseGenerator : ISirenResponseGenerator
public Siren Generate(object data, Uri uri)
{
public bool CanHandle(Type type)
{
var listType = typeof(IEnumerable<Actor>);
var classType = typeof(Actor);
return classType.IsAssignableFrom(type) || listType.IsAssignableFrom(type);
}
return data is IEnumerable<Actor>
? Generate((IEnumerable<Actor>)data, uri)
: Generate((Actor)data, uri);
}

public Siren Generate(object data, Uri uri)
private Siren Generate(IEnumerable<Actor> actors, Uri uri)
{
var doc = new Siren
{
return data is IEnumerable<Actor>
? Generate((IEnumerable<Actor>) data, uri)
: Generate((Actor) data, uri);
}
@class = new[] { "collection" },
entities = new List<Entity>(),
properties = new { Count = actors.Count() }
};

private Siren Generate(IEnumerable<Actor> actors, Uri uri)
foreach (var actor in actors)
{
var doc = new Siren
var entity = new Entity
{
@class = new [] { "collection" },
entities = new List<Entity> (),
properties = new { Count = actors.Count() }
@class = new[] { nameof(Actor) },
rel = new[] { "item" },
properties = actor,
links = new List<Link> { new Link { href = uri + "/" + actor.Id, rel = new[] { "self" } } }
};

foreach (var actor in actors)
{
var entity = new Entity
{
@class = new [] { nameof(Actor) },
rel = new [] { "item" },
properties = actor,
links = new List<Link> { new Link { href = uri + "/" + actor.Id, rel = new [] { "self" } } }
};

doc.entities.Add (entity);
}
doc.entities.Add(entity);
}

doc.actions = new List<Action> (new []{
doc.actions = new List<Action>(new[]{

new Action
{
Expand All @@ -57,19 +57,19 @@ private Siren Generate(IEnumerable<Actor> actors, Uri uri)
}
});

doc.links = new List<Link> { new Link { href = uri.ToString(), rel = new [] { "self" } } };
doc.links = new List<Link> { new Link { href = uri.ToString(), rel = new[] { "self" } } };

return doc;
}

private Siren Generate(Actor actor, Uri uri)
return doc;
}

private Siren Generate(Actor actor, Uri uri)
{
return new Siren
{
return new Siren
{
@class = new [] { nameof(Actor) },
properties = actor,
links = new List<Link> { new Link { href = uri.ToString(), rel = new [] { "self" } } },
actions = new List<Action> (new []{
@class = new[] { nameof(Actor) },
properties = actor,
links = new List<Link> { new Link { href = uri.ToString(), rel = new[] { "self" } } },
actions = new List<Action>(new[]{
new Action
{
name = "update-actor",
Expand All @@ -87,7 +87,6 @@ private Siren Generate(Actor actor, Uri uri)
href = uri.ToString()
}
})
};
}
};
}
}
17 changes: 8 additions & 9 deletions sample/Features/Actors/ActorValidator.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
namespace CarterSample.Features.Actors
{
using FluentValidation;
namespace Carter.SirenNegotiator.Sample.Features.Actors;

using FluentValidation;

public class ActorValidator : AbstractValidator<Actor>
public class ActorValidator : AbstractValidator<Actor>
{
public ActorValidator()
{
public ActorValidator()
{
this.RuleFor(x => x.Name).NotEmpty();
this.RuleFor(x => x.Name).NotEmpty();

this.RuleFor(x => x.Age).GreaterThan(0);
}
this.RuleFor(x => x.Age).GreaterThan(0);
}
}
Loading

0 comments on commit 1ca2d2e

Please sign in to comment.