Skip to content

Instantly share code, notes, and snippets.

@mox601
Last active August 29, 2015 14:07
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 mox601/cfdaca9d3f151e516639 to your computer and use it in GitHub Desktop.
Save mox601/cfdaca9d3f151e516639 to your computer and use it in GitHub Desktop.
ddd to view
//an event
// new ItemAdded("item-id-34", 45$, "2014-10-21-18:47:12")
//the handler
public class MonthlyCostsDenormalizer implements IHandle<ItemAddedToCart> {
private MonthlyCostsDao dao
public MonthlyCostsDenormalizer(MonthlyCostsDao dao) {
this.dao = dao;
}
public void handle(ItemAddedToCart) {
MonthlyCosts view = dao.getById(parseYearAndMonth(item.getHappenedAt()));
view.add(item.getCost());
repository.update(view);
}
private static String parseYearAndMonth(DateTime date) {
// for the example returns "2014-10"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment