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 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare Domain for Persistence Layer.
- Loading branch information
Ralf Ueberfuhr
committed
Jun 20, 2024
1 parent
c112f4b
commit 5a1ac28
Showing
5 changed files
with
111 additions
and
25 deletions.
There are no files selected for viewing
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
36 changes: 36 additions & 0 deletions
36
customer-api-provider/src/main/java/de/schulung/sample/quarkus/domain/CustomersSink.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,36 @@ | ||
package de.schulung.sample.quarkus.domain; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
public interface CustomersSink { | ||
|
||
Stream<Customer> findAll(); | ||
|
||
default Stream<Customer> findByState(Customer.CustomerState state) { | ||
return this | ||
.findAll() | ||
.filter(c -> c.getState() == state); | ||
} | ||
|
||
default Optional<Customer> findByUuid(UUID uuid) { | ||
return this | ||
.findAll() | ||
.filter(c -> c.getUuid().equals(uuid)) | ||
.findFirst(); | ||
} | ||
|
||
void save(Customer customer); | ||
|
||
boolean delete(UUID uuid); | ||
|
||
default boolean exists(UUID uuid) { | ||
return this | ||
.findByUuid(uuid) | ||
.isPresent(); | ||
} | ||
|
||
long count(); | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...i-provider/src/main/java/de/schulung/sample/quarkus/domain/CustomersSinkInMemoryImpl.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,52 @@ | ||
package de.schulung.sample.quarkus.domain; | ||
|
||
import io.quarkus.arc.DefaultBean; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Typed; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
@ApplicationScoped | ||
@Typed(CustomersSink.class) | ||
@DefaultBean | ||
public class CustomersSinkInMemoryImpl implements CustomersSink { | ||
|
||
private final Map<UUID, Customer> customers = new HashMap<>(); | ||
|
||
@Override | ||
public Stream<Customer> findAll() { | ||
return this.customers | ||
.values() | ||
.stream(); | ||
} | ||
|
||
@Override | ||
public Optional<Customer> findByUuid(UUID uuid) { | ||
return Optional.ofNullable(customers.get(uuid)); | ||
} | ||
|
||
@Override | ||
public void save(Customer customer) { | ||
customer.setUuid(UUID.randomUUID()); | ||
customers.put(customer.getUuid(), customer); | ||
} | ||
|
||
@Override | ||
public boolean delete(UUID uuid) { | ||
return customers.remove(uuid) != null; | ||
} | ||
|
||
@Override | ||
public boolean exists(UUID uuid) { | ||
return customers.containsKey(uuid); | ||
} | ||
|
||
@Override | ||
public long count() { | ||
return customers.size(); | ||
} | ||
} |
11 changes: 5 additions & 6 deletions
11
...r-api-provider/src/test/java/de/schulung/sample/quarkus/domain/CustomersServiceTests.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