Skip to content

Commit

Permalink
static scaffold PersonController
Browse files Browse the repository at this point in the history
  • Loading branch information
Dierk Koenig committed Oct 30, 2024
1 parent 024c688 commit 6ffcd77
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 3 deletions.
8 changes: 7 additions & 1 deletion grails-app/controllers/rooms/BookingController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package rooms

class BookingController {

static scaffold = Booking
static scaffold = Booking // dynamic scaffold

def play() {
Person dierk = Person.findByFirstName("Dierk")
String result = Booking.findAllByPerson(dierk).toString()
render text:result
}

}
94 changes: 93 additions & 1 deletion grails-app/controllers/rooms/PersonController.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,99 @@
package rooms

import grails.validation.ValidationException
import static org.springframework.http.HttpStatus.*

class PersonController {

static scaffold = Person
PersonService personService

static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]

def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
respond personService.list(params), model:[personCount: personService.count()]
}

def show(Long id) {
respond personService.get(id)
}

def create() {
respond new Person(params)
}

def save(Person person) {
if (person == null) {
notFound()
return
}

try {
personService.save(person)
} catch (ValidationException e) {
respond person.errors, view:'create'
return
}

request.withFormat {
form multipartForm {
flash.message = message(code: 'default.created.message', args: [message(code: 'person.label', default: 'Person'), person.id])
redirect person
}
'*' { respond person, [status: CREATED] }
}
}

def edit(Long id) {
respond personService.get(id)
}

def update(Person person) {
if (person == null) {
notFound()
return
}

try {
personService.save(person)
} catch (ValidationException e) {
respond person.errors, view:'edit'
return
}

request.withFormat {
form multipartForm {
flash.message = message(code: 'default.updated.message', args: [message(code: 'person.label', default: 'Person'), person.id])
redirect person
}
'*'{ respond person, [status: OK] }
}
}

def delete(Long id) {
if (id == null) {
notFound()
return
}

personService.delete(id)

request.withFormat {
form multipartForm {
flash.message = message(code: 'default.deleted.message', args: [message(code: 'person.label', default: 'Person'), 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: 'person.label', default: 'Person'), params.id])
redirect action: "index", method: "GET"
}
'*'{ render status: NOT_FOUND }
}
}
}
2 changes: 1 addition & 1 deletion grails-app/controllers/rooms/RoomController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package rooms

class RoomController {

static scaffold = Room
static scaffold = Room // dynamic scaffold



Expand Down
5 changes: 5 additions & 0 deletions grails-app/domain/rooms/Booking.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package rooms

// Relation
class Booking {
Person person
Room room
Date date
String timeSlot

String toString() {
return "Booking for " + person.toString() + " for room " + room.toString() + " at " + date.toString() + " " + timeSlot
}

static final AM = "08:15-11:00"
static final PM1 = "12:15-15:00"
static final PM2 = "15:15-18:00"
Expand Down
1 change: 1 addition & 0 deletions grails-app/domain/rooms/Person.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rooms

// Entität
class Person {
String firstName
String lastName
Expand Down
1 change: 1 addition & 0 deletions grails-app/domain/rooms/Room.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rooms

// Entität
class Room {
String name
Integer capacity
Expand Down

0 comments on commit 6ffcd77

Please sign in to comment.