Last active
April 17, 2019 19:49
-
-
Save recursivecodes/ee98ecaabad10b1a377aad11701d6993 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package codes.recursive | |
| import codes.recursive.model.Person | |
| import codes.recursive.service.PersonService | |
| import groovy.transform.CompileStatic | |
| import io.micronaut.http.HttpResponse | |
| import io.micronaut.http.HttpStatus | |
| import io.micronaut.http.annotation.Body | |
| import io.micronaut.http.annotation.Controller | |
| import io.micronaut.http.annotation.Get | |
| import io.micronaut.http.annotation.Post | |
| import org.grails.datastore.mapping.validation.ValidationException | |
| import javax.inject.Inject | |
| @CompileStatic | |
| @Controller("/test") | |
| class TestController { | |
| @Inject PersonService personService | |
| @Get("/") | |
| HttpResponse index() { | |
| return HttpResponse.status(HttpStatus.OK).body([awesome: true, javaVersion: System.getProperty("java.version")]) | |
| } | |
| @Get("/persons") | |
| List<Person> getPersons() { | |
| return personService.findAll() | |
| } | |
| @Get("/person/{id}") | |
| Person getPerson(int id) { | |
| return personService.find(id) | |
| } | |
| @Post("/savePerson") | |
| Person savePerson(@Body Person person) { | |
| try { | |
| return personService.save(person) | |
| } | |
| catch(ValidationException e) { | |
| println e.errors.allErrors | |
| throw e | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment