Skip to content

Commit

Permalink
Merge pull request #59 from Microarchitecturovisco/RSWW-140-Fix-sched…
Browse files Browse the repository at this point in the history
…uled-deletion-of-reservation

Rsww 140 fix scheduled deletion of reservation
  • Loading branch information
pcichowski authored Jun 9, 2024
2 parents fb2290f + 2af9462 commit 5282eff
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ public void updateHotelDataInHotelModules(DataUpdateType updateType, Room room)
}

private void updateHotelUpdatesOnFrontend(DataUpdateType updateType, String roomName, String hotelName, int capacityChange, float priceChange) {
LocalDateTime currentDateAndTime = LocalDateTime.now().withSecond(0).withNano(0);
LocalDateTime currentDateAndTime = LocalDateTime.now().withNano(0);

HotelUpdate hotelUpdate = HotelUpdate.builder()
.updateDateTime(currentDateAndTime)
.updateDateTime(currentDateAndTime.toString())
.updateType(String.valueOf(updateType))
.hotelName(hotelName)
.roomName(roomName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void updateTransportDataInTransportModules(DataUpdateType updateType, Tra
}

private void updateTransportUpdatesOnFrontend(DataUpdateType updateType, Transport transport, int capacityChange, float priceChange) {
LocalDateTime currentDateAndTime = LocalDateTime.now().withSecond(0).withNano(0);
LocalDateTime currentDateAndTime = LocalDateTime.now().withNano(0);

String departureRegion = transport.getCourse().getDepartureFrom().getRegion();
String departureCountry = transport.getCourse().getDepartureFrom().getCountry();
Expand All @@ -121,7 +121,7 @@ private void updateTransportUpdatesOnFrontend(DataUpdateType updateType, Transpo
String transportTypeName = transport.getCourse().getType().toString();

TransportUpdate transportUpdate = TransportUpdate.builder()
.updateDateTime(currentDateAndTime)
.updateDateTime(currentDateAndTime.toString())
.updateType(String.valueOf(updateType))
.departureRegionAndCountry(departureRegion + ", " + departureCountry)
.arrivalRegionAndCountry(arrivalRegion + ", " + arrivalCountry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class HotelUpdate implements Serializable {
private LocalDateTime updateDateTime;
private String updateDateTime;
private String updateType;
private String hotelName;
private String roomName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class TransportUpdate implements Serializable {
private LocalDateTime updateDateTime;
private String updateDateTime;
private String updateType;
private String departureRegionAndCountry;
private String arrivalRegionAndCountry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.microarchitecturovisco.reservationservice.controllers;

import lombok.RequiredArgsConstructor;
import org.microarchitecturovisco.reservationservice.domain.commands.DeleteReservationCommand;
import org.microarchitecturovisco.reservationservice.domain.commands.UpdateReservationCommand;
import org.microarchitecturovisco.reservationservice.domain.dto.ReservationPreference;
import org.microarchitecturovisco.reservationservice.domain.dto.requests.ReservationRequest;
import org.microarchitecturovisco.reservationservice.domain.dto.requests.UpdateReservationPaymentStatus;
import org.microarchitecturovisco.reservationservice.domain.entity.Reservation;
import org.microarchitecturovisco.reservationservice.domain.exceptions.ReservationFailException;
import org.microarchitecturovisco.reservationservice.domain.model.PurchaseRequestBody;
import org.microarchitecturovisco.reservationservice.domain.model.ReservationConfirmationResponse;
import org.microarchitecturovisco.reservationservice.services.ReservationAggregate;
import org.microarchitecturovisco.reservationservice.services.ReservationService;
import org.microarchitecturovisco.reservationservice.utils.json.JsonReader;
import org.microarchitecturovisco.reservationservice.websockets.ReservationWebSocketHandlerPreferences;
Expand All @@ -18,7 +22,9 @@

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;

@RestController
@RequiredArgsConstructor
Expand All @@ -27,11 +33,13 @@ public class ReservationController {

private final ReservationService reservationService;
private final ReservationWebSocketHandlerPreferences reservationWebSocketHandlerPreferences;
private final ReservationAggregate reservationAggregate;
public static Logger logger = Logger.getLogger(ReservationController.class.getName());

@PostMapping("/reservation")
public String addReservation(@RequestBody ReservationRequest reservationRequest) {
try {
System.out.println("RESERVATION REQUEST:" + reservationRequest.toString());
logger.info("RESERVATION REQUEST:" + reservationRequest.toString());
UUID reservationId = reservationService.bookOrchestration(reservationRequest);
return "Reservation with id " + reservationId.toString() + " created successfully!";
} catch (ReservationFailException exception) {
Expand Down Expand Up @@ -65,7 +73,7 @@ public void consumeMessageCreateReservation(String reservationRequestJson) {
reservationRequest.getUserId(),
reservationRequest.getId()
);
System.out.println("Reservation in Reservation module created successfully: " + reservation.getId());
logger.info("Reservation in Reservation module created successfully: " + reservation.getId());
}

private void updateBookingPreferences(ReservationRequest reservationRequest) {
Expand All @@ -87,4 +95,62 @@ private String getCurrentTime(){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return now.format(formatter);
}

@RabbitListener(queues = "#{handleReservationDeleteQueue.name}")
public void consumeMessageDeleteReservation(String reservationRequestJson) {

ReservationRequest reservationRequest = JsonReader.readDtoFromJson(reservationRequestJson, ReservationRequest.class);

deleteReservation(
reservationRequest.getHotelTimeFrom(),
reservationRequest.getHotelTimeTo(),
reservationRequest.getChildrenUnder3Quantity(),
reservationRequest.getChildrenUnder10Quantity(),
reservationRequest.getChildrenUnder18Quantity(),
reservationRequest.getAdultsQuantity(),
reservationRequest.getPrice(),
reservationRequest.getHotelId(),
reservationRequest.getRoomReservationsIds(),
reservationRequest.getTransportReservationsIds(),
reservationRequest.getUserId(),
reservationRequest.getId()
);

logger.info("Reservation in Reservation module deleted successfully");
}

private void deleteReservation(LocalDateTime hotelTimeFrom, LocalDateTime hotelTimeTo,
int infantsQuantity, int kidsQuantity, int teensQuantity, int adultsQuantity,
float price, UUID hotelId, List<UUID> roomReservationsIds,
List<UUID> transportReservationsIds, UUID userId, UUID reservationId) {

DeleteReservationCommand command = DeleteReservationCommand.builder()
.id(reservationId)
.hotelTimeFrom(hotelTimeFrom)
.hotelTimeTo(hotelTimeTo)
.infantsQuantity(infantsQuantity)
.kidsQuantity(kidsQuantity)
.teensQuantity(teensQuantity)
.adultsQuantity(adultsQuantity)
.price(price)
.paid(false)
.hotelId(hotelId)
.roomReservationsIds(roomReservationsIds)
.transportReservationsIds(transportReservationsIds)
.userId(userId)
.build();
reservationAggregate.handleDeleteReservationCommand(command);
}


@RabbitListener(queues = "#{handleReservationUpdateQueue.name}")
public void consumeMessageUpdateReservationPaymentStatus(String reservationPaymentStatusJson) {
UpdateReservationPaymentStatus reservationPaymentStatus = JsonReader.readDtoFromJson(reservationPaymentStatusJson, UpdateReservationPaymentStatus.class);
UUID reservationId = reservationPaymentStatus.getReservationId();

reservationAggregate.handleReservationUpdateCommand(UpdateReservationCommand.builder().reservationId(reservationId).paid(true).build());

logger.info("Reservation in Reservation module updated successfully");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.microarchitecturovisco.reservationservice.domain.dto.requests;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.UUID;

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateReservationPaymentStatus implements Serializable {
private UUID reservationId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
@Configuration
public class QueuesReservationConfig {

public static final String EXCHANGE_RESERVATION = "reservations.events.createReservation.exchange";
public static final String EXCHANGE_CREATE_RESERVATION = "reservations.events.createReservation.exchange";

@Bean
public FanoutExchange handleReservationCreateExchange() {
return new FanoutExchange(EXCHANGE_RESERVATION);
return new FanoutExchange(EXCHANGE_CREATE_RESERVATION);
}

@Bean
Expand All @@ -31,4 +31,46 @@ public Binding handleReservationCreateRequestBinding(
Queue handleReservationCreateQueue) {
return BindingBuilder.bind(handleReservationCreateQueue).to(handleReservationCreateExchange);
}


public static final String EXCHANGE_DELETE_RESERVATION = "reservations.events.deleteReservation.exchange";

@Bean
public FanoutExchange handleReservationDeleteExchange() {
return new FanoutExchange(EXCHANGE_DELETE_RESERVATION);
}

@Bean
public Queue handleReservationDeleteQueue() {
String uniqueQueueName = "reservations.events.deleteReservation.queue." + UUID.randomUUID();
return new Queue(uniqueQueueName, false, false, true);
}

@Bean
public Binding handleReservationDeleteRequestBinding(
FanoutExchange handleReservationDeleteExchange,
Queue handleReservationDeleteQueue) {
return BindingBuilder.bind(handleReservationDeleteQueue).to(handleReservationDeleteExchange);
}


public static final String EXCHANGE_UPDATE_RESERVATION = "reservations.events.updateReservation.exchange";

@Bean
public FanoutExchange handleReservationUpdateExchange() {
return new FanoutExchange(EXCHANGE_UPDATE_RESERVATION);
}

@Bean
public Queue handleReservationUpdateQueue() {
String uniqueQueueName = "reservations.events.updateReservation.queue." + UUID.randomUUID();
return new Queue(uniqueQueueName, false, false, true);
}

@Bean
public Binding handleReservationUpdateRequestBinding(
FanoutExchange handleReservationUpdateExchange,
Queue handleReservationUpdateQueue) {
return BindingBuilder.bind(handleReservationUpdateQueue).to(handleReservationUpdateExchange);
}
}
Loading

0 comments on commit 5282eff

Please sign in to comment.