Skip to content

Instantly share code, notes, and snippets.

@wfaler
Created January 18, 2011 00:55
Show Gist options
  • Save wfaler/783814 to your computer and use it in GitHub Desktop.
Save wfaler/783814 to your computer and use it in GitHub Desktop.
import org.bowlerframework.controller.Controller
import org.bowlerframework.model.{ ParameterMapper, Validations}
import org.bowlerframework.view.{Renderable}
/**
*
* extends:
* - Controller: used to construct routes and deal with them by providing functions that respond to routes.
* - ParameterMapper: takes a request and maps any values into beans or other objects.
* - Validations: validation enables the Controller
* - Renderable: allows you to render View Model objects.
*/
class WidgetController extends Controller with FunctionNameConventionRoutes with Validations with Renderable {
// HTTP POST for creating new Widgets.
def `POST /widgets`(widget: Widget) = {
// validate the Widget, pass the widget as a param, so the validation error functionality knows which object
// failed validation, IF it fails.
validate(widget){
val validator = new WidgetValidator(widget)
validator.add(new UniqueValidator({widget.id}))
validator.validate // returns an Option[List[Tuple2[String,String]] where :
// None = no validation errors
// Some with a List: validation errors, 1st String in tuple: property key, 2nd String: error message.
}
Widgets.create(widget)
render(widget)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment