Skip to content

Commit 75ad2e8

Browse files
committed
Creating Event logic added, booking seat logic added and enums added , some fields are added in Event model.
1 parent fc740b2 commit 75ad2e8

13 files changed

Lines changed: 164 additions & 7 deletions

File tree

‎.github/workflows/event-service-deploy.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: Deploy Event Service to Amazon ECS
22

33
on:
44
push:
5-
branches: [ "main" ]
6-
# PRO TIP: Only run this pipeline if files in the event-service folder change
7-
paths:
8-
- 'event-service/**'
5+
# branches: [ "main" ]
6+
# # PRO TIP: Only run this pipeline if files in the event-service folder change
7+
# paths:
8+
# - 'event-service/**'
99

1010
env:
1111
AWS_REGION: us-east-1

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.streamseat.bookingservice.client;
22

33
import com.streamseat.bookingservice.dto.EventDTO;
4+
import com.streamseat.bookingservice.dto.SeatType;
45
import org.springframework.cloud.openfeign.FeignClient;
56
import org.springframework.web.bind.annotation.GetMapping;
67
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.PutMapping;
9+
import org.springframework.web.bind.annotation.RequestParam;
710

811
// NAME must match the name in Eureka (EVENT-SERVICE)
912
@FeignClient(name = "event-service")
@@ -14,4 +17,7 @@ public interface EventClient {
1417
// (Note: We need to go add this endpoint to Event Service later if it's missing!)
1518
@GetMapping("/api/events/{id}")
1619
EventDTO getEventById(@PathVariable("id") Long id);
20+
21+
@PutMapping("/api/events/{id}/reserve")
22+
boolean reserveSeat(@PathVariable("id") Long id, @RequestParam SeatType seatType);
1723
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public class EventDTO {
88
private Long id;
99
private String title;
1010
private int capacity;
11-
// private LocalDateTime eventDateTime;
11+
private LocalDateTime eventDateTime;
1212
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.streamseat.bookingservice.dto;
2+
3+
public enum SeatType{
4+
FRONT_SEAT,
5+
BACK_SEAT
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.streamseat.bookingservice.dto;
2+
3+
public enum Status {
4+
CONFIRMED,
5+
CANCELLED
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.streamseat.bookingservice.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@AllArgsConstructor
10+
@NoArgsConstructor
11+
@Builder
12+
public class TicketDTO {
13+
private int eventId;
14+
private int eventDateTime;
15+
private int seatType;
16+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.streamseat.bookingservice.model;
22

3+
import com.streamseat.bookingservice.dto.SeatType;
4+
import com.streamseat.bookingservice.dto.Status;
35
import jakarta.persistence.*;
46
import lombok.AllArgsConstructor;
57
import lombok.Builder;
@@ -20,6 +22,8 @@ public class Booking {
2022

2123
private Long eventId; // Which event?
2224
private Long userId; // Who booked it? (We'll hardcode this for now)
23-
private String status; // CONFIRMED, CANCELLED
25+
@Enumerated(EnumType.STRING)
26+
private SeatType seatType;
27+
private Status status; // CONFIRMED, CANCELLED
2428
private LocalDateTime bookingTime;
2529
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.streamseat.bookingservice.service;
2+
3+
import com.streamseat.bookingservice.client.EventClient;
4+
import com.streamseat.bookingservice.dto.EventDTO;
5+
import com.streamseat.bookingservice.dto.Status;
6+
import com.streamseat.bookingservice.dto.TicketDTO;
7+
import com.streamseat.bookingservice.dto.SeatType;
8+
import com.streamseat.bookingservice.model.Booking;
9+
import com.streamseat.bookingservice.repository.BookingRepository;
10+
import lombok.RequiredArgsConstructor;
11+
import org.springframework.stereotype.Service;
12+
13+
import java.awt.print.Book;
14+
15+
@Service
16+
@RequiredArgsConstructor
17+
public class BookingService {
18+
public final EventClient eventClient;
19+
private final BookingRepository bookingRepository;
20+
public String bookTicket(Long eventId, SeatType seat,Long userId){
21+
EventDTO event=eventClient.getEventById(eventId);
22+
Booking booking=new Booking();
23+
booking.setBookingTime(event.getEventDateTime());
24+
booking.setSeatType(seat);
25+
booking.setEventId(eventId);
26+
booking.setUserId(userId);
27+
booking.setStatus(Status.CONFIRMED);
28+
bookingRepository.save(booking);
29+
30+
return "Booked";
31+
}
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.streamseat.eventservice.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.time.LocalDateTime;
8+
@Data
9+
@AllArgsConstructor
10+
@NoArgsConstructor
11+
public class EventDTO {
12+
private String title;
13+
private String description;
14+
private LocalDateTime eventDateTime;
15+
private int capacity;
16+
private int frontSeats;
17+
private int backSeats;
18+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.streamseat.eventservice.dto;
2+
3+
public enum SeatType {
4+
FRONT_SEAT,
5+
BACK_SEAT
6+
}

0 commit comments

Comments
 (0)