Skip to content

Instantly share code, notes, and snippets.

@Bowbaq
Created January 6, 2014 23:17
Show Gist options
  • Save Bowbaq/8291695 to your computer and use it in GitHub Desktop.
Save Bowbaq/8291695 to your computer and use it in GitHub Desktop.
diff --git a/servicetown/app/com/angieslist/presentation/core/ConfigurationController.scala b/servicetown/app/com/angieslist/presentation/core/ConfigurationController.scala
index e4cd22d..e4c0c9d 100644
--- a/servicetown/app/com/angieslist/presentation/core/ConfigurationController.scala
+++ b/servicetown/app/com/angieslist/presentation/core/ConfigurationController.scala
@@ -1,11 +1,10 @@
package com.angieslist.presentation.core
import play.api.mvc.{Controller, EssentialAction}
-import utils.{ApiResponseHelpers, SharedAuth}
+import utils.{ApiResponseHelpers, SharedAuth, ControllerUtils}
+import ControllerUtils.deserialize
import utils.Security._
import utils.Security.Group._
-import play.api.data.Form
-import play.api.data.Forms._
trait ConfigurationController {
def get(code: String): EssentialAction
@@ -30,26 +29,11 @@ trait ConfigurationControllerComponentImpl {
} getOrElse ApiResponseHelpers.error(s"RuntimeConfig property missing: ${code}")
}
- def createOrUpdate = securedApiAction(atc) { currentUser => implicit request =>
- val form = configForm.bindFromRequest
- form fold (
- errors => {
- BadRequest
- },
- config => {
- val (code, value) = config
- ApiResponseHelpers.ok(models.RuntimeConfigs.set(code, value))
- }
- )
-
+ def createOrUpdate = securedJsonRequest(atc) { json => implicit request =>
+ deserialize[models.RuntimeConfig](json) { config =>
+ ApiResponseHelpers.ok(models.RuntimeConfigs.set(config.code, config.value getOrElse ""))
+ }
}
- val configForm = Form (
- tuple(
- "code" -> nonEmptyText,
- "value" -> text
- )
- )
-
}
}
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment