Last active
March 8, 2016 05:35
-
-
Save paulofaria/02385cee2a4ec773964d to your computer and use it in GitHub Desktop.
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
let todoResources = Resource(middleware: recovery, contentNegotiaton) { todo in | |
todo.index { _ in | |
let todos = try app.getAllTodos() | |
return Response(content: ["todos": todos.content]) | |
} | |
todo.create(mappingTo: Todo.self) { request, todo in | |
let todo = try app.createTodo(todo) | |
return Response(content: todo) | |
} | |
todo.show { _, id in | |
let todo = try app.getTodo(id: id) | |
return Response(content: todo) | |
} | |
todo.update { request, id, content in | |
let todo = try app.updateTodo( | |
id: id, | |
title: try? content.get("title"), | |
done: try? content.get("done") | |
) | |
return Response(content: todo) | |
} | |
todo.destroy { _, id in | |
try app.removeTodo(id: id) | |
return Response(status: .NoContent) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment