Skip to content

Commit

Permalink
Merge branch 'main' into event/194
Browse files Browse the repository at this point in the history
  • Loading branch information
park0jae authored Jan 10, 2024
2 parents e1dd08c + 0994804 commit 675f736
Show file tree
Hide file tree
Showing 27 changed files with 425 additions and 219 deletions.
4 changes: 4 additions & 0 deletions api/api-booking/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-security'

implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
implementation 'io.jsonwebtoken:jjwt-impl:0.12.3'
implementation 'io.jsonwebtoken:jjwt-jackson:0.12.3'

// querydsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
Expand Down
50 changes: 35 additions & 15 deletions api/api-booking/http/booking.http
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
### 세션 아이디 발급
POST http://localhost:8082/api/v1/bookings/issue-session-id
#Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ

### 대기열 진입
POST http://localhost:8082/api/v1/bookings/enter-queue
Content-Type: application/json
#Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Session-Id: {세션아이디}
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Session-Id: {sessionId}

{
"eventId": 1
}

### 대기열 조회
GET http://localhost:8082/api/v1/bookings/order-in-queue?eventId=1
#Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Session-Id: {세션아이디}
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Session-Id: {sessionId}


### 예매 토큰 발급
POST http://localhost:8082/api/v1/bookings/issue-token
Content-Type: application/json
#Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Session-Id: {세션아이디}
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Session-Id: {sessionId}

{
"eventId": 1
Expand All @@ -31,29 +31,49 @@ Booking-Session-Id: {세션아이디}
### [Optional] 대기열 이탈
POST http://localhost:8082/api/v1/bookings/exit-queue
Content-Type: application/json
#Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Session-Id: {세션아이디}
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Session-Id: {sessionId}

{
"eventId": 1
}

### 좌석 목록 조회
GET http://localhost:8082/api/v1/seats?eventTimeId=1
#Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Authorization: Bearer eyJhbGciOiJIUzM4NCJ9.eyJpc3MiOiJib29raW5nIiwiaWF0IjoxNzA0NzA0NTY0LCJleHAiOjQyMDAxNzA0NzA0NTY0LCJzZXNzaW9uSWQiOiJ7Pz8_Pz99In0.iKZaud5vfvsMzXmQzl1WaCweL9GL00U0iGzCg4_p3Zzei8Y7z19Ff_TTpxh9gLeB

### 좌석 선택
POST http://localhost:8082/api/v1/seats/1/select
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Authorization: Bearer eyJhbGciOiJIUzM4NCJ9.eyJpc3MiOiJib29raW5nIiwiaWF0IjoxNzA0NzA0NTY0LCJleHAiOjQyMDAxNzA0NzA0NTY0LCJzZXNzaW9uSWQiOiJ7Pz8_Pz99In0.iKZaud5vfvsMzXmQzl1WaCweL9GL00U0iGzCg4_p3Zzei8Y7z19Ff_TTpxh9gLeB

{
"seatId": 1
}

### 좌석 선택 해제
POST http://localhost:8082/api/v1/seats/1/deselect
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Authorization: Bearer eyJhbGciOiJIUzM4NCJ9.eyJpc3MiOiJib29raW5nIiwiaWF0IjoxNzA0NzA0NTY0LCJleHAiOjQyMDAxNzA0NzA0NTY0LCJzZXNzaW9uSWQiOiJ7Pz8_Pz99In0.iKZaud5vfvsMzXmQzl1WaCweL9GL00U0iGzCg4_p3Zzei8Y7z19Ff_TTpxh9gLeB

{
"seatId": 1
}

### 예매 ~ 결제 (브라우저에서 진행해 주세요)
GET http://localhost:8082/bookings

### [Optional] 예매 이탈
POST http://localhost:8082/api/v1/bookings/bookingCreateTestId/exit
#Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Booking-Authorization: Bearer eyJhbGciOiJIUzM4NCJ9.eyJpc3MiOiJib29raW5nIiwiaWF0IjoxNzA0NzA0NTY0LCJleHAiOjQyMDAxNzA0NzA0NTY0LCJzZXNzaW9uSWQiOiJ7Pz8_Pz99In0.iKZaud5vfvsMzXmQzl1WaCweL9GL00U0iGzCg4_p3Zzei8Y7z19Ff_TTpxh9gLeB

### 예매 취소 (브라우저에서 생성된 예매번호로 진행해 주세요)
POST http://localhost:8082/api/v1/bookings/1704704631741/cancel
#Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
POST http://localhost:8082/api/v1/bookings/{bookingId}/cancel
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Content-Type: application/json

{
Expand All @@ -62,8 +82,8 @@ Content-Type: application/json

### 내 예매 내역 목록 조회
GET http://localhost:8082/api/v1/bookings
#Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ

### 내 예매 내역 상세 조회
GET http://localhost:8082/api/v1/bookings/bookingCancelTestId
#Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJpYXQiOjE3MDQ2OTE0OTEsImV4cCI6MTgwNDY4MzI5MSwiYXV0aG9yaXR5IjoiUk9MRV9VU0VSIn0.wFNSz2uwRa35jP1KihNlTOewVLgMMeg3ADQ5Kztl3QQ
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.pgms.apibooking.common.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import com.pgms.apibooking.common.exception.BookingException;
import com.pgms.apibooking.common.jwt.BookingJwtPayload;
import com.pgms.apibooking.common.jwt.BookingJwtProvider;
import com.pgms.coredomain.domain.common.BookingErrorCode;

import io.jsonwebtoken.JwtException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
@RequiredArgsConstructor
public class BookingTokenInterceptor implements HandlerInterceptor {

private final BookingJwtProvider bookingJwtProvider;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws
Exception {
String token = parseToken(request);
try {
BookingJwtPayload authentication = bookingJwtProvider.validateAndParsePayload(token);
request.setAttribute("tokenSessionId", authentication.sessionId());
} catch (JwtException | BookingException e) {
log.warn(e.getMessage(), e);
throw new BookingException(BookingErrorCode.INVALID_BOOKING_TOKEN);
}
return true;
}

private String parseToken(HttpServletRequest request) {
String headerAuth = request.getHeader("Booking-Authorization");
if (headerAuth != null && headerAuth.startsWith("Bearer ")) {
return headerAuth.substring(7);
}
throw new BookingException(BookingErrorCode.BOOKING_TOKEN_NOT_EXIST);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pgms.coresecurity.security.jwt.booking;
package com.pgms.apibooking.common.jwt;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pgms.coresecurity.security.jwt.booking;
package com.pgms.apibooking.common.jwt;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.pgms.coresecurity.security.config;
package com.pgms.apibooking.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.pgms.coresecurity.security.jwt.booking.BookingJwtProvider;

import com.pgms.apibooking.common.jwt.BookingJwtProvider;
import io.jsonwebtoken.security.Keys;

import lombok.Getter;

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.pgms.apibooking.common.interceptor.BookingSessionInterceptor;
import com.pgms.apibooking.common.interceptor.BookingTokenInterceptor;

import lombok.RequiredArgsConstructor;

Expand All @@ -15,6 +16,7 @@
public class WebConfig implements WebMvcConfigurer {

private final BookingSessionInterceptor bookingSessionInterceptor;
private final BookingTokenInterceptor bookingTokenInterceptor;

@Override
public void addInterceptors(InterceptorRegistry registry) {
Expand All @@ -23,5 +25,11 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/api/*/bookings/order-in-queue")
.addPathPatterns("/api/*/bookings/issue-token")
.addPathPatterns("/api/*/bookings/exit-queue");
registry.addInterceptor(bookingTokenInterceptor)
.addPathPatterns("/api/*/bookings/create")
.addPathPatterns("/api/*/exit")
.addPathPatterns("/api/*/seats")
.addPathPatterns("/api/*/*/select")
.addPathPatterns("/api/*/*/deselect");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -22,6 +23,7 @@
import com.pgms.apibooking.domain.booking.dto.response.PageResponse;
import com.pgms.apibooking.domain.booking.service.BookingService;
import com.pgms.coredomain.response.ApiResponse;
import com.pgms.coresecurity.security.resolver.CurrentAccount;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
Expand All @@ -34,13 +36,13 @@ public class BookingController {

private final BookingService bookingService;

@PostMapping
@PostMapping("/create")
public ResponseEntity<ApiResponse<BookingCreateResponse>> createBooking(
//@CurrentAccount Long memberId,
@CurrentAccount Long memberId,
@RequestBody @Valid BookingCreateRequest request,
HttpServletRequest httpRequest
) {
BookingCreateResponse createdBooking = bookingService.createBooking(request, 1L); //TODO: 인증된 memberId 지정
@RequestAttribute("tokenSessionId") String tokenSessionId,
HttpServletRequest httpRequest) {
BookingCreateResponse createdBooking = bookingService.createBooking(request, memberId, tokenSessionId);
ApiResponse<BookingCreateResponse> response = ApiResponse.ok(createdBooking);
URI location = UriComponentsBuilder
.fromHttpUrl(httpRequest.getRequestURL().toString())
Expand All @@ -52,11 +54,10 @@ public ResponseEntity<ApiResponse<BookingCreateResponse>> createBooking(

@PostMapping("/{id}/cancel")
public ResponseEntity<Void> cancelBooking(
//@CurrentAccount Long memberId,
@CurrentAccount Long memberId,
@PathVariable String id,
@RequestBody @Valid BookingCancelRequest request
) {
bookingService.cancelBooking(id, request, 1L); //TODO: 인증된 memberId 지정
@RequestBody @Valid BookingCancelRequest request) {
bookingService.cancelBooking(id, request, memberId);
return ResponseEntity.ok().build();
}

Expand All @@ -68,21 +69,21 @@ public ResponseEntity<Void> exitBooking(@PathVariable String id) {

@GetMapping
public ResponseEntity<ApiResponse<PageResponse<BookingsGetResponse>>> getBookings(
// @CurrentAccount Long memberId,
@CurrentAccount Long memberId,
@ModelAttribute @Valid PageCondition pageCondition,
@ModelAttribute @Valid BookingSearchCondition searchCondition
) {
PageResponse<BookingsGetResponse> bookings = bookingService.getBookings(pageCondition, searchCondition, 1L); //TODO: 인증된 memberId 지정
PageResponse<BookingsGetResponse> bookings = bookingService.getBookings(pageCondition, searchCondition, memberId);
ApiResponse<PageResponse<BookingsGetResponse>> response = ApiResponse.ok(bookings);
return ResponseEntity.ok().body(response);
}

@GetMapping("/{id}")
public ResponseEntity<ApiResponse<BookingGetResponse>> getBooking(
// @CurrentAccount Long memberId,
@CurrentAccount Long memberId,
@PathVariable String id
) {
BookingGetResponse booking = bookingService.getBooking(id, 1L); //TODO: 인증된 memberId 지정
BookingGetResponse booking = bookingService.getBooking(id, memberId);
ApiResponse<BookingGetResponse> response = ApiResponse.ok(booking);
return ResponseEntity.ok().body(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -45,7 +43,6 @@
import com.pgms.coredomain.domain.event.repository.EventTimeRepository;
import com.pgms.coredomain.domain.member.Member;
import com.pgms.coredomain.domain.member.repository.MemberRepository;
import com.pgms.coresecurity.security.jwt.booking.BookingAuthToken;

import lombok.RequiredArgsConstructor;

Expand All @@ -64,7 +61,7 @@ public class BookingService { //TODO: 테스트 코드 작성
private final TossPaymentConfig tossPaymentConfig;
private final PaymentService paymentService;

public BookingCreateResponse createBooking(BookingCreateRequest request, Long memberId) {
public BookingCreateResponse createBooking(BookingCreateRequest request, Long memberId, String tokenSessionId) {
Member member = getMemberById(memberId);
EventTime time = getBookableTimeWithEvent(request.timeId());
List<EventSeat> seats = getBookableSeatsWithArea(request.timeId(), request.seatIds());
Expand All @@ -91,7 +88,7 @@ public BookingCreateResponse createBooking(BookingCreateRequest request, Long me

seats.forEach(seat -> seat.updateStatus(EventSeatStatus.BOOKED));

removeSessionIdInBookingQueue(booking.getTime().getEvent().getId());
removeSessionIdInBookingQueue(booking.getTime().getEvent().getId(), tokenSessionId);

return BookingCreateResponse.of(booking, tossPaymentConfig.getSuccessUrl(), tossPaymentConfig.getFailUrl());
}
Expand Down Expand Up @@ -164,8 +161,8 @@ public BookingGetResponse getBooking(String id, Long memberId) {
}

@Async
protected void removeSessionIdInBookingQueue(Long eventId) {
bookingQueueRepository.remove(eventId, getCurrentSessionId());
protected void removeSessionIdInBookingQueue(Long eventId, String tokenSessionId) {
bookingQueueRepository.remove(eventId, tokenSessionId);
}

private EventTime getBookableTimeWithEvent(Long timeId) {
Expand Down Expand Up @@ -212,12 +209,4 @@ private Member getMemberById(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new BookingException(MemberErrorCode.MEMBER_NOT_FOUND));
}

private String getCurrentSessionId() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof BookingAuthToken) {
return authentication.getPrincipal().toString();
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pgms.apibooking.domain.bookingqueue.repository;

import java.util.Optional;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

Expand All @@ -15,8 +17,8 @@ public void add(Long eventId, String sessionId, double currentTimeSeconds) {
redisTemplate.opsForZSet().add(String.valueOf(eventId), sessionId, currentTimeSeconds);
}

public Long getRank(Long eventId, String sessionId) {
return redisTemplate.opsForZSet().rank(String.valueOf(eventId), sessionId);
public Optional<Long> getRank(Long eventId, String sessionId) {
return Optional.ofNullable(redisTemplate.opsForZSet().rank(String.valueOf(eventId), sessionId));
}

public Long getEntryLimit() {
Expand Down
Loading

0 comments on commit 675f736

Please sign in to comment.