Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocolize Controller #58

Merged
merged 1 commit into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ import Vapor

class HeartbeatController: Controller {

override func index(request: Request) -> AnyObject {
func index(request: Request) throws -> ResponseConvertible {
return ["lub": "dub"]
}

Expand Down
34 changes: 21 additions & 13 deletions Sources/Controller.swift
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
/**
* Organize your routing logic with a subclass of
* `Controller`. Controlls group related route logic into
* a single class that, by default, conforms to standard
* Organize your routing logic with a conformance of
* `Controller`. Controls group related route logic into
* a single protocol that, by default, conforms to standard
* CRUD operations.
*/
public class Controller {
public protocol Controller: class {
/// Display many instances
func index(request: Request) throws -> ResponseConvertible

///Create a default controller
public init() {}
/// Create a new instance.
func store(request: Request) throws -> ResponseConvertible

///Display many instances
/// Show an instance.
func show(request: Request) throws -> ResponseConvertible

/// Update an instance.
func update(request: Request) throws -> ResponseConvertible

/// Delete an instance.
func destroy(request: Request) throws -> ResponseConvertible

}

extension Controller {
public func index(request: Request) throws -> ResponseConvertible {
return "index"
}

///Create a new instance.
public func store(request: Request) throws -> ResponseConvertible {
return "store"
}

///Show an instance.
public func show(request: Request) throws -> ResponseConvertible {
return "show"
}

///Update an instance.
public func update(request: Request) throws -> ResponseConvertible {
return "update"
}

///Delete an instance.
public func destroy(request: Request) throws -> ResponseConvertible {
return "destroy"
}

}
}