Created
November 6, 2014 10:20
-
-
Save jbrisbin/29a0b2caee4fa5e9ab20 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
@Bean | |
public Action<Chain> handlers(PersonRepository persons, | |
HotStream<Person> personStream, | |
ObjectMapper jsonMapper, | |
ModelMapper beanMapper) { | |
return (chain) -> { | |
chain.handler("person", ctx -> | |
ctx.byMethod(spec -> | |
spec | |
.get(c -> { | |
c.render(Streams.just("") | |
.dispatchOn(get()) | |
.map(o -> persons.findAll())); | |
}) | |
.put(c -> { | |
Person p = c.parse(fromJson(Person.class)); | |
c.render(Streams.just(p.getId()) | |
.dispatchOn(get()) | |
.<Person>map(persons::findOne) | |
.observe(pers -> beanMapper.map(p, pers)) | |
.map(persons::save)); | |
}) | |
.post(c -> { | |
Person p = c.parse(fromJson(Person.class)); | |
c.render(Streams.just(p) | |
.dispatchOn(get()) | |
.map(persons::save) | |
.observe(personStream::broadcastNext)); | |
}) | |
)); | |
chain.handler("person/updates", ctx -> websocketBroadcast(ctx, personStream.map(p -> p.toJson(jsonMapper)))); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment