This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce mapper for CustomerEventRecord, extend producer to also sen…
…d REPLACE- and DELETE-Events.
- Loading branch information
Ralf Ueberfuhr
committed
Jun 27, 2024
1 parent
6fe01a5
commit 5fa738f
Showing
2 changed files
with
82 additions
and
13 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...e-provider/src/main/java/de/sample/schulung/accounts/kafka/CustomerEventRecordMapper.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package de.sample.schulung.accounts.kafka; | ||
|
||
import de.sample.schulung.accounts.domain.Customer; | ||
import de.sample.schulung.accounts.domain.Customer.CustomerState; | ||
import de.sample.schulung.accounts.domain.events.CustomerCreatedEvent; | ||
import de.sample.schulung.accounts.domain.events.CustomerDeletedEvent; | ||
import de.sample.schulung.accounts.domain.events.CustomerReplacedEvent; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CustomerEventRecordMapper { | ||
|
||
public String map(CustomerState state) { | ||
return switch (state) { | ||
case ACTIVE -> "active"; | ||
case LOCKED -> "locked"; | ||
case DISABLED -> "disabled"; | ||
}; | ||
} | ||
|
||
public CustomerRecord map(Customer customer) { | ||
return new CustomerRecord( | ||
customer.getName(), | ||
customer.getDateOfBirth(), | ||
this.map(customer.getState()) | ||
); | ||
} | ||
|
||
public CustomerEventRecord map(CustomerCreatedEvent event) { | ||
var customer = event.customer(); | ||
return new CustomerEventRecord( | ||
"created", | ||
customer.getUuid(), | ||
this.map(customer) | ||
); | ||
} | ||
|
||
public CustomerEventRecord map(CustomerReplacedEvent event) { | ||
var customer = event.customer(); | ||
return new CustomerEventRecord( | ||
"replaced", | ||
customer.getUuid(), | ||
this.map(customer) | ||
); | ||
} | ||
|
||
public CustomerEventRecord map(CustomerDeletedEvent event) { | ||
return new CustomerEventRecord( | ||
"deleted", | ||
event.uuid(), | ||
null | ||
); | ||
} | ||
|
||
} |
This file contains 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