-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RSWW-136 transport get data from data generator #64
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import org.microarchitecturovisco.transport.model.dto.LocationDto; | ||
import org.microarchitecturovisco.transport.model.dto.TransportDto; | ||
import org.microarchitecturovisco.transport.model.dto.TransportReservationDto; | ||
import org.microarchitecturovisco.transport.model.dto.data_generator.TransportUpdateRequest; | ||
import org.microarchitecturovisco.transport.model.dto.request.*; | ||
import org.microarchitecturovisco.transport.model.dto.response.AvailableTransportsDto; | ||
import org.microarchitecturovisco.transport.model.dto.response.CheckTransportAvailabilityResponseDto; | ||
|
@@ -32,6 +33,8 @@ | |
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.logging.Logger; | ||
import org.microarchitecturovisco.transport.model.dto.data_generator.DataUpdateType; | ||
|
||
|
||
@RestController() | ||
@RequestMapping("/transports") | ||
|
@@ -201,4 +204,35 @@ public void consumeMessageDeleteTransportReservation(String requestJson) { | |
transportCommandService.deleteReservation(command); | ||
} | ||
} | ||
|
||
@RabbitListener(queues = "#{handleDataGeneratorCreateQueue}") | ||
public void consumeDataGeneratorMessage(String requestJson) { | ||
Logger logger = Logger.getLogger("TransportController"); | ||
logger.info("Got transport data generator: " + requestJson); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. przekopiowane z hoteli bez patrzenia, tam jeszcze na to pozwoliłem ale ten frazes moim zdaniem do zmiany |
||
|
||
TransportUpdateRequest request = JsonReader.readDtoFromJson(requestJson, TransportUpdateRequest.class); | ||
|
||
// create transport | ||
if (request.getUpdateType() == DataUpdateType.CREATE) { | ||
System.out.println("Created transport: " + request); | ||
CzajaLukasz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
transportsQueryService.createTransport(request.getId(), request.getCourseId(), request.getDepartureDate(), | ||
request.getCapacity(), request.getPricePerAdult()); | ||
return; | ||
} | ||
|
||
Transport transport = null; | ||
transport = transportsQueryService.getTransportById(request.getId()); | ||
CzajaLukasz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (transport == null) | ||
{ | ||
return; | ||
} | ||
// update transport | ||
if (request.getUpdateType() == DataUpdateType.UPDATE) { | ||
System.out.println("Updated transport: " + request); | ||
CzajaLukasz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
transportsQueryService.updateTransport(request.getId(), request.getCapacity(), request.getPricePerAdult()); | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.microarchitecturovisco.transport.model.dto.data_generator; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum DataUpdateType { | ||
CREATE("CREATE"), | ||
UPDATE("UPDATE"); | ||
|
||
private final String value; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.microarchitecturovisco.transport.model.dto.data_generator; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
|
||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class TransportUpdateRequest { | ||
|
||
private DataUpdateType updateType; | ||
|
||
private UUID id; | ||
|
||
private UUID courseId; | ||
|
||
private UUID courseLocationFromId; | ||
private UUID courseLocationToId; | ||
|
||
private LocalDateTime departureDate; | ||
|
||
private int capacity; | ||
|
||
private float pricePerAdult; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.microarchitecturovisco.transport.model.events; | ||
|
||
|
||
|
||
import jakarta.persistence.Entity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
|
||
|
||
@Entity | ||
@NoArgsConstructor | ||
@SuperBuilder | ||
@Getter | ||
@Setter | ||
public class TransportOnlyCreatedEvent extends TransportEvent { | ||
private UUID courseId; | ||
private LocalDateTime departureDate; | ||
private int capacity; | ||
private float pricePerAdult; | ||
|
||
public TransportOnlyCreatedEvent(UUID transportId, UUID courseId, LocalDateTime departureDate, int capacity, | ||
float pricePerAdult) { | ||
this.setIdTransport(transportId); | ||
this.setEventTimeStamp(LocalDateTime.now()); | ||
this.courseId = courseId; | ||
this.departureDate = departureDate; | ||
this.capacity = capacity; | ||
this.pricePerAdult = pricePerAdult; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.microarchitecturovisco.transport.model.events; | ||
|
||
import jakarta.persistence.Entity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
|
||
|
||
@Entity | ||
@NoArgsConstructor | ||
@SuperBuilder | ||
@Getter | ||
@Setter | ||
public class TransportUpdateEvent extends TransportEvent { | ||
private int capacity; | ||
private float pricePerAdult; | ||
|
||
public TransportUpdateEvent(UUID transportId, int capacity, float pricePerAdult){ | ||
this.setEventTimeStamp(LocalDateTime.now()); | ||
this.setIdTransport(transportId); | ||
this.capacity = capacity; | ||
this.pricePerAdult = pricePerAdult; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.microarchitecturovisco.transport.queues.config; | ||
|
||
|
||
import org.springframework.amqp.core.BindingBuilder; | ||
import org.springframework.amqp.core.FanoutExchange; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import org.springframework.amqp.core.Queue; | ||
import org.springframework.amqp.core.Binding; | ||
import java.util.UUID; | ||
|
||
@Configuration | ||
public class DataGeneratorExchangeConfig { | ||
|
||
public static final String EXCHANGE_DATA_GENERATOR = "data.generate.transports.exchange"; | ||
|
||
@Bean | ||
public FanoutExchange handleDataGeneratorExchange() { | ||
return new FanoutExchange(EXCHANGE_DATA_GENERATOR); | ||
} | ||
|
||
@Bean | ||
public Queue handleDataGeneratorCreateQueue() { | ||
String uniqueQueueName = "data.generate.transports.queue" + UUID.randomUUID(); | ||
return new Queue(uniqueQueueName, false, false, false); | ||
} | ||
|
||
@Bean | ||
public Binding handleDataGeneratorBinding( | ||
FanoutExchange handleDataGeneratorExchange, | ||
Queue handleDataGeneratorCreateQueue) { | ||
return BindingBuilder.bind(handleDataGeneratorCreateQueue).to(handleDataGeneratorExchange); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,24 @@ | |
import lombok.RequiredArgsConstructor; | ||
import org.microarchitecturovisco.transport.model.domain.*; | ||
import org.microarchitecturovisco.transport.model.dto.TransportDto; | ||
import org.microarchitecturovisco.transport.model.dto.data_generator.DataUpdateType; | ||
import org.microarchitecturovisco.transport.model.dto.request.GetTransportsBetweenLocationsRequestDto; | ||
import org.microarchitecturovisco.transport.model.dto.request.GetTransportsBetweenMultipleLocationsRequestDto; | ||
import org.microarchitecturovisco.transport.model.dto.request.GetTransportsBySearchQueryRequestDto; | ||
import org.microarchitecturovisco.transport.model.dto.response.AvailableTransportsDepartures; | ||
import org.microarchitecturovisco.transport.model.dto.response.AvailableTransportsDto; | ||
import org.microarchitecturovisco.transport.model.dto.response.GetTransportsBetweenLocationsResponseDto; | ||
import org.microarchitecturovisco.transport.model.dto.response.GetTransportsBySearchQueryResponseDto; | ||
import org.microarchitecturovisco.transport.model.events.TransportCreatedEvent; | ||
import org.microarchitecturovisco.transport.model.events.TransportOnlyCreatedEvent; | ||
import org.microarchitecturovisco.transport.model.events.TransportUpdateEvent; | ||
import org.microarchitecturovisco.transport.model.mappers.LocationMapper; | ||
import org.microarchitecturovisco.transport.model.mappers.TransportMapper; | ||
import org.microarchitecturovisco.transport.repositories.LocationRepository; | ||
import org.microarchitecturovisco.transport.repositories.TransportCourseRepository; | ||
import org.microarchitecturovisco.transport.repositories.TransportEventStore; | ||
import org.microarchitecturovisco.transport.repositories.TransportRepository; | ||
import org.springframework.cglib.core.Local; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
|
@@ -30,6 +36,8 @@ public class TransportsQueryService { | |
private final TransportCourseRepository transportCourseRepository; | ||
private final TransportRepository transportRepository; | ||
private final LocationRepository locationRepository; | ||
private final TransportEventSourcingHandler transportEventSourcingHandler; | ||
private final TransportEventStore transportEventStore; | ||
|
||
public List<TransportDto> getAllTransports() { | ||
List<Transport> transports = transportRepository.findAll(); | ||
|
@@ -265,6 +273,19 @@ public Integer getTransportOccupiedSeats(Transport transport) { | |
.sum(); | ||
} | ||
|
||
public void updateTransport(UUID transportId, int capacity, float pricePerAdult) { | ||
TransportUpdateEvent transportUpdateEvent = new TransportUpdateEvent(transportId, capacity, pricePerAdult); | ||
transportEventStore.save(transportUpdateEvent); | ||
transportEventSourcingHandler.project(List.of(transportUpdateEvent)); | ||
} | ||
|
||
public void createTransport(UUID transportId, UUID courseId, LocalDateTime departureDate, int capacity, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ta funkcja istniała wcześniej w
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i albo korzystamy z |
||
float pricePerAdult) { | ||
|
||
TransportOnlyCreatedEvent transportOnlyCreatedEvent = new TransportOnlyCreatedEvent(transportId, | ||
courseId, departureDate, capacity, pricePerAdult); | ||
transportEventStore.save(transportOnlyCreatedEvent); | ||
transportEventSourcingHandler.project(List.of(transportOnlyCreatedEvent)); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plik nazywa się TransportQueryController więc nie powinno tu być logiki tworzenia ani aktualizacji