Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package intern__grails
- import static org.springframework.http.HttpStatus.*
- import grails.transaction.Transactional
- import grails.converters.*
- @Transactional(readOnly = true)
- class DriverController {
- static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]
- def index(Integer max) {
- params.max = Math.min(max ?: 10, 100)
- respond Driver.list(params), model:[driverCount: Driver.count()]
- }
- def show(Driver driver) {
- respond driver
- }
- def create() {
- respond new Driver(params)
- }
- @Transactional
- def save(Driver driver) {
- if (driver == null) {
- transactionStatus.setRollbackOnly()
- notFound()
- return
- }
- if (driver.hasErrors()) {
- transactionStatus.setRollbackOnly()
- respond driver.errors, view:'create'
- return
- }
- driver.save flush:true
- request.withFormat {
- form multipartForm {
- flash.message = message(code: 'default.created.message', args: [message(code: 'driver.label', default: 'Driver'), driver.id])
- redirect driver
- }
- '*' { respond driver, [status: CREATED] }
- }
- }
- def edit(Driver driver) {
- respond driver
- }
- @Transactional
- def update(Driver driver) {
- if (driver == null) {
- transactionStatus.setRollbackOnly()
- notFound()
- return
- }
- if (driver.hasErrors()) {
- transactionStatus.setRollbackOnly()
- respond driver.errors, view:'edit'
- return
- }
- driver.save flush:true
- request.withFormat {
- form multipartForm {
- flash.message = message(code: 'default.updated.message', args: [message(code: 'driver.label', default: 'Driver'), driver.id])
- redirect driver
- }
- '*'{ respond driver, [status: OK] }
- }
- }
- @Transactional
- def delete(Driver driver) {
- if (driver == null) {
- transactionStatus.setRollbackOnly()
- notFound()
- return
- }
- driver.delete flush:true
- request.withFormat {
- form multipartForm {
- flash.message = message(code: 'default.deleted.message', args: [message(code: 'driver.label', default: 'Driver'), driver.id])
- redirect action:"index", method:"GET"
- }
- '*'{ render status: NO_CONTENT }
- }
- }
- def testFunc(){
- print("tes")
- }
- def list(Integer max){
- // render Driver.list() as JSON
- def drivers = Driver.withCriteria{
- maxResults params.int( 'max' ) ?: 10
- }
- render drivers as JSON
- }
- protected void notFound() {
- request.withFormat {
- form multipartForm {
- flash.message = message(code: 'default.not.found.message', args: [message(code: 'driver.label', default: 'Driver'), params.id])
- redirect action: "index", method: "GET"
- }
- '*'{ render status: NOT_FOUND }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement