Skip to content

Instantly share code, notes, and snippets.

@recursivecodes
Last active April 17, 2019 19:49
Show Gist options
  • Select an option

  • Save recursivecodes/ee98ecaabad10b1a377aad11701d6993 to your computer and use it in GitHub Desktop.

Select an option

Save recursivecodes/ee98ecaabad10b1a377aad11701d6993 to your computer and use it in GitHub Desktop.
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