Slide 171
Slide 171 text
class DocumentDataModelProjection(ProcessApplication):
@singledispatchmethod
def policy(self, domain_event, process_event):
"""Default policy"""
@policy.register(Effective.EffectiveCreated)
def handle(self, event: Effective.EffectiveCreated, _):
with get_db() as db:
document = get_document_by_id(db, event.doc_id)
update_document(db, event.doc_id, DocumentUpdate(effective_count=document.effective_count + 1))
@policy.register(Effective.EffectiveMarked)
def handle(self, event: Effective.EffectiveMarked, _):
with get_db() as db:
document = get_document_by_id(db, event.doc_id)
update_document(db, event.doc_id, DocumentUpdate(effective_count=document.effective_count + 1))
@policy.register(Effective.EffectiveUnmarked)
def handle(self, event: Effective.EffectiveUnmarked, _):
with get_db() as db:
document = get_document_by_id(db, event.doc_id)
update_document(db, event.doc_id, DocumentUpdate(effective_count=document.effective_count - 1))