| package functional.tests |
| |
| import grails.gorm.transactions.Transactional |
| import grails.neo4j.Neo4jEntity |
| import org.grails.datastore.gorm.GormEntity |
| |
| import static org.springframework.http.HttpStatus.* |
| |
| @Transactional(readOnly = true) |
| class AuthorController { |
| |
| static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"] |
| |
| def index(Integer max) { |
| params.max = Math.min(max ?: 10, 100) |
| respond Author.list(params), model:[authorCount: Author.count()] |
| } |
| |
| |
| def show(Author author) { |
| assert !(author instanceof Neo4jEntity) |
| assert author instanceof GormEntity |
| respond author |
| } |
| |
| def create() { |
| respond new Author(params) |
| } |
| |
| @Transactional |
| def save(Author author) { |
| if (author == null) { |
| transactionStatus.setRollbackOnly() |
| notFound() |
| return |
| } |
| |
| if (author.hasErrors()) { |
| transactionStatus.setRollbackOnly() |
| respond author.errors, view:'create' |
| return |
| } |
| |
| author.save flush:true |
| |
| request.withFormat { |
| form multipartForm { |
| flash.message = message(code: 'default.created.message', args: [message(code: 'author.label', default: 'Author'), author.id]) |
| redirect author |
| } |
| '*' { respond author, [status: CREATED] } |
| } |
| } |
| |
| def edit(Author author) { |
| respond author |
| } |
| |
| @Transactional |
| def update(Author author) { |
| if (author == null) { |
| transactionStatus.setRollbackOnly() |
| notFound() |
| return |
| } |
| |
| if (author.hasErrors()) { |
| transactionStatus.setRollbackOnly() |
| respond author.errors, view:'edit' |
| return |
| } |
| |
| author.save flush:true |
| |
| request.withFormat { |
| form multipartForm { |
| flash.message = message(code: 'default.updated.message', args: [message(code: 'author.label', default: 'Author'), author.id]) |
| redirect author |
| } |
| '*'{ respond author, [status: OK] } |
| } |
| } |
| |
| @Transactional |
| def delete(Author author) { |
| |
| if (author == null) { |
| transactionStatus.setRollbackOnly() |
| notFound() |
| return |
| } |
| |
| author.delete flush:true |
| |
| request.withFormat { |
| form multipartForm { |
| flash.message = message(code: 'default.deleted.message', args: [message(code: 'author.label', default: 'Author'), author.id]) |
| redirect action:"index", method:"GET" |
| } |
| '*'{ render status: NO_CONTENT } |
| } |
| } |
| |
| protected void notFound() { |
| request.withFormat { |
| form multipartForm { |
| flash.message = message(code: 'default.not.found.message', args: [message(code: 'author.label', default: 'Author'), params.id]) |
| redirect action: "index", method: "GET" |
| } |
| '*'{ render status: NOT_FOUND } |
| } |
| } |
| } |