Skip to content

Commit a24ff8c

Browse files
committed
Consolidate shared code
1 parent 4a4f6b3 commit a24ff8c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

persistence/src/main/scala/hmda/persistence/institutions/FilingPersistence.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ class FilingPersistence(institutionId: String) extends HmdaPersistentActor {
4949
override def receiveCommand: Receive = super.receiveCommand orElse {
5050
case CreateFiling(f) =>
5151
if (!state.filings.map(_.period).contains(f.period)) {
52-
persist(FilingCreated(f)) { e =>
53-
log.debug(s"Persisted: $f")
54-
updateState(e)
55-
sender() ! Some(f)
56-
}
52+
persistFilingEvent(FilingCreated(f), f)
5753
} else {
5854
sender() ! None
5955
log.warning(s"Could not create Filing. Filing period ${f.period} already exists for institution $institutionId.")
@@ -65,11 +61,7 @@ class FilingPersistence(institutionId: String) extends HmdaPersistentActor {
6561
val startTime = if (newStatus == InProgress) System.currentTimeMillis else filing.start
6662
val endTime = if (newStatus == Completed) System.currentTimeMillis else filing.end
6763
val updatedFiling = filing.copy(status = newStatus, start = startTime, end = endTime)
68-
persist(FilingStatusUpdated(updatedFiling)) { e =>
69-
log.debug(s"persisted: $updatedFiling")
70-
updateState(e)
71-
sender() ! Some(updatedFiling)
72-
}
64+
persistFilingEvent(FilingStatusUpdated(updatedFiling), updatedFiling)
7365
case None =>
7466
sender() ! None
7567
log.warning(s"Could not update filing status. Institution $institutionId, filing period $period")
@@ -87,4 +79,12 @@ class FilingPersistence(institutionId: String) extends HmdaPersistentActor {
8779
sender() ! state.filings
8880

8981
}
82+
83+
private def persistFilingEvent(event: Event, filing: Filing) = {
84+
persist(event) { e =>
85+
log.debug(s"persisted: $filing")
86+
updateState(e)
87+
sender() ! Some(filing)
88+
}
89+
}
9090
}

0 commit comments

Comments
 (0)