Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

Commit

Permalink
target netstandard 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Ovens authored and drewfreyling committed Dec 15, 2017
1 parent 32a6449 commit ff5281b
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 487 deletions.
2 changes: 1 addition & 1 deletion SharedAssemblyInfo.cs
Expand Up @@ -5,4 +5,4 @@
[assembly: AssemblyCompany("Dan Barua, Matt Vane, Thomas Eizinger, Richard Bennett")]
[assembly: AssemblyProduct("Nancy.Hal")]
[assembly: AssemblyCopyright("Copyright (C) Dan Barua, Matt Vane, Thomas Eizinger, Richard Bennett and other contributors")]
[assembly: AssemblyVersion("1.2.1")]
[assembly: AssemblyVersion("2.0.0")]
16 changes: 10 additions & 6 deletions rakefile.rb
Expand Up @@ -4,8 +4,12 @@
require 'rake/clean'
require 'rexml/document'

NANCY_VERSION = "1.4.3"
LIB_VERSION = "1.3.0"
NANCY_VERSION = "2.0.0-beta"
LIB_VERSION = "2.0.0-beta0001"
ASSEMBLY_VERSION = LIB_VERSION
if LIB_VERSION.include? "-"
ASSEMBLY_VERSION = LIB_VERSION.gsub(/\-\S+/, '')
end

OUTPUT = "build"
CONFIGURATION = 'Release'
Expand All @@ -16,7 +20,7 @@
Albacore.configure do |config|
config.log_level = :verbose
config.msbuild.use :net4
config.xunit.command = "tools/xunit/xunit.console.clr4.x86.exe"
config.xunit.command = "tools/xunit/xunit.console.clr4.x86.exe"
end

desc "Compiles solution and runs unit tests"
Expand All @@ -28,7 +32,7 @@

desc "Update shared assemblyinfo file for the build"
assemblyinfo :version => [:clean] do |asm|
asm.version = LIB_VERSION
asm.version = ASSEMBLY_VERSION
asm.company_name = "#{CONTRIBUTORS}"
asm.product_name = "Nancy.Hal"
asm.title = "Nancy.Hal"
Expand Down Expand Up @@ -81,7 +85,7 @@

desc "Generates NuGet packages for each project that contains a nuspec"
task :nuget_package => [:publish] do
Dir.mkdir("#{OUTPUT}/nuget")
Dir.mkdir("#{OUTPUT}/nuget")
nuspecs = FileList["src/**/*.nuspec"]
root = File.dirname(__FILE__)

Expand Down Expand Up @@ -159,4 +163,4 @@ def get_assembly_version(file)
return result[1] if !result.nil?
end
end
end
end
102 changes: 46 additions & 56 deletions src/Nancy.Hal.Example/Model/Users/RolesModule.cs
@@ -1,63 +1,53 @@
namespace Nancy.Hal.Example.Model.Users
{
using Nancy;
namespace Nancy.Hal.Example.Model.Users {
using Nancy.Hal.Example.Model.Users.Commands;
using Nancy.Hal.Example.Model.Users.Queries;
using Nancy.ModelBinding;
using Nancy;

public class RolesModule : NancyModule {
public RolesModule (Database db) : base ("/roles") {
this.Get ("/", _ => {
var request = this.Bind<GetRoleList> ();
var roles = db.GetAllRoles ();
return Negotiate.WithModel (roles);
});

this.Get ("/{roleId:guid}", _ => {
var req = this.Bind<GetRoleDetails> ();
var role = db.GetRoleById (req.RoleId);
if (role == null) {
return 404;
}
return Negotiate.WithModel (role);
});

this.Post ("/", _ => {
var req = this.Bind<CreateRole> ();
db.CreateRole (req);
var role = db.GetRoleById (req.Id.GetValueOrDefault ());
return Negotiate
.WithHeader ("Location", "/roles/" + req.Id.GetValueOrDefault ())
.WithModel (role)
.WithStatusCode (HttpStatusCode.Created);
});

this.Put ("/{roleId:guid}", _ => {
var req = this.Bind<UpdateRole> ();
db.UpdateRole (req);
var role = db.GetRoleById (req.RoleId);
return
Negotiate.WithHeader ("Location", "/roles/" + req.RoleId)
.WithModel (role);
});

public class RolesModule : NancyModule
{
public RolesModule(Database db)
: base("/roles")
{
this.Get["/"] = _ =>
{
var request = this.Bind<GetRoleList>();
var roles = db.GetAllRoles();
return Negotiate.WithModel(roles);
};

this.Get["/{roleId:guid}"] = _ =>
{
var req = this.Bind<GetRoleDetails>();
var role = db.GetRoleById(req.RoleId);
if (role == null)
{
return 404;
}
return Negotiate.WithModel(role);
};

this.Post["/"] = _ =>
{
var req = this.Bind<CreateRole>();
db.CreateRole(req);
var role = db.GetRoleById(req.Id.GetValueOrDefault());
return Negotiate
.WithHeader("Location", "/roles/" + req.Id.GetValueOrDefault())
.WithModel(role)
.WithStatusCode(HttpStatusCode.Created);
};

this.Put["/{roleId:guid}"] = _ =>
{
var req = this.Bind<UpdateRole>();
db.UpdateRole(req);
var role = db.GetRoleById(req.RoleId);
return
Negotiate.WithHeader("Location", "/roles/" + req.RoleId)
.WithModel(role);
};

this.Delete["/{roleId:guid}"] = _ =>
{
var req = this.Bind<DeleteRole>();
db.DeleteRole(req);
return this.Negotiate.WithStatusCode(HttpStatusCode.NoContent);
};
this.Delete ("/{roleId:guid}", _ => {
var req = this.Bind<DeleteRole> ();
db.DeleteRole (req);
return this.Negotiate.WithStatusCode (HttpStatusCode.NoContent);
});
}
}
}
127 changes: 58 additions & 69 deletions src/Nancy.Hal.Example/Model/Users/UsersModule.cs
@@ -1,86 +1,75 @@
namespace Nancy.Hal.Example.Model.Users
{
using Nancy;
using Nancy.Hal.Example.Model.Users.Commands;
using Nancy.Hal.Example.Model.Users.Queries;
using Nancy.ModelBinding;
using Nancy;
using Nancy.Hal.Example.Model.Users.Commands;
using Nancy.Hal.Example.Model.Users.Queries;
using Nancy.ModelBinding;
namespace Nancy.Hal.Example.Model.Users {

public class UsersModule : NancyModule
{
public UsersModule(Database db)
: base("/users")
{
this.Get["/"] = _ =>
{
var request = this.Bind<GetUserList>();
var users = db.GetAllUsersPaged(request);
public class UsersModule : NancyModule {
public UsersModule (Database db) : base ("/users") {
this.Get ("/", _ => {
var request = this.Bind<GetUserList> ();
var users = db.GetAllUsersPaged (request);
return Negotiate.WithModel(users);
};
return Negotiate.WithModel (users);
});

this.Get["/{userId:guid}"] = _ =>
{
var request = this.Bind<GetUserDetails>();
var user = db.GetUserById(request.UserId);
if (user == null)
{
return 404;
}
this.Get ("/{userId:guid}", _ => {
var request = this.Bind<GetUserDetails> ();
var user = db.GetUserById (request.UserId);
if (user == null) {
return 404;
}
return Negotiate.WithModel(user);
};
return Negotiate.WithModel (user);
});

this.Post["/"] = _ =>
{
var request = this.Bind<CreateUser>();
db.CreateUser(request);
var user = db.GetUserById(request.Id.GetValueOrDefault());
this.Post ("/", _ => {
var request = this.Bind<CreateUser> ();
db.CreateUser (request);
var user = db.GetUserById (request.Id.GetValueOrDefault ());
return
this.Negotiate.WithHeader("Location", LinkTemplates.Users.GetUser.CreateLink(new { Id = user.Id }).ToString())
.WithModel(user)
.WithStatusCode(HttpStatusCode.Created);
};
return
this.Negotiate.WithHeader ("Location", LinkTemplates.Users.GetUser.CreateLink (new { Id = user.Id }).ToString ())
.WithModel (user)
.WithStatusCode (HttpStatusCode.Created);
});

this.Put["/{userId:guid}"] = _ =>
{
var request = this.Bind<UpdateUserDetails>();
db.UpdateUser(request);
var user = db.GetUserById(request.UserId);
this.Put ("/{userId:guid}", _ => {
var request = this.Bind<UpdateUserDetails> ();
db.UpdateUser (request);
var user = db.GetUserById (request.UserId);
return this.Negotiate.WithModel(user)
.WithStatusCode(HttpStatusCode.OK);
};
return this.Negotiate.WithModel (user)
.WithStatusCode (HttpStatusCode.OK);
});

this.Put["/{userId:guid}/deactivate"] = _ =>
{
var request = this.Bind<DeactivateUser>();
db.Deactivate(request);
var user = db.GetUserById(request.UserId);
this.Put ("/{userId:guid}/deactivate", _ => {
var request = this.Bind<DeactivateUser> ();
db.Deactivate (request);
var user = db.GetUserById (request.UserId);
return this.Negotiate.WithModel(user)
.WithStatusCode(HttpStatusCode.OK);
};
return this.Negotiate.WithModel (user)
.WithStatusCode (HttpStatusCode.OK);
});

this.Put["/{userId:guid}/reactivate"] = _ =>
{
var request = this.Bind<ReactivateUser>();
db.Reactivate(request);
var user = db.GetUserById(request.UserId);
this.Put ("/{userId:guid}/reactivate", _ => {
var request = this.Bind<ReactivateUser> ();
db.Reactivate (request);
var user = db.GetUserById (request.UserId);
return this.Negotiate.WithModel(user)
.WithStatusCode(HttpStatusCode.OK);
};
return this.Negotiate.WithModel (user)
.WithStatusCode (HttpStatusCode.OK);
});

this.Put["/{userId:guid}/role/{roleId:guid}"] = _ =>
{
var request = this.Bind<ChangeUserRole>();
db.ChangeRole(request);
var user = db.GetUserById(request.UserId);
this.Put ("/{userId:guid}/role/{roleId:guid}", _ => {
var request = this.Bind<ChangeUserRole> ();
db.ChangeRole (request);
var user = db.GetUserById (request.UserId);
return this.Negotiate.WithModel(user)
.WithStatusCode(HttpStatusCode.OK);
};
return this.Negotiate.WithModel (user)
.WithStatusCode (HttpStatusCode.OK);
});
}
}
}

0 comments on commit ff5281b

Please sign in to comment.