Created
November 6, 2014 10:20
-
-
Save jbrisbin/29a0b2caee4fa5e9ab20 to your computer and use it in GitHub Desktop.
Revisions
-
jbrisbin created this gist
Nov 6, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ @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)))); }; }