This repository has been archived by the owner on Jul 20, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32a6449
commit ff5281b
Showing
15 changed files
with
202 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.