Skip to content

Commit

Permalink
Merge branch 'dev' into RSWW-103-Transport-Reservation-Rollback---saga
Browse files Browse the repository at this point in the history
  • Loading branch information
Danzigerrr committed May 20, 2024
2 parents a8df82f + f385e04 commit 4bc9bff
Show file tree
Hide file tree
Showing 32 changed files with 543 additions and 89 deletions.
35 changes: 27 additions & 8 deletions api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,37 @@ eureka:
instance:
prefer-ip-address: true


logging:
level:
org:
springframework:
cloud:
gateway: TRACE
spring:
application:
name: api-gateway
cloud:
gateway:
globalcors:
cors-configurations:
"[/**]":
'[/**]':
allowed-origins:
- "*"
- '*'
allowed-origin-patterns:
- '*'
allowed-methods:
- "*"
"/**":
- '*'
'/**':
allowed-origin-patterns:
- "*"
- '*'
allowed-origins:
- '*'
allowed-headers:
- '*'
allowed-methods:
- "*"
- '*'
add-to-simple-url-handler-mapping: true
routes:
- id: hotel-service
uri: lb://hotel-service
Expand Down Expand Up @@ -54,11 +68,16 @@ spring:
uri: lb://reservation-service
predicates:
- Path=/reservations/**
filters:
- RemoveRequestHeader=Cookie
metadata:
cors:
allowedOrigins: '*'
allowedMethods: '*'
allowedHeaders: '*'
- id: payment-service
uri: lb://payment-service
predicates:
- Path=/payments/**
filters:
- RemoveRequestHeader=Cookie
default-filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.microarchitecturovisco.hotelservice.bootstrap.util;

import org.microarchitecturovisco.hotelservice.model.dto.HotelDto;
import org.microarchitecturovisco.hotelservice.model.dto.LocationDto;
import org.microarchitecturovisco.hotelservice.model.dto.RoomDto;
import org.microarchitecturovisco.hotelservice.model.dto.RoomReservationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.Duration;
Expand All @@ -13,7 +11,6 @@
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.UUID;
import java.util.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import lombok.RequiredArgsConstructor;
import org.microarchitecturovisco.hotelservice.controllers.reservations.CheckHotelAvailabilityRequest;
import org.microarchitecturovisco.hotelservice.controllers.reservations.CreateHotelReservationRequest;
import org.microarchitecturovisco.hotelservice.controllers.reservations.DeleteHotelReservationRequest;
import org.microarchitecturovisco.hotelservice.model.cqrs.commands.CreateRoomReservationCommand;
import org.microarchitecturovisco.hotelservice.model.cqrs.commands.DeleteRoomReservationCommand;
import org.microarchitecturovisco.hotelservice.model.dto.RoomReservationDto;
import org.microarchitecturovisco.hotelservice.model.dto.request.CheckHotelAvailabilityQueryRequestDto;
import org.microarchitecturovisco.hotelservice.model.dto.request.GetHotelDetailsRequestDto;
import org.microarchitecturovisco.hotelservice.model.dto.request.GetHotelsBySearchQueryRequestDto;
import org.microarchitecturovisco.hotelservice.model.dto.response.CheckHotelAvailabilityResponseDto;
Expand All @@ -23,6 +26,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;

@RestController()
@RequestMapping("/hotels")
Expand All @@ -35,21 +39,26 @@ public class HotelsController {
@RabbitListener(queues = "hotels.requests.hotelsBySearchQuery")
public String consumeGetHotelsRequest(String requestDtoJson) {

Logger logger = Logger.getLogger("getHotelsBySearchQuery");
logger.info("Request: " + requestDtoJson);

GetHotelsBySearchQueryRequestDto requestDto = JsonReader.readGetHotelsBySearchQueryRequestFromJson(requestDtoJson);
GetHotelsBySearchQueryResponseDto responseDto = hotelsService.GetHotelsBySearchQuery(requestDto);

System.out.println("Send hotels response size " + responseDto.getHotels().size());

logger.info("Response hotels size: " + responseDto.getHotels().size());

return JsonConverter.convertGetHotelsBySearchQueryResponseDto(responseDto);
}

@RabbitListener(queues = "hotels.requests.getHotelDetails")
public String consumeGetHotelDetails(String requestDtoJson) {

Logger logger = Logger.getLogger("getHotelDetails");

GetHotelDetailsRequestDto requestDto = JsonReader.readGetHotelDetailsRequestFromJson(requestDtoJson);
GetHotelDetailsResponseDto responseDto = hotelsService.getHotelDetails(requestDto);

logger.info("Response for hotel: " + responseDto.getHotelId() + " " + responseDto.getHotelName());

return JsonConverter.convertGetHotelDetailsResponseDto(responseDto);
}
Expand Down Expand Up @@ -87,10 +96,10 @@ public void consumeMessageCreateHotelReservation(String requestJson) {
UUID roomId = request.getRoomIds().get(i);

RoomReservationDto roomReservation = new RoomReservationDto();
roomReservation.setReservationId(request.getReservationId());
roomReservation.setDateFrom(request.getHotelTimeFrom());
roomReservation.setDateTo(request.getHotelTimeTo());
roomReservation.setHotelId(request.getHotelId());
roomReservation.setReservationId(createHotelReservationRequest.getId());
roomReservation.setDateFrom(createHotelReservationRequest.getHotelTimeFrom());
roomReservation.setDateTo(createHotelReservationRequest.getHotelTimeTo());
roomReservation.setHotelId(createHotelReservationRequest.getHotelId());
roomReservation.setRoomId(roomId);

roomReservations.add(roomReservation);
Expand All @@ -107,5 +116,28 @@ public void consumeMessageCreateHotelReservation(String requestJson) {
System.out.println("roomReservation: " + roomReservation);
}
}

@RabbitListener(queues = "#{handleDeleteHotelReservationQueue.name}")
public void consumeMessageDeleteHotelReservation(DeleteHotelReservationRequest request) {
System.out.println("Message received from queue DeleteHotelReservationRequest: " + request);

// TODO: delete the reservation using fields in request:
// private UUID reservationId;
// private UUID hotelId;
// private List<UUID> roomIds;

for (UUID roomId : request.getRoomIds()){
DeleteRoomReservationCommand command = DeleteRoomReservationCommand.builder()
.commandTimeStamp(LocalDateTime.now())
.reservationId(request.getReservationId())
.roomId(roomId)
.hotelId(request.getHotelId())
.build();

hotelsCommandService.deleteReservation(command);
}


}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public class CheckHotelAvailabilityRequest implements Serializable {
private int amountOfQuests;

private UUID hotelId;

private List<UUID> roomReservationsIds;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.microarchitecturovisco.hotelservice.controllers.reservations;

import lombok.*;

import java.util.List;
import java.util.UUID;

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Getter
@Setter
public class DeleteHotelReservationRequest {
private UUID reservationId;
private UUID hotelId;
private List<UUID> roomIds;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.microarchitecturovisco.hotelservice.model.cqrs.commands;

import lombok.Builder;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.UUID;

@Data
@Builder
public class DeleteRoomReservationCommand {
private LocalDateTime commandTimeStamp;
private UUID reservationId;
private UUID roomId;
private UUID hotelId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.microarchitecturovisco.hotelservice.model.dto.request;

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

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CheckHotelAvailabilityQueryRequestDto implements Serializable {

private LocalDateTime dateFrom;
private LocalDateTime dateTo;

private Integer adults;
private Integer childrenUnderThree;
private Integer childrenUnderTen;
private Integer childrenUnderEighteen;

private UUID hotelId;

private List<UUID> roomReservationsIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.time.LocalDateTime;
Expand All @@ -26,4 +25,6 @@ public class GetHotelsBySearchQueryRequestDto implements Serializable {
private Integer childrenUnderThree;
private Integer childrenUnderTen;
private Integer childrenUnderEighteen;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.microarchitecturovisco.hotelservice.model.events;


import jakarta.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.util.UUID;

@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class RoomReservationDeletedEvent extends HotelEvent {
private UUID idRoomReservation;
private UUID idRoom;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.UUID;

@Configuration
public class QueuesConfig {
public static final String EXCHANGE_HOTEL = "hotels.requests.checkAvailabilityByQuery.exchange";
Expand All @@ -28,25 +30,46 @@ public Binding handleReservationRequestBinding(
return BindingBuilder.bind(handleReservationQueue).to(handleReservationExchange).with(QUEUE_HOTEL_CHECK_AVAILABILITY_REQ);
}

public static final String QUEUE_HOTEL_CREATE_RESERVATION_REQ = "hotels.events.createHotelReservation.queue";
public static final String EXCHANGE_HOTEL_FANOUT = "hotels.createReservation.exchange";
public static final String QUEUE_HOTEL_CREATE_RESERVATION_REQ_PREFIX = "hotels.events.createHotelReservation.queue.";
public static final String EXCHANGE_HOTEL_FANOUT_CREATE_RESERVATION = "hotels.createReservation.exchange";

@Bean
@Qualifier("fanoutExchange")
public FanoutExchange fanoutExchange() {
return new FanoutExchange(EXCHANGE_HOTEL_FANOUT);
@Bean(name="fanoutExchangeCreateHotelReservation")
public FanoutExchange fanoutExchangeCreateHotelReservation() {
return new FanoutExchange(EXCHANGE_HOTEL_FANOUT_CREATE_RESERVATION);
}

@Bean
@Qualifier("handleCreateHotelReservationQueue")
@Bean(name="handleCreateHotelReservationQueue")
public Queue handleCreateHotelReservationQueue() {
return new Queue(QUEUE_HOTEL_CREATE_RESERVATION_REQ, false, false, true);
String uniqueQueueName = QUEUE_HOTEL_CREATE_RESERVATION_REQ_PREFIX + UUID.randomUUID();
return new Queue(uniqueQueueName, false, false, true);
}

@Bean
public Binding handleCreateHotelReservationBinding(
@Qualifier("fanoutExchange") FanoutExchange fanoutExchange,
@Qualifier("fanoutExchangeCreateHotelReservation") FanoutExchange fanoutExchangeCreateHotelReservation,
@Qualifier("handleCreateHotelReservationQueue") Queue handleCreateHotelReservationQueue) {
return BindingBuilder.bind(handleCreateHotelReservationQueue).to(fanoutExchange);
return BindingBuilder.bind(handleCreateHotelReservationQueue).to(fanoutExchangeCreateHotelReservation);
}


public static final String QUEUE_HOTEL_DELETE_RESERVATION_REQ_PREFIX = "hotels.events.deleteHotelReservation.queue.";
public static final String EXCHANGE_HOTEL_FANOUT_DELETE_RESERVATION = "hotels.deleteReservation.exchange";

@Bean(name="fanoutExchangeDeleteHotelReservation")
public FanoutExchange fanoutExchangeDeleteHotelReservation() {
return new FanoutExchange(EXCHANGE_HOTEL_FANOUT_DELETE_RESERVATION);
}

@Bean(name="handleDeleteHotelReservationQueue")
public Queue handleDeleteHotelReservationQueue() {
String uniqueQueueName = QUEUE_HOTEL_DELETE_RESERVATION_REQ_PREFIX + UUID.randomUUID();
return new Queue(uniqueQueueName, false, false, true);
}

@Bean
public Binding handleDeleteHotelReservationBinding(
@Qualifier("fanoutExchangeDeleteHotelReservation") FanoutExchange fanoutExchangeDeleteHotelReservation,
@Qualifier("handleDeleteHotelReservationQueue") Queue handleDeleteHotelReservationQueue) {
return BindingBuilder.bind(handleDeleteHotelReservationQueue).to(fanoutExchangeDeleteHotelReservation);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.microarchitecturovisco.hotelservice.repositories;

import org.microarchitecturovisco.hotelservice.model.events.HotelEvent;
import org.microarchitecturovisco.hotelservice.model.events.RoomReservationCreatedEvent;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
import java.util.UUID;

public interface HotelEventStore extends JpaRepository<HotelEvent, UUID> {

}
Loading

0 comments on commit 4bc9bff

Please sign in to comment.