-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RSWW-56 transport-service: create event store
Signed-off-by: Paweł Cichowski <[email protected]>
- Loading branch information
1 parent
b9c8b91
commit 4901d2a
Showing
12 changed files
with
163 additions
and
39 deletions.
There are no files selected for viewing
26 changes: 0 additions & 26 deletions
26
...n/java/org/microarchitecturovisco/transport/model/cqrs/aggregates/TransportAggregate.java
This file was deleted.
Oops, something went wrong.
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
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
11 changes: 0 additions & 11 deletions
11
...java/org/microarchitecturovisco/transport/model/cqrs/projections/TransportProjection.java
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...rc/main/java/org/microarchitecturovisco/transport/model/events/TransportCreatedEvent.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,14 @@ | ||
package org.microarchitecturovisco.transport.model.events; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Builder; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Entity | ||
@Table(name = "transport_created_events") | ||
@RequiredArgsConstructor | ||
@Builder | ||
public class TransportCreatedEvent extends TransportEvent { | ||
|
||
// TODO | ||
} |
28 changes: 28 additions & 0 deletions
28
...rvice/src/main/java/org/microarchitecturovisco/transport/model/events/TransportEvent.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,28 @@ | ||
package org.microarchitecturovisco.transport.model.events; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@RequiredArgsConstructor | ||
@Entity | ||
public abstract class TransportEvent { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private int id; | ||
|
||
private LocalDateTime eventTimeStamp; | ||
|
||
private UUID idTransport; | ||
} |
17 changes: 17 additions & 0 deletions
17
...a/org/microarchitecturovisco/transport/model/events/TransportReservationCreatedEvent.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,17 @@ | ||
package org.microarchitecturovisco.transport.model.events; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Entity | ||
@Table(name = "transports_reservation_created_events") | ||
@Builder | ||
@Getter | ||
@Setter | ||
@RequiredArgsConstructor | ||
public class TransportReservationCreatedEvent extends TransportEvent { | ||
|
||
private int idTransportReservation; | ||
private int numberOfSeats; | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
.../src/main/java/org/microarchitecturovisco/transport/repositories/TransportEventStore.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,11 @@ | ||
package org.microarchitecturovisco.transport.repositories; | ||
|
||
import org.microarchitecturovisco.transport.model.events.TransportEvent; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public interface TransportEventStore extends JpaRepository<TransportEvent, Integer> { | ||
List<TransportEvent> findTransportEventsByIdTransport(UUID idTransport); | ||
} |
7 changes: 7 additions & 0 deletions
7
...ava/org/microarchitecturovisco/transport/repositories/TransportReservationRepository.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,7 @@ | ||
package org.microarchitecturovisco.transport.repositories; | ||
|
||
import org.microarchitecturovisco.transport.model.domain.TransportReservation; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface TransportReservationRepository extends JpaRepository<TransportReservation, Integer> { | ||
} |
18 changes: 18 additions & 0 deletions
18
.../src/main/java/org/microarchitecturovisco/transport/services/TransportCommandService.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,18 @@ | ||
package org.microarchitecturovisco.transport.services; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class TransportCommandService { | ||
|
||
private final TransportEventSourcingHandler transportEventSourcingHandler; | ||
|
||
public void save(UUID idTransport) { | ||
transportEventSourcingHandler.project(idTransport); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...ain/java/org/microarchitecturovisco/transport/services/TransportEventSourcingHandler.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,53 @@ | ||
package org.microarchitecturovisco.transport.services; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import org.microarchitecturovisco.transport.model.domain.Transport; | ||
import org.microarchitecturovisco.transport.model.domain.TransportReservation; | ||
import org.microarchitecturovisco.transport.model.events.TransportCreatedEvent; | ||
import org.microarchitecturovisco.transport.model.events.TransportEvent; | ||
import org.microarchitecturovisco.transport.model.events.TransportReservationCreatedEvent; | ||
import org.microarchitecturovisco.transport.repositories.TransportEventStore; | ||
import org.microarchitecturovisco.transport.repositories.TransportRepository; | ||
import org.microarchitecturovisco.transport.repositories.TransportReservationRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class TransportEventSourcingHandler { | ||
|
||
private final TransportEventStore eventStore; | ||
|
||
private final TransportRepository transportRepository; | ||
private final TransportReservationRepository transportReservationRepository; | ||
|
||
public void project(UUID idTransport) { | ||
List<TransportEvent> events = eventStore.findTransportEventsByIdTransport(idTransport); | ||
|
||
Transport transport = new Transport(); | ||
|
||
for (TransportEvent event : events) { | ||
if (event instanceof TransportCreatedEvent) { | ||
// TODO | ||
} | ||
if (event instanceof TransportReservationCreatedEvent) { | ||
apply((TransportReservationCreatedEvent) event, transport); | ||
} | ||
} | ||
} | ||
|
||
private void apply(TransportReservationCreatedEvent event, Transport transport) { | ||
TransportReservation transportReservation = TransportReservation.builder() | ||
.id(event.getIdTransportReservation()) | ||
.numberOfSeats(event.getNumberOfSeats()) | ||
.transport(transport) | ||
.build(); | ||
transport.getTransportReservations().add(transportReservation); | ||
|
||
transportReservationRepository.save(transportReservation); | ||
transportRepository.save(transport); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ce/src/main/java/org/microarchitecturovisco/transport/services/TransportQueryService.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,13 @@ | ||
package org.microarchitecturovisco.transport.services; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.microarchitecturovisco.transport.model.domain.Transport; | ||
import org.microarchitecturovisco.transport.repositories.TransportRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class TransportQueryService { | ||
|
||
// TODO | ||
} |