Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:f-lab-edu/kbo-ticketing into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
princenim committed May 1, 2024
2 parents 0fb4690 + 4dbbc67 commit 283f39c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.kboticketing.kboticketing.Interceptor;

import com.kboticketing.kboticketing.exception.CustomException;
import com.kboticketing.kboticketing.exception.ErrorCode;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

/**
* todo 수정 예정
*
* @author hazel
*/

@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) {
String requestURI = request.getRequestURI();
log.info("[interceptor] requestURI : " + requestURI);

String token = request.getHeader("Authorization");
if (token == null) {
throw new CustomException(ErrorCode.LOGIN_REQUIRED);
}

String[] splitToken = token.split(" ");
String userId = splitToken[1];
request.setAttribute("userId", userId);
return true;
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/kboticketing/kboticketing/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.kboticketing.kboticketing.config;

import com.kboticketing.kboticketing.Interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* @author hazel
*/
@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor())
.order(1)
.addPathPatterns("/", "/seats", "/reservations");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.kboticketing.kboticketing.dto.ReservationDto;
import com.kboticketing.kboticketing.service.ReservationService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -15,12 +16,12 @@
public class ReservationController {

private final ReservationService reservationService;
private final HttpServletRequest request;

@PostMapping("/reservations")
public void reserveSeats(@RequestBody ReservationDto reservationDto) {

//todo 로그인 기능 후 추가
int userId = 1;
Integer userId = Integer.valueOf(request.getAttribute("userId")
.toString());
reservationService.reserveSeats(reservationDto, userId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.kboticketing.kboticketing.dto.SeatDto;
import com.kboticketing.kboticketing.service.SeatService;
import com.kboticketing.kboticketing.response.CommonResponse;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -21,6 +22,7 @@
public class SeatController {

private final SeatService seatService;
private final HttpServletRequest request;

@GetMapping("/schedules/{scheduleId}/seat-grades/{seatGradeId}")
public ResponseEntity<CommonResponse> getSeatsByGrade(@PathVariable String scheduleId,
Expand All @@ -40,8 +42,8 @@ public ResponseEntity<CommonResponse> getSeatGrade(@PathVariable String id) {
@PostMapping("/seats")
public void selectSeats(@RequestBody SeatDto seatDto) {

//todo 로그인 작업 후 추가
Integer userId = 1;
int userId = Integer.parseInt(request.getAttribute("userId")
.toString());
seatService.selectSeats(seatDto, userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum ErrorCode {
MAXIMUM_SEAT_EXCEED(HttpStatus.BAD_REQUEST, "예매 가능한 좌석 수량을 초과했습니다."),
MAXIMUM_RESERVATION_EXCEED(HttpStatus.BAD_REQUEST, "한 경기당 예매 가능한 횟수를 초과했습니다."),
RESERVED_SEAT(HttpStatus.BAD_REQUEST, "이미 예매된 좌석입니다."),
LOGIN_REQUIRED(HttpStatus.BAD_REQUEST, "로그인을 먼저 진행해주세요."),

/* 500 INTERNAL_SERVER_ERROR : 서버 오류 */
FAIL_SEND_EMAIL(HttpStatus.INTERNAL_SERVER_ERROR, "이메일 전송에 실패하였습니다."),
Expand Down

0 comments on commit 283f39c

Please sign in to comment.