Skip to content

Instantly share code, notes, and snippets.

@bytekast
Created March 25, 2017 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bytekast/6420277ab301107daa13de5f59100754 to your computer and use it in GitHub Desktop.
Save bytekast/6420277ab301107daa13de5f59100754 to your computer and use it in GitHub Desktop.
@Component
@Log4j
@CompileStatic
class FindUsersByLastName implements Handler {
@Autowired
private UserRepository userRepository
@Override
boolean route(final Request request) {
request.resourcePath() == '/users/{lastName}' && request.httpMethod() == 'GET'
}
@Override
Response respond(final Request request) {
def customers = userRepository.findByLastName(request.pathParameter('lastName'))
Response.builder()
.statusCode(200)
.body(JsonOutput.prettyPrint(JsonOutput.toJson(customers)))
.build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment