-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dierk Koenig
committed
Oct 30, 2024
1 parent
024c688
commit 6ffcd77
Showing
6 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package rooms | ||
|
||
// Entität | ||
class Person { | ||
String firstName | ||
String lastName | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package rooms | ||
|
||
// Entität | ||
class Room { | ||
String name | ||
Integer capacity | ||
|