Skip to content

Commit a8e16fc

Browse files
committed
fixed application.properties of booking-service and fixed feignClient in booking-service, and X-user-id returning username
1 parent 2d9508d commit a8e16fc

5 files changed

Lines changed: 17 additions & 14 deletions

File tree

‎booking-service/src/main/java/com/streamseat/bookingservice/client/EventClient.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
import org.springframework.web.bind.annotation.PutMapping;
99
import org.springframework.web.bind.annotation.RequestParam;
1010

11-
// NAME must match the name in Eureka (EVENT-SERVICE)
1211
@FeignClient(name = "event-service")
1312
public interface EventClient {
1413

15-
// We are "mapping" the call to the Event Service's existing endpoint
16-
// GET http://event-service/api/events/{id}
17-
// (Note: We need to go add this endpoint to Event Service later if it's missing!)
1814
@GetMapping("/api/events/{id}")
15+
// Added ("id") here
1916
EventDTO getEventById(@PathVariable("id") Long id);
2017

2118
@PutMapping("/api/events/{id}/reserve")
22-
boolean reserveSeat(@PathVariable("id") Long id, @RequestParam SeatType seatType);
19+
// Added ("id") and ("seatType") here
20+
boolean reserveSeat(@PathVariable("id") Long id,
21+
@RequestParam("seatType") SeatType seatType);
2322
}

‎booking-service/src/main/java/com/streamseat/bookingservice/controller/BookingController.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ public BookingController(BookingRepository bookingRepository, EventClient eventC
2121
}
2222

2323
@PostMapping
24-
public String bookTicket(@RequestBody Booking bookingRequest) {
24+
public String bookTicket(@RequestBody Booking bookingRequest,@RequestHeader("X-User-Id") String userId) {
2525
Long eventId = bookingRequest.getEventId();
2626

27+
2728
// 1. TALK to Event Service: "Does this event exist?"
2829
EventDTO event = eventClient.getEventById(eventId);
2930
if (event == null) {
@@ -39,6 +40,8 @@ public String bookTicket(@RequestBody Booking bookingRequest) {
3940
// 3. BOOK IT
4041
bookingRequest.setStatus(Status.valueOf("CONFIRMED"));
4142
bookingRequest.setBookingTime(LocalDateTime.now());
43+
bookingRequest.setUserId(userId);
44+
System.out.println(userId);
4245
bookingRepository.save(bookingRequest);
4346

4447
return "Success! Ticket booked for event: " + event.getTitle();

‎booking-service/src/main/java/com/streamseat/bookingservice/model/Booking.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Booking {
2121
private Long id;
2222

2323
private Long eventId; // Which event?
24-
private Long userId; // Who booked it? (We'll hardcode this for now)
24+
private String userId; // Who booked it? (We'll hardcode this for now)
2525
@Enumerated(EnumType.STRING)
2626
private SeatType seatType;
2727
private Status status; // CONFIRMED, CANCELLED

‎booking-service/src/main/java/com/streamseat/bookingservice/service/BookingService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class BookingService {
1818
public final EventClient eventClient;
1919
private final BookingRepository bookingRepository;
20-
public String bookTicket(Long eventId, SeatType seat,Long userId){
20+
public String bookTicket(Long eventId, SeatType seat,String userId){
2121
EventDTO event=eventClient.getEventById(eventId);
2222
Booking booking=new Booking();
2323
booking.setBookingTime(event.getEventDateTime());

‎booking-service/src/main/resources/application.properties‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ spring.application.name=booking-service
44
server.port=8080
55

66
# 1. Eureka Fix: Use the service name 'discovery-server'
7-
eureka.client.service-url.defaultZone=${EUREKA_URL:http://discovery-server:8761/eureka/}
7+
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
88

99
# 2. Database Fix: Use the service name 'mysqldb'
10-
spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:mysql://mysqldb:3306/stream_seat_db?createDatabaseIfNotExist=true}
11-
spring.datasource.username=${SPRING_DATASOURCE_USERNAME:root}
12-
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:root}
10+
spring.datasource.url=jdbc:mysql://localhost:3306/stream_seat_db?createDatabaseIfNotExist=true
11+
spring.datasource.username=root
12+
spring.datasource.password=kesh@v123
13+
spring.jpa.hibernate.ddl-auto=create
1314
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
14-
15+
event.service.url=http://localhost:8081
1516
# 3. Networking Fix: Crucial for Docker
1617
eureka.instance.prefer-ip-address=true
1718

18-
spring.jpa.hibernate.ddl-auto=update
19+
1920
spring.jpa.show-sql=true
2021
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect

0 commit comments

Comments
 (0)