Permalink
Browse files

#11 order response methods by HTTP status code

  • Loading branch information...
robfletcher
robfletcher committed Mar 13, 2013
1 parent 8a45e18 commit 4f31f7e4711edf46b24bd8c54e9c0dd37a55614a
Showing with 21 additions and 21 deletions.
  1. +21 −21 test/apps/gson-test/src/templates/scaffolding/Controller.groovy
@@ -87,33 +87,38 @@ class ${className}Controller {
render ${propertyName} as GSON
}
- private void respondCreated(${className} ${propertyName}) {
- response.status = SC_CREATED
- response.addHeader LOCATION, createLink(action: 'show', id: ${propertyName}.id)
- render ${propertyName} as GSON
- }
-
private void respondUpdated(${className} ${propertyName}) {
response.status = SC_OK
render ${propertyName} as GSON
}
- private void respondUnprocessableEntity(${className} ${propertyName}) {
+ private void respondDeleted(id) {
def responseBody = [:]
- responseBody.errors = ${propertyName}.errors.allErrors.collect {
- message(error: it)
- }
- response.status = SC_UNPROCESSABLE_ENTITY
+ responseBody.message = message(code: 'default.deleted.message', args: [message(code: '${domainClass.propertyName}.label', default: '${className}'), id])
+ response.status = SC_OK
render responseBody as GSON
}
+ private void respondCreated(${className} ${propertyName}) {
+ response.status = SC_CREATED
+ response.addHeader LOCATION, createLink(action: 'show', id: ${propertyName}.id)
+ render ${propertyName} as GSON
+ }
+
private void respondNotFound(id) {
def responseBody = [:]
responseBody.message = message(code: 'default.not.found.message', args: [message(code: '${domainClass.propertyName}.label', default: '${className}'), id])
response.status = SC_NOT_FOUND
render responseBody as GSON
}
+ private void respondNotAcceptable() {
+ response.status = SC_NOT_ACCEPTABLE
+ response.contentLength = 0
+ response.outputStream.flush()
+ response.outputStream.close()
+ }
+
private void respondConflict(${className} ${propertyName}) {
${propertyName}.errors.rejectValue('version', 'default.optimistic.locking.failure',
[message(code: '${domainClass.propertyName}.label', default: '${className}')] as Object[],
@@ -126,10 +131,12 @@ class ${className}Controller {
render responseBody as GSON
}
- private void respondDeleted(id) {
+ private void respondUnprocessableEntity(${className} ${propertyName}) {
def responseBody = [:]
- responseBody.message = message(code: 'default.deleted.message', args: [message(code: '${domainClass.propertyName}.label', default: '${className}'), id])
- response.status = SC_OK
+ responseBody.errors = ${propertyName}.errors.allErrors.collect {
+ message(error: it)
+ }
+ response.status = SC_UNPROCESSABLE_ENTITY
render responseBody as GSON
}
@@ -140,11 +147,4 @@ class ${className}Controller {
render responseBody as GSON
}
- private void respondNotAcceptable() {
- response.status = SC_NOT_ACCEPTABLE
- response.contentLength = 0
- response.outputStream.flush()
- response.outputStream.close()
- }
-
}

0 comments on commit 4f31f7e

Please sign in to comment.