Skip to content

Commit 06a0e58

Browse files
authored
Merge pull request #23 from meysamhadeli/feat/add-rest-client-for-all-endpoints
feat: add rest client for all endpoints
2 parents 79c025d + 228a599 commit 06a0e58

File tree

19 files changed

+504
-84
lines changed

19 files changed

+504
-84
lines changed

apigateway/src/main/resources/application-dev.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ spring:
1717
- Path=/api/{version}/flight/**
1818
filters:
1919
- TokenRelay
20+
- id: passenger-service
21+
uri: http://localhost:8083
22+
predicates:
23+
- Path=/api/{version}/passenger/**
24+
filters:
25+
- TokenRelay
26+
- id: booking-service
27+
uri: http://localhost:8084
28+
predicates:
29+
- Path=/api/{version}/booking/**
30+
filters:
31+
- TokenRelay
2032

2133

2234
server:

booking.rest

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
2+
@api-gateway=http://localhost:8081
3+
@keycloak-api=http://localhost:8080
4+
@flight-api=http://localhost:8082
5+
@passenger-api=http://localhost:8083
6+
@booking-api=http://localhost:8084
7+
8+
@contentType = application/json
9+
@flightId = "3c5c0000-97c6-fc34-2eb9-08db322230c9"
10+
@passengerId = "4c5c0000-97c6-fc34-a0cb-08db322230c0"
11+
@aircraftId = "3c5c0000-97c6-fc34-fcd3-08db322230c8"
12+
@arriveAirportId = "3c5c0000-97c6-fc34-a0cb-08db322230c8"
13+
@departureAirportId = "3c5c0000-97c6-fc34-fc3c-08db322230c8"
14+
################################# Keycloak API #################################
15+
16+
###
17+
# @name ApiRoot_Keycloak
18+
GET {{keycloak-api}}
19+
###
20+
21+
22+
###
23+
# @name Authenticate
24+
POST {{keycloak-api}}/realms/keycloak-realm/protocol/openid-connect/token
25+
Content-Type: application/x-www-form-urlencoded
26+
27+
grant_type=client_credentials
28+
&client_id=flight-client-credentials
29+
&client_secret=Glcz8z8E6alTIfay1GdMc6XTTeuZrgOs
30+
&scope=openid
31+
###
32+
33+
34+
################################# Flight API #################################
35+
36+
###
37+
# @name ApiRoot_Flight
38+
GET {{flight-api}}
39+
###
40+
41+
###
42+
# @name Create_Seat
43+
Post {{api-gateway}}/api/v1/flight/seat
44+
accept: application/json
45+
Content-Type: application/json
46+
authorization: bearer {{Authenticate.response.body.access_token}}
47+
48+
{
49+
"seatNumber": "1255",
50+
"seatType": "Window",
51+
"seatClass": "FirstClass",
52+
"flightId": {{flightId}}
53+
}
54+
###
55+
56+
57+
###
58+
# @name Reserve_Seat
59+
Post {{api-gateway}}/api/v1/flight/reserve-seat
60+
accept: application/json
61+
Content-Type: application/json
62+
authorization: bearer {{Authenticate.response.body.access_token}}
63+
64+
{
65+
"seatNumber":"1255",
66+
"flightId": {{flightId}}
67+
}
68+
###
69+
70+
71+
###
72+
# @name Get_Available_Seats
73+
GET {{api-gateway}}/api/v1/flight/get-available-seats/3c5c0000-97c6-fc34-2eb9-08db322230c9
74+
accept: application/json
75+
Content-Type: application/json
76+
authorization: bearer {{Authenticate.response.body.access_token}}
77+
###
78+
79+
80+
###
81+
# @name Get_Flight_By_Id
82+
GET {{api-gateway}}/api/v1/flight/3c5c0000-97c6-fc34-2eb9-08db322230c9
83+
accept: application/json
84+
Content-Type: application/json
85+
authorization: bearer {{Authenticate.response.body.access_token}}
86+
###
87+
88+
89+
###
90+
# @name Get_Available_Flights
91+
GET {{api-gateway}}/api/v1/flight/get-available-flights
92+
accept: application/json
93+
Content-Type: application/json
94+
authorization: bearer {{Authenticate.response.body.access_token}}
95+
###
96+
97+
98+
###
99+
# @name Create_Flights
100+
POST {{api-gateway}}/api/v1/flight
101+
accept: application/json
102+
Content-Type: application/json
103+
authorization: bearer {{Authenticate.response.body.access_token}}
104+
105+
{
106+
"flightNumber": "20BB",
107+
"aircraftId": {{aircraftId}},
108+
"departureAirportId": {{departureAirportId}},
109+
"departureDate": "2022-03-01T14:55:41.255Z",
110+
"arriveDate": "2022-03-01T14:55:41.255Z",
111+
"arriveAirportId": {{arriveAirportId}},
112+
"durationMinutes": 120,
113+
"flightDate": "2022-03-01T14:55:41.255Z",
114+
"status": "Delay",
115+
"price": 8000
116+
}
117+
###
118+
119+
120+
###
121+
# @name Update_Flights
122+
PUT {{api-gateway}}/api/v1/flight/01949849-1608-7e16-975a-e7f4cf1d029d
123+
accept: application/json
124+
Content-Type: application/json
125+
authorization: bearer {{Authenticate.response.body.access_token}}
126+
127+
{
128+
"flightNumber": "20BB",
129+
"aircraftId": {{aircraftId}},
130+
"departureAirportId": {{departureAirportId}},
131+
"departureDate": "2025-01-24T12:35:11.803Z",
132+
"arriveDate": "2025-01-24T12:35:11.803Z",
133+
"arriveAirportId": {{arriveAirportId}},
134+
"durationMinutes": 140,
135+
"flightDate": "2025-01-24T12:35:11.803Z",
136+
"status": "Flying",
137+
"price": 8000,
138+
"isDeleted": false
139+
}
140+
###
141+
142+
143+
###
144+
# @name Delete_Flights
145+
DELETE {{api-gateway}}/api/v1/flight/01949849-1608-7e16-975a-e7f4cf1d029d
146+
accept: application/json
147+
Content-Type: application/json
148+
authorization: bearer {{Authenticate.response.body.access_token}}
149+
###
150+
151+
152+
###
153+
# @name Create_Airport
154+
POST {{api-gateway}}/api/v1/flight/airport
155+
accept: application/json
156+
Content-Type: application/json
157+
authorization: bearer {{Authenticate.response.body.access_token}}
158+
159+
{
160+
"name": "mehrabad",
161+
"address": "tehran",
162+
"code": "12YD"
163+
}
164+
###
165+
166+
167+
168+
###
169+
# @name Create_Aircraft
170+
POST {{api-gateway}}/api/v1/flight/aircraft
171+
accept: application/json
172+
Content-Type: application/json
173+
authorization: bearer {{Authenticate.response.body.access_token}}
174+
175+
{
176+
"name": "airbus2",
177+
"model": "322",
178+
"manufacturingYear": 2012
179+
}
180+
###
181+
182+
183+
################################# Passenger API #################################
184+
185+
###
186+
# @name ApiRoot_Passenger
187+
GET {{passenger-api}}
188+
###
189+
190+
191+
###
192+
# @name Register_Passenger
193+
POST {{api-gateway}}/api/v1/passenger
194+
accept: application/json
195+
Content-Type: application/json
196+
authorization: bearer {{Authenticate.response.body.access_token}}
197+
198+
{
199+
"name": "test-passenger",
200+
"passportNumber": "412900000000",
201+
"passengerType": 1,
202+
"age": 30
203+
}
204+
###
205+
206+
207+
###
208+
# @name Get_Passenger_By_Id
209+
GET {{api-gateway}}/api/v1/passenger/4c5c0000-97c6-fc34-a0cb-08db322230c0
210+
accept: application/json
211+
Content-Type: application/json
212+
authorization: bearer {{Authenticate.response.body.access_token}}
213+
###
214+
215+
216+
################################# Booking API #################################
217+
218+
###
219+
# @name ApiRoot_Booking
220+
GET {{booking-api}}
221+
###
222+
223+
224+
###
225+
# @name Create_Booking
226+
POST {{api-gateway}}/api/v1/booking
227+
accept: application/json
228+
Content-Type: application/json
229+
authorization: bearer {{Authenticate.response.body.access_token}}
230+
231+
{
232+
"passengerId": {{passengerId}},
233+
"flightId": {{flightId}},
234+
"description": "I want to fly to iran"
235+
}
236+
###

booking/src/main/java/io/bookingmicroservices/booking/bookings/features/createbooking/CreateBookingCommandHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public BookingDto handle(CreateBookingCommand command) {
5959
throw new PassengerNotFoundException();
6060
}
6161

62-
Flight.SeatResponseDto emptySeat = flightServiceBlockingStub.getAvailableSeats(toGetAvailableSeatsResponseDto(command)).getSeatsDtoList().stream().findFirst().orElse(null);
62+
Flight.SeatResponseDto emptySeat = flightServiceBlockingStub.getAvailableSeats(toGetAvailableSeatsResponseDto(command)).getSeatsDtoList().stream().findAny().orElse(null);
6363

6464
if(emptySeat == null){
6565
throw new SeatNumberIsNotAvailableException();

booking/src/main/resources/application-dev.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ logging:
1414
name: booking-logger
1515
level:
1616
root: INFO
17+
io:
18+
grpc: DEBUG
1719

1820
server:
1921
port: 8084
2022

2123
grpc:
24+
server:
25+
port: 9094
2226
client:
2327
flight-service:
2428
address: "static://localhost:9092"

buildingblocks/src/main/java/buildingblocks/testbase/EndToEndTestBase.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

buildingblocks/src/main/java/buildingblocks/testbase/IntegrationTestBase.java renamed to buildingblocks/src/main/java/buildingblocks/testbase/TestBase.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@
1111
import org.springframework.test.context.ActiveProfiles;
1212
import org.springframework.test.context.DynamicPropertyRegistry;
1313
import org.springframework.test.context.DynamicPropertySource;
14+
import org.springframework.test.web.servlet.MockMvc;
1415

1516

1617
@SpringBootTest
1718
@ActiveProfiles("test")
1819
@AutoConfigureMockMvc
1920
@WithMockUser(authorities = "ADMIN")
20-
public abstract class IntegrationTestBase {
21+
public abstract class TestBase {
2122

2223
@Autowired
2324
private ApplicationContext applicationContext;
2425

26+
@Autowired
27+
protected MockMvc mockMvc;
28+
2529
protected TestFixture fixture;
2630

2731
@PostConstruct

flight/src/main/java/io/bookingmicroservices/flight/data/jpa/repositories/SeatRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import io.bookingmicroservices.flight.data.jpa.entities.SeatEntity;
44
import io.bookingmicroservices.flight.seats.features.Mappings;
55
import io.bookingmicroservices.flight.seats.models.Seat;
6+
import io.bookingmicroservices.flight.seats.valueobjects.FlightId;
7+
import io.bookingmicroservices.flight.seats.valueobjects.SeatNumber;
68
import jakarta.persistence.EntityManager;
79
import org.springframework.data.jpa.repository.JpaRepository;
810
import org.springframework.stereotype.Repository;
@@ -12,7 +14,7 @@
1214
@Repository
1315
public interface SeatRepository extends JpaRepository<SeatEntity, UUID>, SeatRepositoryCustom {
1416
SeatEntity findSeatByIdAndIsDeletedFalse(UUID id);
15-
SeatEntity findSeatByFlightIdAndSeatNumberAndIsDeletedFalse(UUID flightId, String seatNumber);
17+
SeatEntity findSeatByFlightIdAndSeatNumberAndIsDeletedFalse(FlightId flightId, SeatNumber seatNumber);
1618
}
1719

1820
interface SeatRepositoryCustom {

flight/src/main/java/io/bookingmicroservices/flight/data/mongo/repositories/SeatReadRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.UUID;
99

1010
public interface SeatReadRepository extends MongoRepository<SeatDocument, ObjectId> {
11-
SeatDocument findBySeatIdAndIsDeletedFalse(UUID seatId);
11+
SeatDocument findSeatByFlightIdAndSeatNumberAndIsDeletedFalse(UUID flightId, String seatNumber);
1212
List<SeatDocument> findAllSeatsByFlightIdAndIsDeletedFalse(UUID flightId);
1313
}
1414

0 commit comments

Comments
 (0)