order api + statistics
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -35,7 +35,7 @@
|
||||
<dependency>
|
||||
<groupId>de.infinimotion</groupId>
|
||||
<artifactId>model-backend</artifactId>
|
||||
<version>0.0.101</version>
|
||||
<version>0.0.110</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Quarkus -->
|
||||
|
||||
44
src/main/java/de/infinimotion/backend/endpoint/OrderTx.java
Normal file
44
src/main/java/de/infinimotion/backend/endpoint/OrderTx.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package de.infinimotion.backend.endpoint;
|
||||
|
||||
import de.infinimotion.model.backend.*;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@ApplicationScoped
|
||||
@Path("/order-transaction")
|
||||
public class OrderTx {
|
||||
|
||||
@Inject
|
||||
RequestReply requester;
|
||||
|
||||
@POST
|
||||
@Path("/create")
|
||||
public OrderTransaction createOrderTransaction(OrderTransaction orderTransaction) throws Exception {
|
||||
CommandWrapper orderRequest = new CommandCreateBestellung(orderTransaction.getOrder()).serialize().generateIds();
|
||||
Bestellung orderResponse = CommandCreateBestellungResponse.deserialize(requester.request(orderRequest)).getBestellung();
|
||||
|
||||
AtomicInteger countDown = new AtomicInteger(orderTransaction.getTickets().size());
|
||||
List<Eintrittskarte> ticketResponses = orderTransaction.getTickets().stream().map(ticket -> {
|
||||
try {
|
||||
ticket.setOrder(orderResponse);
|
||||
CommandWrapper ticketRequest = new CommandCreateEintrittskarte(ticket).serialize().tx(orderRequest);
|
||||
if (countDown.decrementAndGet() == 0) {
|
||||
ticketRequest.commit();
|
||||
}
|
||||
return CommandCreateEintrittskarteResponse.deserialize(requester.request(ticketRequest)).getEintrittskarte();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).toList();
|
||||
|
||||
orderTransaction.setOrder(orderResponse);
|
||||
orderTransaction.setTickets(ticketResponses);
|
||||
return orderTransaction;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,10 +15,27 @@ public class Statistics {
|
||||
|
||||
@GET
|
||||
@Path("/list")
|
||||
public CommandListStatisticsResponse list() throws Exception {
|
||||
public StatisticsReduced list() throws Exception {
|
||||
CommandListStatistics request = new CommandListStatistics();
|
||||
CommandWrapper requestWrapper = request.serialize().generateIds().commit();
|
||||
return CommandListStatisticsResponse.deserialize(requester.request(requestWrapper));
|
||||
CommandListStatisticsResponse response = CommandListStatisticsResponse.deserialize(requester.request(requestWrapper));
|
||||
|
||||
StatisticsReduced stats = new StatisticsReduced();
|
||||
stats.setMovies(response.getMovies().stream().map(movieStats -> {
|
||||
StatisticsFilmReduced reduced = new StatisticsFilmReduced();
|
||||
reduced.setMovie(movieStats.getMovie());
|
||||
reduced.setTickets(movieStats.getTickets().size());
|
||||
reduced.setEarnings(movieStats.getEarnings());
|
||||
return reduced;
|
||||
}).toList());
|
||||
stats.setShows(response.getShows().stream().map(showStats -> {
|
||||
StatisticsVorstellungReduced reduced = new StatisticsVorstellungReduced();
|
||||
reduced.setShow(showStats.getShow());
|
||||
reduced.setTickets(showStats.getTickets().size());
|
||||
reduced.setEarnings(showStats.getEarnings());
|
||||
return reduced;
|
||||
}).toList());
|
||||
return stats;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ mp.messaging.outgoing.command.connector=smallrye-kafka
|
||||
|
||||
mp.messaging.incoming.command-replies.connector=smallrye-kafka
|
||||
mp.messaging.incoming.command-replies.auto.offset.reset=earliest
|
||||
mp.messaging.incoming.command-replies.assign-seek=0
|
||||
|
||||
omdb.api-key=2a3264fc
|
||||
quarkus.rest-client.omdb-api.url=https://omdbapi.com/
|
||||
|
||||
Reference in New Issue
Block a user