Compare commits
2 Commits
feature/Ti
...
feature/pa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5059eb3b09 | ||
|
|
e42613a14c |
@@ -91,7 +91,7 @@ erDiagram
|
|||||||
bigint seat_id FK "좌석 ID"
|
bigint seat_id FK "좌석 ID"
|
||||||
bigint movie_time_id FK "상영시간표 ID"
|
bigint movie_time_id FK "상영시간표 ID"
|
||||||
bigint payment_id "결제 ID"
|
bigint payment_id "결제 ID"
|
||||||
varchar status "상태 - 판매가능/예약/"
|
varchar status "상태 - 구매가능/예약진행중/판매완료"
|
||||||
int ticket_price "가격"
|
int ticket_price "가격"
|
||||||
datetime deleted_at "삭제일시"
|
datetime deleted_at "삭제일시"
|
||||||
datetime created_at "등록일시"
|
datetime created_at "등록일시"
|
||||||
@@ -101,11 +101,10 @@ erDiagram
|
|||||||
PAYMENT {
|
PAYMENT {
|
||||||
bigint id PK "결제 ID"
|
bigint id PK "결제 ID"
|
||||||
bigint user_alternate_id "유저 대체ID"
|
bigint user_alternate_id "유저 대체ID"
|
||||||
varchar tid "카카오페이 결제고유번호"
|
|
||||||
varchar movie_title "영화제목"
|
varchar movie_title "영화제목"
|
||||||
varchar type "결제 타입 - 예) 네이버페이, 카카오페이"
|
varchar type "결제 타입 - 예) 네이버페이, 카카오페이"
|
||||||
varchar status "상태 - 완료/환불"
|
varchar status "상태 - 완료/환불/실패"
|
||||||
varchar failed_message "실패사유"
|
varchar failed_message "실패사유 - 컬럼명을 알아보기 쉬운가?"
|
||||||
varchar payment_number "예매번호"
|
varchar payment_number "예매번호"
|
||||||
int total_price "결제 금액"
|
int total_price "결제 금액"
|
||||||
datetime deleted_at "삭제일시"
|
datetime deleted_at "삭제일시"
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.ticketing.server.global.config;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import org.springframework.security.test.context.support.WithSecurityContext;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@WithSecurityContext(factory = WithAuthUserSecurityContextFactory.class)
|
|
||||||
public @interface WithAuthUser {
|
|
||||||
|
|
||||||
String email();
|
|
||||||
|
|
||||||
String role();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.ticketing.server.global.config;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
||||||
import org.springframework.security.core.context.SecurityContext;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
|
||||||
import org.springframework.security.test.context.support.WithSecurityContextFactory;
|
|
||||||
|
|
||||||
public class WithAuthUserSecurityContextFactory implements WithSecurityContextFactory<WithAuthUser> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SecurityContext createSecurityContext(WithAuthUser annotation) {
|
|
||||||
String email = annotation.email();
|
|
||||||
String role = annotation.role();
|
|
||||||
List<SimpleGrantedAuthority> authorities = List.of(new SimpleGrantedAuthority(role));
|
|
||||||
|
|
||||||
User authUser = new User(email, "", authorities);
|
|
||||||
UsernamePasswordAuthenticationToken token =
|
|
||||||
new UsernamePasswordAuthenticationToken(authUser, "", authorities);
|
|
||||||
SecurityContext context = SecurityContextHolder.getContext();
|
|
||||||
context.setAuthentication(token);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package com.ticketing.server.movie.aop;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class TicketLockAspectTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TicketLockAspect ticketLockAspect;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("티켓 lock 동시성 체크")
|
|
||||||
@SuppressWarnings({"java:S5960"})
|
|
||||||
void ticketMultiThread() throws InterruptedException {
|
|
||||||
// given
|
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
|
||||||
CountDownLatch latch = new CountDownLatch(2);
|
|
||||||
|
|
||||||
List<String> lockIds = List.of("TicketLock:1", "TicketLock:2", "TicketLock:3");
|
|
||||||
AtomicBoolean result1 = new AtomicBoolean(Boolean.TRUE);
|
|
||||||
AtomicBoolean result2 = new AtomicBoolean(Boolean.TRUE);
|
|
||||||
|
|
||||||
// when
|
|
||||||
executorService.execute(() -> {
|
|
||||||
result1.set(ticketLockAspect.isEveryTicketIdLock(lockIds));
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
|
|
||||||
executorService.execute(() -> {
|
|
||||||
result2.set(ticketLockAspect.isEveryTicketIdLock(List.of("TicketLock:1")));
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
|
|
||||||
latch.await();
|
|
||||||
|
|
||||||
// then
|
|
||||||
Long unlockCount = ticketLockAspect.ticketIdsUnlock(lockIds);
|
|
||||||
|
|
||||||
assertAll(
|
|
||||||
() -> assertThat(result1).isNotEqualTo(result2),
|
|
||||||
() -> assertThat(unlockCount > 1).isTrue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,242 +1,7 @@
|
|||||||
package com.ticketing.server.user.application;
|
package com.ticketing.server.user.application;
|
||||||
|
|
||||||
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.ticketing.server.global.config.WithAuthUser;
|
|
||||||
import com.ticketing.server.user.application.request.LoginRequest;
|
|
||||||
import com.ticketing.server.user.application.request.SignUpRequest;
|
|
||||||
import com.ticketing.server.user.application.request.UserChangeGradeRequest;
|
|
||||||
import com.ticketing.server.user.application.request.UserChangePasswordRequest;
|
|
||||||
import com.ticketing.server.user.application.request.UserDeleteRequest;
|
|
||||||
import com.ticketing.server.user.domain.UserGrade;
|
|
||||||
import com.ticketing.server.user.domain.UserGrade.ROLES;
|
|
||||||
import com.ticketing.server.user.domain.repository.UserRepository;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
|
||||||
import org.springframework.test.web.servlet.ResultActions;
|
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
|
||||||
@Transactional
|
|
||||||
class UserControllerTest {
|
class UserControllerTest {
|
||||||
|
|
||||||
private static final String LOGIN_URL = "/api/auth/token";
|
|
||||||
|
|
||||||
private static final String BASICS_URL = "/api/users";
|
|
||||||
private static final String DETAILS_URL = "/api/users/details";
|
|
||||||
private static final String CHANGE_PASSWORD_URL = "/api/users/password";
|
|
||||||
private static final String CHANGE_GRADE_URL = "/api/users/grade";
|
|
||||||
|
|
||||||
private static final String NAME = "$.name";
|
|
||||||
private static final String EMAIL = "$.email";
|
|
||||||
private static final String GRADE = "$.grade";
|
|
||||||
private static final String PHONE = "$.phone";
|
|
||||||
private static final String BEFORE_GRADE = "$.beforeGrade";
|
|
||||||
private static final String AFTER_GRADE = "$.afterGrade";
|
|
||||||
|
|
||||||
private static final String USER_EMAIL = "testemail@ticketing.com";
|
|
||||||
private static final String USER_PW = "qwe123";
|
|
||||||
private static final String USER_NAME = "김철수";
|
|
||||||
private static final String USER_PHONE = "010-1234-5678";
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
UserRepository userRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ObjectMapper mapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
WebApplicationContext context;
|
|
||||||
|
|
||||||
MockMvc mvc;
|
|
||||||
|
|
||||||
SignUpRequest signUpRequest;
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("회원가입 성공")
|
|
||||||
void registerSuccess() throws Exception {
|
|
||||||
// given
|
|
||||||
// when
|
|
||||||
ResultActions resultActions = mvc.perform(
|
|
||||||
post(BASICS_URL)
|
|
||||||
.content(mapper.writeValueAsString(signUpRequest))
|
|
||||||
.contentType(APPLICATION_JSON)
|
|
||||||
);
|
|
||||||
|
|
||||||
// then
|
|
||||||
resultActions
|
|
||||||
.andExpect(status().isCreated())
|
|
||||||
.andExpect(content().contentType(APPLICATION_JSON))
|
|
||||||
.andExpect(jsonPath(NAME).value(USER_NAME))
|
|
||||||
.andExpect(jsonPath(EMAIL).value(USER_EMAIL));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("유저 정보 조회")
|
|
||||||
@WithAuthUser(email = USER_EMAIL, role = ROLES.USER)
|
|
||||||
void detailsSuccess() throws Exception {
|
|
||||||
// given
|
|
||||||
mvc.perform(
|
|
||||||
post(BASICS_URL)
|
|
||||||
.content(mapper.writeValueAsString(signUpRequest))
|
|
||||||
.contentType(APPLICATION_JSON)
|
|
||||||
);
|
|
||||||
|
|
||||||
// when
|
|
||||||
ResultActions resultActions = mvc.perform(
|
|
||||||
get(DETAILS_URL)
|
|
||||||
.content(mapper.writeValueAsString(signUpRequest))
|
|
||||||
.contentType(APPLICATION_JSON)
|
|
||||||
);
|
|
||||||
|
|
||||||
// then
|
|
||||||
resultActions
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(content().contentType(APPLICATION_JSON))
|
|
||||||
.andExpect(jsonPath(NAME).value(USER_NAME))
|
|
||||||
.andExpect(jsonPath(EMAIL).value(USER_EMAIL))
|
|
||||||
.andExpect(jsonPath(GRADE).value(UserGrade.USER.name()))
|
|
||||||
.andExpect(jsonPath(PHONE).value(USER_PHONE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("유저 탈퇴 성공")
|
|
||||||
@WithAuthUser(email = USER_EMAIL, role = ROLES.USER)
|
|
||||||
void deleteUserSuccess() throws Exception {
|
|
||||||
// given
|
|
||||||
UserDeleteRequest deleteRequest = new UserDeleteRequest(USER_EMAIL, USER_PW);
|
|
||||||
LoginRequest loginRequest = new LoginRequest(USER_EMAIL, USER_PW);
|
|
||||||
mvc.perform(
|
|
||||||
post(BASICS_URL)
|
|
||||||
.content(mapper.writeValueAsString(signUpRequest))
|
|
||||||
.contentType(APPLICATION_JSON)
|
|
||||||
);
|
|
||||||
|
|
||||||
// when
|
|
||||||
|
|
||||||
// 1. 회원 탈퇴 진행
|
|
||||||
mvc.perform(
|
|
||||||
delete(BASICS_URL)
|
|
||||||
.content(mapper.writeValueAsString(deleteRequest))
|
|
||||||
.contentType(APPLICATION_JSON)
|
|
||||||
);
|
|
||||||
|
|
||||||
// 2. 탈퇴된 계정 로그인
|
|
||||||
ResultActions resultActions = mvc.perform(post(LOGIN_URL)
|
|
||||||
.content(mapper.writeValueAsString(loginRequest))
|
|
||||||
.contentType(MediaType.APPLICATION_JSON));
|
|
||||||
|
|
||||||
// then
|
|
||||||
resultActions
|
|
||||||
.andExpect(status().isUnauthorized());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("비밀번호 변경 성공")
|
|
||||||
@WithAuthUser(email = USER_EMAIL, role = ROLES.USER)
|
|
||||||
void changePasswordSuccess() throws Exception {
|
|
||||||
// given
|
|
||||||
UserChangePasswordRequest changePasswordRequest = new UserChangePasswordRequest(USER_PW, "qwe1234");
|
|
||||||
LoginRequest loginRequest = new LoginRequest(USER_EMAIL, USER_PW);
|
|
||||||
mvc.perform(
|
|
||||||
post(BASICS_URL)
|
|
||||||
.content(mapper.writeValueAsString(this.signUpRequest))
|
|
||||||
.contentType(APPLICATION_JSON)
|
|
||||||
);
|
|
||||||
|
|
||||||
// when
|
|
||||||
|
|
||||||
// 1. 패스워드 변경
|
|
||||||
mvc.perform(
|
|
||||||
put(CHANGE_PASSWORD_URL)
|
|
||||||
.content(mapper.writeValueAsString(changePasswordRequest))
|
|
||||||
.contentType(APPLICATION_JSON)
|
|
||||||
)
|
|
||||||
.andExpect(status().isOk());
|
|
||||||
|
|
||||||
// 2. 변경 전 계정으로 로그인
|
|
||||||
ResultActions resultActions = mvc.perform(post(LOGIN_URL)
|
|
||||||
.content(mapper.writeValueAsString(loginRequest))
|
|
||||||
.contentType(MediaType.APPLICATION_JSON));
|
|
||||||
|
|
||||||
// then
|
|
||||||
resultActions
|
|
||||||
.andExpect(status().isUnauthorized());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("유저 등급 변경")
|
|
||||||
@WithAuthUser(email = "admin@ticketing.com", role = ROLES.ADMIN)
|
|
||||||
void changeGradeSuccess() throws Exception {
|
|
||||||
// given
|
|
||||||
UserChangeGradeRequest changeGradeRequest = new UserChangeGradeRequest(USER_EMAIL, UserGrade.STAFF);
|
|
||||||
mvc.perform(
|
|
||||||
post(BASICS_URL)
|
|
||||||
.content(mapper.writeValueAsString(signUpRequest))
|
|
||||||
.contentType(APPLICATION_JSON)
|
|
||||||
);
|
|
||||||
|
|
||||||
// when
|
|
||||||
ResultActions resultActions = mvc.perform(
|
|
||||||
post(CHANGE_GRADE_URL)
|
|
||||||
.content(mapper.writeValueAsString(changeGradeRequest))
|
|
||||||
.contentType(APPLICATION_JSON)
|
|
||||||
);
|
|
||||||
|
|
||||||
// then
|
|
||||||
resultActions
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(content().contentType(APPLICATION_JSON))
|
|
||||||
.andExpect(jsonPath(EMAIL).value(USER_EMAIL))
|
|
||||||
.andExpect(jsonPath(BEFORE_GRADE).value(UserGrade.USER.name()))
|
|
||||||
.andExpect(jsonPath(AFTER_GRADE).value(UserGrade.STAFF.name()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("유저 등급 변경 실패 - 권한 등급이 낮을 경우")
|
|
||||||
@WithAuthUser(email = "staff@ticketing.com", role = ROLES.STAFF)
|
|
||||||
void changeGradeFail() throws Exception {
|
|
||||||
// given
|
|
||||||
UserChangeGradeRequest changeGradeRequest = new UserChangeGradeRequest(USER_EMAIL, UserGrade.STAFF);
|
|
||||||
|
|
||||||
// when
|
|
||||||
ResultActions resultActions = mvc.perform(
|
|
||||||
post(CHANGE_GRADE_URL)
|
|
||||||
.content(mapper.writeValueAsString(changeGradeRequest))
|
|
||||||
.contentType(APPLICATION_JSON)
|
|
||||||
);
|
|
||||||
|
|
||||||
// then
|
|
||||||
resultActions
|
|
||||||
.andExpect(status().isForbidden());
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void init() {
|
|
||||||
mvc = MockMvcBuilders
|
|
||||||
.webAppContextSetup(context)
|
|
||||||
.apply(springSecurity())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
signUpRequest = new SignUpRequest(USER_NAME, USER_EMAIL, USER_PW, USER_PHONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ spring:
|
|||||||
pathmatch:
|
pathmatch:
|
||||||
matching-strategy: ant_path_matcher
|
matching-strategy: ant_path_matcher
|
||||||
|
|
||||||
config:
|
|
||||||
import: "optional:configserver:"
|
|
||||||
|
|
||||||
jasypt:
|
jasypt:
|
||||||
encryptor:
|
encryptor:
|
||||||
bean: jasyptStringEncryptor
|
bean: jasyptStringEncryptor
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import static org.springframework.http.HttpStatus.CONFLICT;
|
|||||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||||
|
|
||||||
|
import com.ticketing.server.global.redis.PaymentCache;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@@ -23,11 +24,6 @@ public enum ErrorCode {
|
|||||||
BAD_REQUEST_PAYMENT_COMPLETE(BAD_REQUEST, "처리할 결제 정보가 존재하지 않습니다."),
|
BAD_REQUEST_PAYMENT_COMPLETE(BAD_REQUEST, "처리할 결제 정보가 존재하지 않습니다."),
|
||||||
BAD_REQUEST_PAYMENT_READY(BAD_REQUEST, "이미 진행 중인 결제가 존재합니다."),
|
BAD_REQUEST_PAYMENT_READY(BAD_REQUEST, "이미 진행 중인 결제가 존재합니다."),
|
||||||
BAD_REQUEST_PAYMENT_CANCEL(BAD_REQUEST, "취소할 티켓이 존재하지 않습니다."),
|
BAD_REQUEST_PAYMENT_CANCEL(BAD_REQUEST, "취소할 티켓이 존재하지 않습니다."),
|
||||||
BAD_REQUEST_TICKET_RESERVATION(BAD_REQUEST, "이미 다른 고객이 예약 진행 중인 좌석이 존재합니다."),
|
|
||||||
BAD_REQUEST_TICKET_SOLD(BAD_REQUEST, "이미 환불 진행 중 입니다."),
|
|
||||||
NOT_REFUNDABLE_TIME(BAD_REQUEST, "환불이 가능한 시간이 지났습니다."),
|
|
||||||
NOT_REFUNDABLE_SEAT(BAD_REQUEST, "환불할 수 있는 좌석이 아닙니다."),
|
|
||||||
EMPTY_TICKET_ID(BAD_REQUEST, "티켓 정보가 존재하지 않습니다."),
|
|
||||||
|
|
||||||
/* 403 FORBIDDEN : 접근 권한 제한 */
|
/* 403 FORBIDDEN : 접근 권한 제한 */
|
||||||
VALID_USER_ID(FORBIDDEN, "해당 정보에 접근 권한이 존재하지 않습니다."),
|
VALID_USER_ID(FORBIDDEN, "해당 정보에 접근 권한이 존재하지 않습니다."),
|
||||||
@@ -36,7 +32,6 @@ public enum ErrorCode {
|
|||||||
USER_NOT_FOUND(NOT_FOUND, "해당 유저 정보를 찾을 수 없습니다."),
|
USER_NOT_FOUND(NOT_FOUND, "해당 유저 정보를 찾을 수 없습니다."),
|
||||||
EMAIL_NOT_FOUND(NOT_FOUND, "해당 이메일을 찾을 수 없습니다."),
|
EMAIL_NOT_FOUND(NOT_FOUND, "해당 이메일을 찾을 수 없습니다."),
|
||||||
MOVIE_NOT_FOUND(NOT_FOUND, "해당 제목의 영화를 찾을 수 없습니다."),
|
MOVIE_NOT_FOUND(NOT_FOUND, "해당 제목의 영화를 찾을 수 없습니다."),
|
||||||
MOVIE_TIME_NOT_FOUND(NOT_FOUND, "해당 영화 시간표 정보를 찾을 수 없습니다"),
|
|
||||||
REFRESH_TOKEN_NOT_FOUND(NOT_FOUND, "리프레쉬 토큰을 찾을 수 없습니다."),
|
REFRESH_TOKEN_NOT_FOUND(NOT_FOUND, "리프레쉬 토큰을 찾을 수 없습니다."),
|
||||||
PAYMENT_ID_NOT_FOUND(NOT_FOUND, "결제정보를 찾을 수 없습니다."),
|
PAYMENT_ID_NOT_FOUND(NOT_FOUND, "결제정보를 찾을 수 없습니다."),
|
||||||
THEATER_NOT_FOUND(NOT_FOUND, "상영관 정보를 찾을 수 없습니다."),
|
THEATER_NOT_FOUND(NOT_FOUND, "상영관 정보를 찾을 수 없습니다."),
|
||||||
@@ -50,7 +45,7 @@ public enum ErrorCode {
|
|||||||
DELETED_MOVIE(CONFLICT, "이미 삭제된 영화 입니다.");
|
DELETED_MOVIE(CONFLICT, "이미 삭제된 영화 입니다.");
|
||||||
|
|
||||||
private final HttpStatus httpStatus;
|
private final HttpStatus httpStatus;
|
||||||
private final String detail;
|
private String detail;
|
||||||
|
|
||||||
/* 400 BAD_REQUEST : 잘못된 요청 */
|
/* 400 BAD_REQUEST : 잘못된 요청 */
|
||||||
public static TicketingException throwMismatchPassword() {
|
public static TicketingException throwMismatchPassword() {
|
||||||
@@ -69,6 +64,14 @@ public enum ErrorCode {
|
|||||||
throw new TicketingException(UNABLE_CHANGE_GRADE);
|
throw new TicketingException(UNABLE_CHANGE_GRADE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TicketingException throwInvalidTicketId() {
|
||||||
|
throw new TicketingException(INVALID_TICKET_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TicketingException throwBadRequestMovieTime() {
|
||||||
|
throw new TicketingException(BAD_REQUEST_MOVIE_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
public static TicketingException throwBadRequestPaymentComplete() {
|
public static TicketingException throwBadRequestPaymentComplete() {
|
||||||
throw new TicketingException(BAD_REQUEST_PAYMENT_COMPLETE);
|
throw new TicketingException(BAD_REQUEST_PAYMENT_COMPLETE);
|
||||||
}
|
}
|
||||||
@@ -77,12 +80,19 @@ public enum ErrorCode {
|
|||||||
throw new TicketingException(BAD_REQUEST_PAYMENT_READY);
|
throw new TicketingException(BAD_REQUEST_PAYMENT_READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TicketingException throwBadRequestPaymentCancel() {
|
||||||
|
throw new TicketingException(BAD_REQUEST_PAYMENT_CANCEL);
|
||||||
|
}
|
||||||
|
|
||||||
/* 403 FORBIDDEN : 접근 권한 제한 */
|
/* 403 FORBIDDEN : 접근 권한 제한 */
|
||||||
public static TicketingException throwValidUserId() {
|
public static TicketingException throwValidUserId() {
|
||||||
throw new TicketingException(VALID_USER_ID);
|
throw new TicketingException(VALID_USER_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 404 NOT_FOUND : Resource 를 찾을 수 없음 */
|
/* 404 NOT_FOUND : Resource 를 찾을 수 없음 */
|
||||||
|
public static TicketingException throwUserNotFound() {
|
||||||
|
throw new TicketingException(USER_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
public static TicketingException throwEmailNotFound() {
|
public static TicketingException throwEmailNotFound() {
|
||||||
throw new TicketingException(EMAIL_NOT_FOUND);
|
throw new TicketingException(EMAIL_NOT_FOUND);
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import org.springframework.http.HttpMethod;
|
|||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
|
||||||
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.validation.BindException;
|
import org.springframework.validation.BindException;
|
||||||
import org.springframework.validation.ObjectError;
|
import org.springframework.validation.ObjectError;
|
||||||
@@ -212,17 +211,6 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
|
|||||||
return ResponseEntity.status(response.getStatus()).headers(new HttpHeaders()).body(response);
|
return ResponseEntity.status(response.getStatus()).headers(new HttpHeaders()).body(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 이메일이 존재하지 않을 경우
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(value = BadCredentialsException.class)
|
|
||||||
protected ResponseEntity<ErrorResponse> handleBadCredentialsException(BadCredentialsException ex) {
|
|
||||||
log.error("BadCredentialsException :: ", ex);
|
|
||||||
|
|
||||||
ErrorResponse response = new ErrorResponse(UNAUTHORIZED, ex.getLocalizedMessage(), "아이디 혹은 패스워드가 일치하지 않습니다.");
|
|
||||||
return ResponseEntity.status(response.getStatus()).headers(new HttpHeaders()).body(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 인증 정보가 없을 때
|
* 인증 정보가 없을 때
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -33,15 +33,12 @@ public class PaymentCache {
|
|||||||
|
|
||||||
private Long paymentNumber;
|
private Long paymentNumber;
|
||||||
|
|
||||||
private Integer totalAmount;
|
public PaymentCache(String email, String movieTitle, String tid, List<Long> ticketIds, Long userAlternateId, Long paymentNumber) {
|
||||||
|
|
||||||
public PaymentCache(String email, String movieTitle, String tid, List<Long> ticketIds, Long userAlternateId, Long paymentNumber, Integer totalAmount) {
|
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.movieTitle = movieTitle;
|
this.movieTitle = movieTitle;
|
||||||
this.tid = tid;
|
this.tid = tid;
|
||||||
this.ticketIds = ticketIds;
|
this.ticketIds = ticketIds;
|
||||||
this.userAlternateId = userAlternateId;
|
this.userAlternateId = userAlternateId;
|
||||||
this.paymentNumber = paymentNumber;
|
this.paymentNumber = paymentNumber;
|
||||||
this.totalAmount = totalAmount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
package com.ticketing.server.movie.aop;
|
|
||||||
|
|
||||||
import static com.ticketing.server.movie.domain.TicketLock.LOCK_VALUE;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.ErrorCode;
|
|
||||||
import com.ticketing.server.global.exception.TicketingException;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketIdsDTO;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.Around;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Aspect
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class TicketLockAspect {
|
|
||||||
|
|
||||||
private final RedisTemplate<String, Object> redisTemplate;
|
|
||||||
|
|
||||||
@Around("execution(* com.ticketing.server.movie.service.TicketLockService.*(..))")
|
|
||||||
public Object ticketLock(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
||||||
List<String> ticketLockIds = getTicketLockIds(joinPoint);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!isEveryTicketIdLock(ticketLockIds)) {
|
|
||||||
throw new TicketingException(ErrorCode.BAD_REQUEST_TICKET_SOLD);
|
|
||||||
}
|
|
||||||
|
|
||||||
return joinPoint.proceed();
|
|
||||||
} finally {
|
|
||||||
ticketIdsUnlock(ticketLockIds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isEveryTicketIdLock(List<String> ids) {
|
|
||||||
for (String id : ids) {
|
|
||||||
if (Boolean.FALSE.equals(redisTemplate.opsForValue().setIfAbsent(id, LOCK_VALUE.getValue(), 5, TimeUnit.MINUTES))) {
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Long ticketIdsUnlock(List<String> ids) {
|
|
||||||
return redisTemplate.delete(ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getTicketLockIds(ProceedingJoinPoint joinPoint) {
|
|
||||||
for (Object arg : joinPoint.getArgs()) {
|
|
||||||
if (arg instanceof TicketIdsDTO) {
|
|
||||||
TicketIdsDTO ids = (TicketIdsDTO) arg;
|
|
||||||
return ids.makeTicketLockIds();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new TicketingException(ErrorCode.EMPTY_TICKET_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -8,12 +8,11 @@ import com.ticketing.server.movie.application.response.MovieDeleteResponse;
|
|||||||
import com.ticketing.server.movie.application.response.MovieListResponse;
|
import com.ticketing.server.movie.application.response.MovieListResponse;
|
||||||
import com.ticketing.server.movie.application.response.MovieInfoResponse;
|
import com.ticketing.server.movie.application.response.MovieInfoResponse;
|
||||||
import com.ticketing.server.movie.service.dto.DeletedMovieDTO;
|
import com.ticketing.server.movie.service.dto.DeletedMovieDTO;
|
||||||
import com.ticketing.server.movie.service.dto.MovieDTO;
|
import com.ticketing.server.movie.service.dto.MovieListDTO;
|
||||||
import com.ticketing.server.movie.service.dto.RegisteredMovieDTO;
|
import com.ticketing.server.movie.service.dto.RegisteredMovieDTO;
|
||||||
import com.ticketing.server.movie.service.interfaces.MovieService;
|
import com.ticketing.server.movie.service.interfaces.MovieService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import java.util.List;
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -52,11 +51,11 @@ public class MovieController {
|
|||||||
@GetMapping()
|
@GetMapping()
|
||||||
@ApiOperation(value = "영화 목록 조회")
|
@ApiOperation(value = "영화 목록 조회")
|
||||||
public ResponseEntity<MovieListResponse> getMovies() {
|
public ResponseEntity<MovieListResponse> getMovies() {
|
||||||
List<MovieDTO> movieDtos = movieService.getMovies();
|
MovieListDTO movieListDto = movieService.getMovies();
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(
|
.body(
|
||||||
new MovieListResponse(movieDtos)
|
movieListDto.toResponse()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,13 @@ import static com.ticketing.server.user.domain.UserGrade.ROLES.STAFF;
|
|||||||
import com.ticketing.server.movie.application.request.MovieTimeRegisterRequest;
|
import com.ticketing.server.movie.application.request.MovieTimeRegisterRequest;
|
||||||
import com.ticketing.server.movie.application.response.MovieTimeInfoResponse;
|
import com.ticketing.server.movie.application.response.MovieTimeInfoResponse;
|
||||||
import com.ticketing.server.movie.application.response.MovieTimeListResponse;
|
import com.ticketing.server.movie.application.response.MovieTimeListResponse;
|
||||||
import com.ticketing.server.movie.service.dto.MovieTimeDTO;
|
import com.ticketing.server.movie.service.dto.MovieTimeListDTO;
|
||||||
import com.ticketing.server.movie.service.dto.RegisteredMovieTimeDTO;
|
import com.ticketing.server.movie.service.dto.RegisteredMovieTimeDTO;
|
||||||
import com.ticketing.server.movie.service.interfaces.MovieTimeService;
|
import com.ticketing.server.movie.service.interfaces.MovieTimeService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -59,11 +58,11 @@ public class MovieTimeController {
|
|||||||
public ResponseEntity<MovieTimeListResponse> getMovieTimes(
|
public ResponseEntity<MovieTimeListResponse> getMovieTimes(
|
||||||
@ApiParam(value = "영화 ID", required = true) @RequestParam @NotNull Long movieId,
|
@ApiParam(value = "영화 ID", required = true) @RequestParam @NotNull Long movieId,
|
||||||
@ApiParam(value = "상영 날짜", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate runningDate) {
|
@ApiParam(value = "상영 날짜", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate runningDate) {
|
||||||
List<MovieTimeDTO> movieTimeDtos = movieTimeService.getMovieTimes(movieId, runningDate);
|
MovieTimeListDTO movieTimeListDto = movieTimeService.getMovieTimes(movieId, runningDate);
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(
|
.body(
|
||||||
new MovieTimeListResponse(movieTimeDtos)
|
movieTimeListDto.toResponse()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,16 @@
|
|||||||
package com.ticketing.server.movie.application;
|
package com.ticketing.server.movie.application;
|
||||||
|
|
||||||
import static com.ticketing.server.user.domain.UserGrade.ROLES.USER;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||||
import com.ticketing.server.movie.application.response.TicketListResponse;
|
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketDTO;
|
|
||||||
import com.ticketing.server.movie.service.interfaces.TicketService;
|
import com.ticketing.server.movie.service.interfaces.TicketService;
|
||||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
|
||||||
import io.swagger.annotations.ApiParam;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.annotation.Secured;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -29,28 +21,12 @@ public class TicketController {
|
|||||||
|
|
||||||
private final TicketService ticketService;
|
private final TicketService ticketService;
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
@Secured(USER)
|
|
||||||
public ResponseEntity<TicketListResponse> getTickets(
|
|
||||||
@ApiParam(value = "영화 시간표 ID", required = true) @RequestParam @NotNull Long movieTimeId) {
|
|
||||||
List<TicketDTO> tickets = ticketService.getTickets(movieTimeId);
|
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
|
||||||
.body(
|
|
||||||
new TicketListResponse(tickets)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/payments/{paymentId}")
|
@GetMapping("/payments/{paymentId}")
|
||||||
@Secured(USER)
|
public ResponseEntity<TicketDetailsResponse> findTicketsByPaymentId(@PathVariable("paymentId") @NotNull Long paymentId) {
|
||||||
public ResponseEntity<TicketDetailsResponse> findTicketsByPaymentId(
|
TicketDetailsDTO tickets = ticketService.findTicketsByPaymentId(paymentId);
|
||||||
@PathVariable("paymentId") @NotNull Long paymentId) {
|
|
||||||
List<TicketDetailDTO> tickets = ticketService.findTicketsByPaymentId(paymentId);
|
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(
|
.body(tickets.toResponse());
|
||||||
new TicketDetailsResponse(tickets)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import lombok.Getter;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class MovieListResponse {
|
public class MovieListResponse {
|
||||||
|
|
||||||
@ApiModelProperty(value = "영화 목록")
|
@ApiModelProperty(value = "영화 제목")
|
||||||
private List<MovieDTO> movieDtos;
|
private List<MovieDTO> movieDtos;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import lombok.Getter;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class MovieTimeListResponse {
|
public class MovieTimeListResponse {
|
||||||
|
|
||||||
@ApiModelProperty(value = "영화 시간표 목록")
|
@ApiModelProperty(value = "영화 시간표 정보")
|
||||||
private List<MovieTimeDTO> movieTimeDtos;
|
private List<MovieTimeDTO> movieTimeDtos;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.ticketing.server.movie.application.response;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketDTO;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class TicketListResponse {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "티켓 목록")
|
|
||||||
private List<TicketDTO> ticketDtos;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,8 @@
|
|||||||
package com.ticketing.server.movie.domain;
|
package com.ticketing.server.movie.domain;
|
||||||
|
|
||||||
import static com.ticketing.server.global.exception.ErrorCode.BAD_REQUEST_PAYMENT_CANCEL;
|
|
||||||
import static com.ticketing.server.global.exception.ErrorCode.DUPLICATE_PAYMENT;
|
|
||||||
import static com.ticketing.server.global.exception.ErrorCode.NOT_REFUNDABLE_SEAT;
|
|
||||||
import static com.ticketing.server.global.exception.ErrorCode.NOT_REFUNDABLE_TIME;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
||||||
import com.ticketing.server.global.exception.ErrorCode;
|
import com.ticketing.server.global.exception.ErrorCode;
|
||||||
import com.ticketing.server.global.exception.TicketingException;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
import javax.persistence.Enumerated;
|
import javax.persistence.Enumerated;
|
||||||
@@ -33,7 +26,7 @@ public class Ticket extends AbstractEntity {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "movie_time_id", referencedColumnName = "id", updatable = false)
|
@JoinColumn(name = "movie_times_id", referencedColumnName = "id", updatable = false)
|
||||||
private MovieTime movieTime;
|
private MovieTime movieTime;
|
||||||
|
|
||||||
private Long paymentId;
|
private Long paymentId;
|
||||||
@@ -62,7 +55,7 @@ public class Ticket extends AbstractEntity {
|
|||||||
|
|
||||||
public Ticket makeReservation() {
|
public Ticket makeReservation() {
|
||||||
if (!TicketStatus.SALE.equals(status)) {
|
if (!TicketStatus.SALE.equals(status)) {
|
||||||
throw new TicketingException(DUPLICATE_PAYMENT);
|
throw ErrorCode.throwDuplicatePayment();
|
||||||
}
|
}
|
||||||
|
|
||||||
status = TicketStatus.RESERVATION;
|
status = TicketStatus.RESERVATION;
|
||||||
@@ -71,7 +64,7 @@ public class Ticket extends AbstractEntity {
|
|||||||
|
|
||||||
public Ticket makeSold(Long paymentId) {
|
public Ticket makeSold(Long paymentId) {
|
||||||
if (TicketStatus.SOLD.equals(status)) {
|
if (TicketStatus.SOLD.equals(status)) {
|
||||||
throw new TicketingException(DUPLICATE_PAYMENT);
|
throw ErrorCode.throwDuplicatePayment();
|
||||||
}
|
}
|
||||||
|
|
||||||
status = TicketStatus.SOLD;
|
status = TicketStatus.SOLD;
|
||||||
@@ -81,30 +74,10 @@ public class Ticket extends AbstractEntity {
|
|||||||
|
|
||||||
public Ticket cancel() {
|
public Ticket cancel() {
|
||||||
if (!TicketStatus.RESERVATION.equals(status)) {
|
if (!TicketStatus.RESERVATION.equals(status)) {
|
||||||
throw new TicketingException(BAD_REQUEST_PAYMENT_CANCEL);
|
throw ErrorCode.throwBadRequestPaymentCancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
status = TicketStatus.SALE;
|
status = TicketStatus.SALE;
|
||||||
paymentId = null;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Ticket refund(LocalDateTime dateTime) {
|
|
||||||
long seconds = ChronoUnit.SECONDS.between(dateTime, getStartAt());
|
|
||||||
if (600L > seconds) {
|
|
||||||
throw new TicketingException(NOT_REFUNDABLE_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
return refund();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Ticket refund() {
|
|
||||||
if (!TicketStatus.SOLD.equals(status)) {
|
|
||||||
throw new TicketingException(NOT_REFUNDABLE_SEAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = TicketStatus.SALE;
|
|
||||||
paymentId = null;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public enum TicketLock {
|
|
||||||
|
|
||||||
LOCK_KEY("TicketLock"),
|
|
||||||
LOCK_VALUE("lock");
|
|
||||||
|
|
||||||
private final String value;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.ticketing.server.movie.domain.repository;
|
package com.ticketing.server.movie.domain.repository;
|
||||||
|
|
||||||
import com.ticketing.server.movie.domain.Movie;
|
import com.ticketing.server.movie.domain.Movie;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@@ -16,8 +17,8 @@ public interface MovieRepository extends JpaRepository<Movie, Long> {
|
|||||||
|
|
||||||
@Query(value = "SELECT m "
|
@Query(value = "SELECT m "
|
||||||
+ "FROM Movie m "
|
+ "FROM Movie m "
|
||||||
+ "WHERE m.title = :title "
|
+ "WHERE title = :title "
|
||||||
+ "AND m.deletedAt IS NULL")
|
+ "AND deleted_at IS NULL")
|
||||||
Optional<Movie> findValidMovieWithTitle(String title);
|
Optional<Movie> findValidMovieWithTitle(String title);
|
||||||
|
|
||||||
@Query(value = "SELECT * "
|
@Query(value = "SELECT * "
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.ticketing.server.movie.domain.repository;
|
package com.ticketing.server.movie.domain.repository;
|
||||||
|
|
||||||
import com.ticketing.server.movie.domain.MovieTime;
|
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
import com.ticketing.server.movie.domain.Ticket;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@@ -12,16 +11,8 @@ import org.springframework.stereotype.Repository;
|
|||||||
public interface TicketRepository extends JpaRepository<Ticket, Long> {
|
public interface TicketRepository extends JpaRepository<Ticket, Long> {
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
value = "SELECT t "
|
value =
|
||||||
+ "FROM Ticket t "
|
"SELECT t "
|
||||||
+ "JOIN FETCH t.seat s "
|
|
||||||
+ "WHERE t.movieTime = :movieTime "
|
|
||||||
+ "AND t.deletedAt IS NULL"
|
|
||||||
)
|
|
||||||
List<Ticket> findValidTickets(MovieTime movieTime);
|
|
||||||
|
|
||||||
@Query(
|
|
||||||
value = "SELECT t "
|
|
||||||
+ "FROM Ticket t "
|
+ "FROM Ticket t "
|
||||||
+ "JOIN FETCH t.movieTime mt "
|
+ "JOIN FETCH t.movieTime mt "
|
||||||
+ "JOIN FETCH t.seat s "
|
+ "JOIN FETCH t.seat s "
|
||||||
@@ -31,7 +22,8 @@ public interface TicketRepository extends JpaRepository<Ticket, Long> {
|
|||||||
List<Ticket> findTicketFetchJoinByPaymentId(@Param("paymentId") Long paymentId);
|
List<Ticket> findTicketFetchJoinByPaymentId(@Param("paymentId") Long paymentId);
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
value = "SELECT t "
|
value =
|
||||||
|
"SELECT t "
|
||||||
+ "FROM Ticket t "
|
+ "FROM Ticket t "
|
||||||
+ "JOIN FETCH t.movieTime mt "
|
+ "JOIN FETCH t.movieTime mt "
|
||||||
+ "JOIN FETCH t.seat s "
|
+ "JOIN FETCH t.seat s "
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.ticketing.server.movie.domain.Movie;
|
|||||||
import com.ticketing.server.movie.domain.repository.MovieRepository;
|
import com.ticketing.server.movie.domain.repository.MovieRepository;
|
||||||
import com.ticketing.server.movie.service.dto.DeletedMovieDTO;
|
import com.ticketing.server.movie.service.dto.DeletedMovieDTO;
|
||||||
import com.ticketing.server.movie.service.dto.MovieDTO;
|
import com.ticketing.server.movie.service.dto.MovieDTO;
|
||||||
|
import com.ticketing.server.movie.service.dto.MovieListDTO;
|
||||||
import com.ticketing.server.movie.service.dto.RegisteredMovieDTO;
|
import com.ticketing.server.movie.service.dto.RegisteredMovieDTO;
|
||||||
import com.ticketing.server.movie.service.interfaces.MovieService;
|
import com.ticketing.server.movie.service.interfaces.MovieService;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -38,12 +39,14 @@ public class MovieServiceImpl implements MovieService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MovieDTO> getMovies() {
|
public MovieListDTO getMovies() {
|
||||||
List<Movie> movies = movieRepository.findValidMovies();
|
List<Movie> movies = movieRepository.findValidMovies();
|
||||||
|
|
||||||
return movies.stream()
|
List<MovieDTO> movieDtos = movies.stream()
|
||||||
.map(movie -> movie.toMovieDTO())
|
.map(movie -> movie.toMovieDTO())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return new MovieListDTO(movieDtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import com.ticketing.server.movie.domain.repository.MovieRepository;
|
|||||||
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
||||||
import com.ticketing.server.movie.domain.repository.TheaterRepository;
|
import com.ticketing.server.movie.domain.repository.TheaterRepository;
|
||||||
import com.ticketing.server.movie.service.dto.MovieTimeDTO;
|
import com.ticketing.server.movie.service.dto.MovieTimeDTO;
|
||||||
|
import com.ticketing.server.movie.service.dto.MovieTimeListDTO;
|
||||||
import com.ticketing.server.movie.service.dto.MovieTimeRegisterDTO;
|
import com.ticketing.server.movie.service.dto.MovieTimeRegisterDTO;
|
||||||
|
import com.ticketing.server.movie.service.dto.RegisteredMovieDTO;
|
||||||
import com.ticketing.server.movie.service.dto.RegisteredMovieTimeDTO;
|
import com.ticketing.server.movie.service.dto.RegisteredMovieTimeDTO;
|
||||||
import com.ticketing.server.movie.service.interfaces.MovieTimeService;
|
import com.ticketing.server.movie.service.interfaces.MovieTimeService;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -36,13 +38,12 @@ public class MovieTimeServiceImpl implements MovieTimeService {
|
|||||||
public RegisteredMovieTimeDTO registerMovieTime(@Valid MovieTimeRegisterDTO movieTimeRegisterDto) {
|
public RegisteredMovieTimeDTO registerMovieTime(@Valid MovieTimeRegisterDTO movieTimeRegisterDto) {
|
||||||
Movie movie = findMovieById(movieTimeRegisterDto.getMovieId());
|
Movie movie = findMovieById(movieTimeRegisterDto.getMovieId());
|
||||||
Theater theater = findTheaterByNumber(movieTimeRegisterDto.getTheaterNumber());
|
Theater theater = findTheaterByNumber(movieTimeRegisterDto.getTheaterNumber());
|
||||||
|
|
||||||
int round = movieTimeRegisterDto.getRound();
|
int round = movieTimeRegisterDto.getRound();
|
||||||
|
|
||||||
Optional<MovieTime> movieTime =
|
Optional<MovieTime> movieTime =
|
||||||
movieTimeRepository.findByMovieAndTheaterAndRoundAndDeletedAtNull(movie, theater, round);
|
movieTimeRepository.findByMovieAndTheaterAndRoundAndDeletedAtNull(movie, theater, round);
|
||||||
|
|
||||||
if (movieTime.isEmpty()) {
|
if(movieTime.isEmpty()) {
|
||||||
MovieTime newMovieTime = movieTimeRepository.save(
|
MovieTime newMovieTime = movieTimeRepository.save(
|
||||||
new MovieTime(movie, theater, round, movieTimeRegisterDto.getStartAt())
|
new MovieTime(movie, theater, round, movieTimeRegisterDto.getStartAt())
|
||||||
);
|
);
|
||||||
@@ -54,7 +55,7 @@ public class MovieTimeServiceImpl implements MovieTimeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MovieTimeDTO> getMovieTimes(Long movieId, LocalDate runningDate) {
|
public MovieTimeListDTO getMovieTimes(Long movieId, LocalDate runningDate) {
|
||||||
Movie movie = findMovieById(movieId);
|
Movie movie = findMovieById(movieId);
|
||||||
|
|
||||||
LocalDateTime startOfDay = runningDate.atStartOfDay().plusHours(6);
|
LocalDateTime startOfDay = runningDate.atStartOfDay().plusHours(6);
|
||||||
@@ -62,9 +63,11 @@ public class MovieTimeServiceImpl implements MovieTimeService {
|
|||||||
|
|
||||||
List<MovieTime> movieTimes = movieTimeRepository.findValidMovieTimes(movie, startOfDay, endOfDay);
|
List<MovieTime> movieTimes = movieTimeRepository.findValidMovieTimes(movie, startOfDay, endOfDay);
|
||||||
|
|
||||||
return movieTimes.stream()
|
List<MovieTimeDTO> movieTimeDtos = movieTimes.stream()
|
||||||
.map(movieTime -> movieTime.toMovieTimeDTO())
|
.map(movieTime -> movieTime.toMovieTimeDTO())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return new MovieTimeListDTO(movieTimeDtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service;
|
|
||||||
|
|
||||||
import static com.ticketing.server.global.exception.ErrorCode.BAD_REQUEST_MOVIE_TIME;
|
|
||||||
import static com.ticketing.server.global.exception.ErrorCode.INVALID_TICKET_ID;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.TicketingException;
|
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
|
||||||
import com.ticketing.server.movie.domain.repository.TicketRepository;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketIdsDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketReservationDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketSoldDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketsReservationDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketsSoldDTO;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Validated
|
|
||||||
public class TicketLockService {
|
|
||||||
|
|
||||||
private final TicketRepository ticketRepository;
|
|
||||||
|
|
||||||
public TicketsReservationDTO ticketReservation(@Valid TicketIdsDTO ticketIdsDto) {
|
|
||||||
List<Ticket> tickets = getTicketsByInTicketIds(ticketIdsDto.getTicketIds());
|
|
||||||
|
|
||||||
Long firstMovieTimeId = firstMovieTimeId(tickets);
|
|
||||||
List<TicketReservationDTO> reservationDtoList = tickets.stream()
|
|
||||||
.map(Ticket::makeReservation)
|
|
||||||
.filter(ticket -> firstMovieTimeId.equals(ticket.getMovieTimeId()))
|
|
||||||
.map(TicketReservationDTO::new)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (tickets.size() != reservationDtoList.size()) {
|
|
||||||
throw new TicketingException(BAD_REQUEST_MOVIE_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new TicketsReservationDTO(firstMovieTitle(tickets), reservationDtoList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TicketsSoldDTO ticketSold(@NotNull Long paymentId, @Valid TicketIdsDTO ticketIdsDto) {
|
|
||||||
List<Ticket> tickets = getTicketsByInTicketIds(ticketIdsDto.getTicketIds());
|
|
||||||
|
|
||||||
List<TicketSoldDTO> soldDtoList = tickets.stream()
|
|
||||||
.map(ticket -> ticket.makeSold(paymentId))
|
|
||||||
.map(TicketSoldDTO::new)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
return new TicketsSoldDTO(paymentId, soldDtoList);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Ticket> getTicketsByInTicketIds(List<Long> ticketIds) {
|
|
||||||
List<Ticket> tickets = ticketRepository.findTicketFetchJoinByTicketIds(ticketIds);
|
|
||||||
|
|
||||||
if (tickets.size() != ticketIds.size()) {
|
|
||||||
throw new TicketingException(INVALID_TICKET_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
return tickets;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Long firstMovieTimeId(List<Ticket> tickets) {
|
|
||||||
Ticket ticket = tickets.get(0);
|
|
||||||
return ticket.getMovieTimeId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String firstMovieTitle(List<Ticket> tickets) {
|
|
||||||
Ticket ticket = tickets.get(0);
|
|
||||||
return ticket.getMovieTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,25 +1,18 @@
|
|||||||
package com.ticketing.server.movie.service;
|
package com.ticketing.server.movie.service;
|
||||||
|
|
||||||
import static com.ticketing.server.global.exception.ErrorCode.INVALID_TICKET_ID;
|
import com.ticketing.server.global.exception.ErrorCode;
|
||||||
import static com.ticketing.server.global.exception.ErrorCode.MOVIE_TIME_NOT_FOUND;
|
|
||||||
import static com.ticketing.server.global.exception.ErrorCode.PAYMENT_ID_NOT_FOUND;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.TicketingException;
|
|
||||||
import com.ticketing.server.global.validator.constraints.NotEmptyCollection;
|
import com.ticketing.server.global.validator.constraints.NotEmptyCollection;
|
||||||
import com.ticketing.server.movie.domain.MovieTime;
|
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
import com.ticketing.server.movie.domain.Ticket;
|
||||||
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
|
||||||
import com.ticketing.server.movie.domain.repository.TicketRepository;
|
import com.ticketing.server.movie.domain.repository.TicketRepository;
|
||||||
import com.ticketing.server.movie.service.dto.TicketDTO;
|
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketIdsDTO;
|
import com.ticketing.server.movie.service.dto.TicketReservationDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketRefundDTO;
|
import com.ticketing.server.movie.service.dto.TicketSoldDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketsCancelDTO;
|
import com.ticketing.server.movie.service.dto.TicketsCancelDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketsReservationDTO;
|
import com.ticketing.server.movie.service.dto.TicketsReservationDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketsSoldDTO;
|
import com.ticketing.server.movie.service.dto.TicketsSoldDTO;
|
||||||
import com.ticketing.server.movie.service.interfaces.TicketService;
|
import com.ticketing.server.movie.service.interfaces.TicketService;
|
||||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.UnaryOperator;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -36,44 +29,51 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
public class TicketServiceImpl implements TicketService {
|
public class TicketServiceImpl implements TicketService {
|
||||||
|
|
||||||
private final TicketRepository ticketRepository;
|
private final TicketRepository ticketRepository;
|
||||||
private final MovieTimeRepository movieTimeRepository;
|
|
||||||
private final TicketLockService ticketLockService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TicketDTO> getTickets(@NotNull Long movieTimeId) {
|
public TicketDetailsDTO findTicketsByPaymentId(@NotNull Long paymentId) {
|
||||||
MovieTime movieTime = movieTimeRepository.findById(movieTimeId)
|
|
||||||
.orElseThrow(() -> new TicketingException(MOVIE_TIME_NOT_FOUND));
|
|
||||||
|
|
||||||
return ticketRepository.findValidTickets(movieTime)
|
|
||||||
.stream()
|
|
||||||
.map(TicketDTO::new)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TicketDetailDTO> findTicketsByPaymentId(@NotNull Long paymentId) {
|
|
||||||
List<TicketDetailDTO> ticketDetails = ticketRepository.findTicketFetchJoinByPaymentId(paymentId)
|
List<TicketDetailDTO> ticketDetails = ticketRepository.findTicketFetchJoinByPaymentId(paymentId)
|
||||||
.stream()
|
.stream()
|
||||||
.map(TicketDetailDTO::new)
|
.map(TicketDetailDTO::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
if (ticketDetails.isEmpty()) {
|
if (ticketDetails.isEmpty()) {
|
||||||
throw new TicketingException(PAYMENT_ID_NOT_FOUND);
|
throw ErrorCode.throwPaymentIdNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ticketDetails;
|
return new TicketDetailsDTO(ticketDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public TicketsReservationDTO ticketReservation(@NotEmptyCollection List<Long> ticketIds) {
|
public TicketsReservationDTO ticketReservation(@NotEmptyCollection List<Long> ticketIds) {
|
||||||
return ticketLockService.ticketReservation(new TicketIdsDTO(ticketIds));
|
List<Ticket> tickets = getTicketsByInTicketIds(ticketIds);
|
||||||
|
|
||||||
|
Long firstMovieTimeId = firstMovieTimeId(tickets);
|
||||||
|
List<TicketReservationDTO> reservationDtoList = tickets.stream()
|
||||||
|
.map(Ticket::makeReservation)
|
||||||
|
.filter(ticket -> firstMovieTimeId.equals(ticket.getMovieTimeId()))
|
||||||
|
.map(TicketReservationDTO::new)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (ticketIds.size() != reservationDtoList.size()) {
|
||||||
|
throw ErrorCode.throwBadRequestMovieTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TicketsReservationDTO(firstMovieTitle(tickets), reservationDtoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public TicketsSoldDTO ticketSold(@NotNull Long paymentId, @NotEmptyCollection List<Long> ticketIds) {
|
public TicketsSoldDTO ticketSold(@NotNull Long paymentId, @NotEmptyCollection List<Long> ticketIds) {
|
||||||
return ticketLockService.ticketSold(paymentId, new TicketIdsDTO(ticketIds));
|
List<Ticket> tickets = getTicketsByInTicketIds(ticketIds);
|
||||||
|
|
||||||
|
List<TicketSoldDTO> soldDtoList = tickets.stream()
|
||||||
|
.map(ticket -> ticket.makeSold(paymentId))
|
||||||
|
.map(TicketSoldDTO::new)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return new TicketsSoldDTO(paymentId, soldDtoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -82,28 +82,27 @@ public class TicketServiceImpl implements TicketService {
|
|||||||
List<Ticket> tickets = getTicketsByInTicketIds(ticketIds);
|
List<Ticket> tickets = getTicketsByInTicketIds(ticketIds);
|
||||||
tickets.forEach(Ticket::cancel);
|
tickets.forEach(Ticket::cancel);
|
||||||
|
|
||||||
return new TicketsCancelDTO(tickets);
|
return new TicketsCancelDTO(ticketIds);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public List<TicketRefundDTO> ticketsRefund(@NotNull Long paymentId, UnaryOperator<Ticket> refund) {
|
|
||||||
List<Ticket> tickets = ticketRepository.findTicketFetchJoinByPaymentId(paymentId);
|
|
||||||
|
|
||||||
return tickets.stream()
|
|
||||||
.map(refund)
|
|
||||||
.map(TicketRefundDTO::new)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Ticket> getTicketsByInTicketIds(List<Long> ticketIds) {
|
private List<Ticket> getTicketsByInTicketIds(List<Long> ticketIds) {
|
||||||
List<Ticket> tickets = ticketRepository.findTicketFetchJoinByTicketIds(ticketIds);
|
List<Ticket> tickets = ticketRepository.findTicketFetchJoinByTicketIds(ticketIds);
|
||||||
|
|
||||||
if (tickets.size() != ticketIds.size()) {
|
if (tickets.size() != ticketIds.size()) {
|
||||||
throw new TicketingException(INVALID_TICKET_ID);
|
throw ErrorCode.throwInvalidTicketId();
|
||||||
}
|
}
|
||||||
|
|
||||||
return tickets;
|
return tickets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Long firstMovieTimeId(List<Ticket> tickets) {
|
||||||
|
Ticket ticket = tickets.get(0);
|
||||||
|
return ticket.getMovieTimeId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String firstMovieTitle(List<Ticket> tickets) {
|
||||||
|
Ticket ticket = tickets.get(0);
|
||||||
|
return ticket.getMovieTitle();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.ticketing.server.movie.service.dto;
|
||||||
|
|
||||||
|
import com.ticketing.server.movie.application.response.MovieListResponse;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MovieListDTO {
|
||||||
|
|
||||||
|
private final List<MovieDTO> movieDtos;
|
||||||
|
|
||||||
|
public MovieListResponse toResponse() {
|
||||||
|
return new MovieListResponse(movieDtos);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.ticketing.server.movie.service.dto;
|
||||||
|
|
||||||
|
import com.ticketing.server.movie.application.response.MovieTimeListResponse;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MovieTimeListDTO {
|
||||||
|
|
||||||
|
private final List<MovieTimeDTO> movieTimeDtos;
|
||||||
|
|
||||||
|
public MovieTimeListResponse toResponse() {
|
||||||
|
return new MovieTimeListResponse(movieTimeDtos);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.dto;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
|
||||||
import com.ticketing.server.movie.domain.TicketStatus;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class TicketDTO {
|
|
||||||
|
|
||||||
private Long ticketId;
|
|
||||||
|
|
||||||
private Integer ticketPrice;
|
|
||||||
|
|
||||||
private Integer seatRow;
|
|
||||||
|
|
||||||
private Integer seatColumn;
|
|
||||||
|
|
||||||
private TicketStatus status;
|
|
||||||
|
|
||||||
public TicketDTO(Ticket ticket) {
|
|
||||||
this(
|
|
||||||
ticket.getId(),
|
|
||||||
ticket.getTicketPrice(),
|
|
||||||
ticket.getRow(),
|
|
||||||
ticket.getColumn(),
|
|
||||||
ticket.getStatus()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.ticketing.server.movie.service.dto;
|
||||||
|
|
||||||
|
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||||
|
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class TicketDetailsDTO {
|
||||||
|
|
||||||
|
private final List<TicketDetailDTO> ticketDetails;
|
||||||
|
|
||||||
|
public TicketDetailsResponse toResponse() {
|
||||||
|
return new TicketDetailsResponse(ticketDetails);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.dto;
|
|
||||||
|
|
||||||
import static com.ticketing.server.movie.domain.TicketLock.LOCK_KEY;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.validator.constraints.NotEmptyCollection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class TicketIdsDTO {
|
|
||||||
|
|
||||||
@NotEmptyCollection
|
|
||||||
private List<Long> ticketIds;
|
|
||||||
|
|
||||||
public List<String> makeTicketLockIds() {
|
|
||||||
return ticketIds.stream()
|
|
||||||
.map(id -> LOCK_KEY.getValue() + ":" + id)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.dto;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
|
||||||
import com.ticketing.server.movie.domain.TicketStatus;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class TicketRefundDTO {
|
|
||||||
|
|
||||||
private Long ticketId;
|
|
||||||
private TicketStatus ticketStatus;
|
|
||||||
|
|
||||||
public TicketRefundDTO(Ticket ticket) {
|
|
||||||
this(ticket.getId(), ticket.getStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,22 +1,16 @@
|
|||||||
package com.ticketing.server.movie.service.dto;
|
package com.ticketing.server.movie.service.dto;
|
||||||
|
|
||||||
import com.ticketing.server.movie.application.response.TicketCancelResponse;
|
import com.ticketing.server.movie.application.response.TicketCancelResponse;
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
public class TicketsCancelDTO {
|
public class TicketsCancelDTO {
|
||||||
|
|
||||||
private final List<Long> ticketIds;
|
private final List<Long> ticketIds;
|
||||||
|
|
||||||
public TicketsCancelDTO(List<Ticket> tickets) {
|
|
||||||
ticketIds = tickets.stream()
|
|
||||||
.map(Ticket::getId)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public TicketCancelResponse toResponse() {
|
public TicketCancelResponse toResponse() {
|
||||||
return new TicketCancelResponse(ticketIds);
|
return new TicketCancelResponse(ticketIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.dto;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class TicketsRefundResponse {
|
|
||||||
|
|
||||||
private final List<TicketRefundDTO> tickets;
|
|
||||||
|
|
||||||
public List<Long> getTicketIds() {
|
|
||||||
return tickets.stream()
|
|
||||||
.mapToLong(TicketRefundDTO::getTicketId)
|
|
||||||
.boxed()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
package com.ticketing.server.movie.service.interfaces;
|
package com.ticketing.server.movie.service.interfaces;
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.dto.DeletedMovieDTO;
|
import com.ticketing.server.movie.service.dto.DeletedMovieDTO;
|
||||||
import com.ticketing.server.movie.service.dto.MovieDTO;
|
import com.ticketing.server.movie.service.dto.MovieListDTO;
|
||||||
import com.ticketing.server.movie.service.dto.RegisteredMovieDTO;
|
import com.ticketing.server.movie.service.dto.RegisteredMovieDTO;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface MovieService {
|
public interface MovieService {
|
||||||
|
|
||||||
RegisteredMovieDTO registerMovie(String title, Long runningTime);
|
RegisteredMovieDTO registerMovie(String title, Long runningTime);
|
||||||
|
|
||||||
List<MovieDTO> getMovies();
|
MovieListDTO getMovies();
|
||||||
|
|
||||||
DeletedMovieDTO deleteMovie(Long id);
|
DeletedMovieDTO deleteMovie(Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,17 @@ package com.ticketing.server.movie.service.interfaces;
|
|||||||
|
|
||||||
import com.ticketing.server.movie.domain.Movie;
|
import com.ticketing.server.movie.domain.Movie;
|
||||||
import com.ticketing.server.movie.domain.Theater;
|
import com.ticketing.server.movie.domain.Theater;
|
||||||
import com.ticketing.server.movie.service.dto.MovieTimeDTO;
|
import com.ticketing.server.movie.service.dto.MovieTimeListDTO;
|
||||||
import com.ticketing.server.movie.service.dto.MovieTimeRegisterDTO;
|
import com.ticketing.server.movie.service.dto.MovieTimeRegisterDTO;
|
||||||
import com.ticketing.server.movie.service.dto.RegisteredMovieTimeDTO;
|
import com.ticketing.server.movie.service.dto.RegisteredMovieTimeDTO;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
public interface MovieTimeService {
|
public interface MovieTimeService {
|
||||||
|
|
||||||
RegisteredMovieTimeDTO registerMovieTime(@Valid MovieTimeRegisterDTO movieTimeRegisterDto);
|
RegisteredMovieTimeDTO registerMovieTime(@Valid MovieTimeRegisterDTO movieTimeRegisterDto);
|
||||||
|
|
||||||
List<MovieTimeDTO> getMovieTimes(Long movieId, LocalDate runningDate);
|
MovieTimeListDTO getMovieTimes(Long movieId, LocalDate runningDate);
|
||||||
|
|
||||||
Movie findMovieById(Long movieId);
|
Movie findMovieById(Long movieId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,16 @@
|
|||||||
package com.ticketing.server.movie.service.interfaces;
|
package com.ticketing.server.movie.service.interfaces;
|
||||||
|
|
||||||
import com.ticketing.server.global.validator.constraints.NotEmptyCollection;
|
import com.ticketing.server.global.validator.constraints.NotEmptyCollection;
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketIdsDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketRefundDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketsCancelDTO;
|
import com.ticketing.server.movie.service.dto.TicketsCancelDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketsReservationDTO;
|
import com.ticketing.server.movie.service.dto.TicketsReservationDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketsSoldDTO;
|
import com.ticketing.server.movie.service.dto.TicketsSoldDTO;
|
||||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.UnaryOperator;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
public interface TicketService {
|
public interface TicketService {
|
||||||
|
|
||||||
List<TicketDTO> getTickets(@NotNull Long movieTimeId);
|
TicketDetailsDTO findTicketsByPaymentId(@NotNull Long paymentId);
|
||||||
|
|
||||||
List<TicketDetailDTO> findTicketsByPaymentId(@NotNull Long paymentId);
|
|
||||||
|
|
||||||
TicketsReservationDTO ticketReservation(@NotEmptyCollection List<Long> ticketIds);
|
TicketsReservationDTO ticketReservation(@NotEmptyCollection List<Long> ticketIds);
|
||||||
|
|
||||||
@@ -26,6 +18,4 @@ public interface TicketService {
|
|||||||
|
|
||||||
TicketsCancelDTO ticketCancel(@NotEmptyCollection List<Long> ticketIds);
|
TicketsCancelDTO ticketCancel(@NotEmptyCollection List<Long> ticketIds);
|
||||||
|
|
||||||
List<TicketRefundDTO> ticketsRefund(@NotNull Long paymentId, UnaryOperator<Ticket> refund);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ MovieSetupService {
|
|||||||
initTheater();
|
initTheater();
|
||||||
initMovieTime();
|
initMovieTime();
|
||||||
initTicket();
|
initTicket();
|
||||||
// initPayment();
|
initPayment();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMovie() {
|
private void initMovie() {
|
||||||
@@ -125,8 +125,7 @@ MovieSetupService {
|
|||||||
"T2d03c9130bf237a9700",
|
"T2d03c9130bf237a9700",
|
||||||
List.of(1L, 2L),
|
List.of(1L, 2L),
|
||||||
user.getAlternateId(),
|
user.getAlternateId(),
|
||||||
124124231513245L,
|
124124231513245L
|
||||||
30_000
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Payment payment = new Payment(paymentCache, PaymentType.KAKAO_PAY, PaymentStatus.SOLD, 30_000);
|
Payment payment = new Payment(paymentCache, PaymentType.KAKAO_PAY, PaymentStatus.SOLD, 30_000);
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ package com.ticketing.server.payment.api;
|
|||||||
import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE;
|
import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE;
|
||||||
|
|
||||||
import com.ticketing.server.payment.api.dto.requset.KakaoPayApproveRequest;
|
import com.ticketing.server.payment.api.dto.requset.KakaoPayApproveRequest;
|
||||||
import com.ticketing.server.payment.api.dto.requset.KakaoPayCancelRequest;
|
|
||||||
import com.ticketing.server.payment.api.dto.requset.KakaoPayReadyRequest;
|
import com.ticketing.server.payment.api.dto.requset.KakaoPayReadyRequest;
|
||||||
import com.ticketing.server.payment.api.dto.response.KakaoPayApproveResponse;
|
import com.ticketing.server.payment.api.dto.response.KakaoPayApproveResponse;
|
||||||
import com.ticketing.server.payment.api.dto.response.KakaoPayCancelResponse;
|
|
||||||
import com.ticketing.server.payment.api.dto.response.KakaoPayReadyResponse;
|
import com.ticketing.server.payment.api.dto.response.KakaoPayReadyResponse;
|
||||||
import feign.Headers;
|
import feign.Headers;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
@@ -25,8 +23,4 @@ public interface KakaoPayClient {
|
|||||||
@Headers("Content-Type: application/x-www-form-urlencoded;charset=utf-8")
|
@Headers("Content-Type: application/x-www-form-urlencoded;charset=utf-8")
|
||||||
KakaoPayApproveResponse approve(@RequestHeader(value = "Authorization") String authorization, KakaoPayApproveRequest request);
|
KakaoPayApproveResponse approve(@RequestHeader(value = "Authorization") String authorization, KakaoPayApproveRequest request);
|
||||||
|
|
||||||
@PostMapping(value = "/cancel", consumes = APPLICATION_FORM_URLENCODED_VALUE)
|
|
||||||
@Headers("Content-Type: application/x-www-form-urlencoded;charset=utf-8")
|
|
||||||
KakaoPayCancelResponse cancel(@RequestHeader(value = "Authorization") String authorization, KakaoPayCancelRequest request);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,11 @@ package com.ticketing.server.payment.api;
|
|||||||
|
|
||||||
import com.ticketing.server.movie.application.request.TicketCancelRequest;
|
import com.ticketing.server.movie.application.request.TicketCancelRequest;
|
||||||
import com.ticketing.server.movie.application.request.TicketReservationRequest;
|
import com.ticketing.server.movie.application.request.TicketReservationRequest;
|
||||||
import com.ticketing.server.movie.application.request.TicketSoldRequest;
|
|
||||||
import com.ticketing.server.movie.application.response.TicketCancelResponse;
|
import com.ticketing.server.movie.application.response.TicketCancelResponse;
|
||||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||||
import com.ticketing.server.movie.application.response.TicketReservationResponse;
|
import com.ticketing.server.movie.application.response.TicketReservationResponse;
|
||||||
|
import com.ticketing.server.movie.application.request.TicketSoldRequest;
|
||||||
import com.ticketing.server.movie.application.response.TicketSoldResponse;
|
import com.ticketing.server.movie.application.response.TicketSoldResponse;
|
||||||
import com.ticketing.server.movie.service.dto.TicketsRefundResponse;
|
|
||||||
import com.ticketing.server.payment.api.impl.TicketsRefundRequest;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
public interface MovieClient {
|
public interface MovieClient {
|
||||||
@@ -21,8 +18,4 @@ public interface MovieClient {
|
|||||||
TicketSoldResponse ticketSold(@NotNull TicketSoldRequest request);
|
TicketSoldResponse ticketSold(@NotNull TicketSoldRequest request);
|
||||||
|
|
||||||
TicketCancelResponse ticketCancel(@NotNull TicketCancelRequest request);
|
TicketCancelResponse ticketCancel(@NotNull TicketCancelRequest request);
|
||||||
|
|
||||||
TicketsRefundResponse ticketRefundByDateTime(TicketsRefundRequest request, LocalDateTime dateTime);
|
|
||||||
|
|
||||||
TicketsRefundResponse ticketRefund(TicketsRefundRequest request);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
package com.ticketing.server.payment.api.dto.requset;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@JsonInclude(Include.NON_NULL)
|
|
||||||
public class KakaoPayCancelRequest {
|
|
||||||
|
|
||||||
@NotEmpty
|
|
||||||
private String cid = "TC0ONETIME";
|
|
||||||
|
|
||||||
@feign.form.FormProperty("cid_secret")
|
|
||||||
private String cidSecret;
|
|
||||||
|
|
||||||
@NotEmpty
|
|
||||||
private String tid;
|
|
||||||
|
|
||||||
@NotEmpty
|
|
||||||
@feign.form.FormProperty("cancel_amount")
|
|
||||||
private Integer cancelAmount;
|
|
||||||
|
|
||||||
@NotEmpty
|
|
||||||
@feign.form.FormProperty("cancel_tax_free_amount")
|
|
||||||
private Integer cancelTaxFreeAmount;
|
|
||||||
|
|
||||||
@feign.form.FormProperty("cancel_vat_amount")
|
|
||||||
private Integer cancelVatAmount;
|
|
||||||
|
|
||||||
@feign.form.FormProperty("cancel_available_amount")
|
|
||||||
private Integer cancelAvailableAmount;
|
|
||||||
|
|
||||||
private String payload;
|
|
||||||
|
|
||||||
public KakaoPayCancelRequest(String tid, Integer cancelAmount) {
|
|
||||||
this(tid, cancelAmount, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public KakaoPayCancelRequest(String tid, Integer cancelAmount, int cancelTaxFreeAmount) {
|
|
||||||
this.tid = tid;
|
|
||||||
this.cancelAmount = cancelAmount;
|
|
||||||
this.cancelTaxFreeAmount = cancelTaxFreeAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.ticketing.server.payment.api.dto.response;
|
|
||||||
|
|
||||||
import com.ticketing.server.payment.api.dto.SnakeCaseStrategy;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class ApprovedCancelAmount extends SnakeCaseStrategy {
|
|
||||||
|
|
||||||
private Integer total;
|
|
||||||
private Integer taxFree;
|
|
||||||
private Integer vat;
|
|
||||||
private Integer point;
|
|
||||||
private Integer discount;
|
|
||||||
private Integer greenDeposit;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.ticketing.server.payment.api.dto.response;
|
|
||||||
|
|
||||||
import com.ticketing.server.payment.api.dto.SnakeCaseStrategy;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class CancelAvailableAmount extends SnakeCaseStrategy {
|
|
||||||
|
|
||||||
private Integer total;
|
|
||||||
private Integer taxFree;
|
|
||||||
private Integer vat;
|
|
||||||
private Integer point;
|
|
||||||
private Integer discount;
|
|
||||||
private Integer greenDeposit;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.ticketing.server.payment.api.dto.response;
|
|
||||||
|
|
||||||
import com.ticketing.server.payment.api.dto.SnakeCaseStrategy;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class CanceledAmount extends SnakeCaseStrategy {
|
|
||||||
|
|
||||||
private Integer total;
|
|
||||||
private Integer taxFree;
|
|
||||||
private Integer vat;
|
|
||||||
private Integer point;
|
|
||||||
private Integer discount;
|
|
||||||
private Integer greenDeposit;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package com.ticketing.server.payment.api.dto.response;
|
|
||||||
|
|
||||||
import com.ticketing.server.payment.api.dto.SnakeCaseStrategy;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class KakaoPayCancelResponse extends SnakeCaseStrategy {
|
|
||||||
|
|
||||||
private String aid;
|
|
||||||
|
|
||||||
private String tid;
|
|
||||||
|
|
||||||
private String cid;
|
|
||||||
|
|
||||||
private String status;
|
|
||||||
|
|
||||||
private String partnerOrderId;
|
|
||||||
|
|
||||||
private String partnerUserId;
|
|
||||||
|
|
||||||
private String paymentMethodType;
|
|
||||||
|
|
||||||
private Amount amount;
|
|
||||||
|
|
||||||
private ApprovedCancelAmount approvedCancelAmount;
|
|
||||||
|
|
||||||
private CanceledAmount canceledAmount;
|
|
||||||
|
|
||||||
private CancelAvailableAmount cancelAvailableAmount;
|
|
||||||
|
|
||||||
private String itemName;
|
|
||||||
|
|
||||||
private String itemCode;
|
|
||||||
|
|
||||||
private Integer quantity;
|
|
||||||
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
|
|
||||||
private LocalDateTime approvedAt;
|
|
||||||
|
|
||||||
private LocalDateTime canceledAt;
|
|
||||||
|
|
||||||
private String payload;
|
|
||||||
|
|
||||||
public Integer getTotalAmount() {
|
|
||||||
return amount.getTotal();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -7,17 +7,12 @@ import com.ticketing.server.movie.application.response.TicketCancelResponse;
|
|||||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||||
import com.ticketing.server.movie.application.response.TicketReservationResponse;
|
import com.ticketing.server.movie.application.response.TicketReservationResponse;
|
||||||
import com.ticketing.server.movie.application.response.TicketSoldResponse;
|
import com.ticketing.server.movie.application.response.TicketSoldResponse;
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketRefundDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketsCancelDTO;
|
import com.ticketing.server.movie.service.dto.TicketsCancelDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketsRefundResponse;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketsReservationDTO;
|
import com.ticketing.server.movie.service.dto.TicketsReservationDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketsSoldDTO;
|
import com.ticketing.server.movie.service.dto.TicketsSoldDTO;
|
||||||
import com.ticketing.server.movie.service.interfaces.TicketService;
|
import com.ticketing.server.movie.service.interfaces.TicketService;
|
||||||
import com.ticketing.server.payment.api.MovieClient;
|
import com.ticketing.server.payment.api.MovieClient;
|
||||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -32,8 +27,8 @@ public class MovieClientImpl implements MovieClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TicketDetailsResponse getTicketsByPaymentId(@NotNull Long paymentId) {
|
public TicketDetailsResponse getTicketsByPaymentId(@NotNull Long paymentId) {
|
||||||
List<TicketDetailDTO> ticketDetails = ticketService.findTicketsByPaymentId(paymentId);
|
TicketDetailsDTO ticketDetails = ticketService.findTicketsByPaymentId(paymentId);
|
||||||
return new TicketDetailsResponse(ticketDetails);
|
return ticketDetails.toResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -54,16 +49,4 @@ public class MovieClientImpl implements MovieClient {
|
|||||||
return ticketsCancelDto.toResponse();
|
return ticketsCancelDto.toResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TicketsRefundResponse ticketRefundByDateTime(TicketsRefundRequest request, LocalDateTime dateTime) {
|
|
||||||
List<TicketRefundDTO> ticketRefundDTOS = ticketService.ticketsRefund(request.getPaymentId(), ticket -> ticket.refund(dateTime));
|
|
||||||
return new TicketsRefundResponse(ticketRefundDTOS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TicketsRefundResponse ticketRefund(TicketsRefundRequest request) {
|
|
||||||
List<TicketRefundDTO> ticketRefundDtos = ticketService.ticketsRefund(request.getPaymentId(), Ticket::refund);
|
|
||||||
return new TicketsRefundResponse(ticketRefundDtos);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.ticketing.server.payment.api.impl;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class TicketsRefundRequest {
|
|
||||||
|
|
||||||
private final Long paymentId;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,25 +1,18 @@
|
|||||||
package com.ticketing.server.payment.application;
|
package com.ticketing.server.payment.application;
|
||||||
|
|
||||||
import static com.ticketing.server.user.domain.UserGrade.ROLES.STAFF;
|
|
||||||
import static com.ticketing.server.user.domain.UserGrade.ROLES.USER;
|
|
||||||
|
|
||||||
import com.ticketing.server.payment.application.request.PaymentReadyRequest;
|
import com.ticketing.server.payment.application.request.PaymentReadyRequest;
|
||||||
import com.ticketing.server.payment.application.request.PaymentRefundRequest;
|
|
||||||
import com.ticketing.server.payment.application.response.PaymentCancelResponse;
|
|
||||||
import com.ticketing.server.payment.application.response.PaymentCompleteResponse;
|
|
||||||
import com.ticketing.server.payment.application.response.PaymentDetailResponse;
|
import com.ticketing.server.payment.application.response.PaymentDetailResponse;
|
||||||
import com.ticketing.server.payment.application.response.PaymentRefundResponse;
|
|
||||||
import com.ticketing.server.payment.application.response.SimplePaymentsResponse;
|
import com.ticketing.server.payment.application.response.SimplePaymentsResponse;
|
||||||
import com.ticketing.server.payment.service.AdminKakaoPayRefundService;
|
|
||||||
import com.ticketing.server.payment.service.MyKakaoPayRefundService;
|
|
||||||
import com.ticketing.server.payment.service.dto.PaymentCancelDTO;
|
import com.ticketing.server.payment.service.dto.PaymentCancelDTO;
|
||||||
|
import com.ticketing.server.payment.application.response.PaymentCancelResponse;
|
||||||
import com.ticketing.server.payment.service.dto.PaymentCompleteDTO;
|
import com.ticketing.server.payment.service.dto.PaymentCompleteDTO;
|
||||||
|
import com.ticketing.server.payment.application.response.PaymentCompleteResponse;
|
||||||
import com.ticketing.server.payment.service.dto.PaymentDetailDTO;
|
import com.ticketing.server.payment.service.dto.PaymentDetailDTO;
|
||||||
import com.ticketing.server.payment.service.dto.PaymentReadyDTO;
|
import com.ticketing.server.payment.service.dto.PaymentReadyDTO;
|
||||||
import com.ticketing.server.payment.service.dto.PaymentRefundDTO;
|
|
||||||
import com.ticketing.server.payment.service.dto.SimplePaymentsDTO;
|
import com.ticketing.server.payment.service.dto.SimplePaymentsDTO;
|
||||||
import com.ticketing.server.payment.service.interfaces.PaymentApisService;
|
import com.ticketing.server.payment.service.interfaces.PaymentApisService;
|
||||||
import com.ticketing.server.payment.service.interfaces.PaymentService;
|
import com.ticketing.server.payment.service.interfaces.PaymentService;
|
||||||
|
import com.ticketing.server.user.domain.UserGrade;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -44,11 +37,9 @@ public class PaymentController {
|
|||||||
|
|
||||||
private final PaymentApisService paymentApisService;
|
private final PaymentApisService paymentApisService;
|
||||||
private final PaymentService paymentService;
|
private final PaymentService paymentService;
|
||||||
private final AdminKakaoPayRefundService adminKakaoPayRefundService;
|
|
||||||
private final MyKakaoPayRefundService myKakaoPayRefundService;
|
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Secured(USER)
|
@Secured(UserGrade.ROLES.USER)
|
||||||
public ResponseEntity<SimplePaymentsResponse> simplePayments(@NotNull Long userAlternateId) {
|
public ResponseEntity<SimplePaymentsResponse> simplePayments(@NotNull Long userAlternateId) {
|
||||||
SimplePaymentsDTO simplePayments = paymentService.findSimplePayments(userAlternateId);
|
SimplePaymentsDTO simplePayments = paymentService.findSimplePayments(userAlternateId);
|
||||||
|
|
||||||
@@ -57,7 +48,7 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/detail")
|
@GetMapping("/detail")
|
||||||
@Secured(USER)
|
@Secured(UserGrade.ROLES.USER)
|
||||||
public ResponseEntity<PaymentDetailResponse> detail(@NotNull Long paymentId) {
|
public ResponseEntity<PaymentDetailResponse> detail(@NotNull Long paymentId) {
|
||||||
PaymentDetailDTO paymentDetail = paymentApisService.findPaymentDetail(paymentId);
|
PaymentDetailDTO paymentDetail = paymentApisService.findPaymentDetail(paymentId);
|
||||||
|
|
||||||
@@ -66,7 +57,7 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/ready")
|
@PostMapping("/ready")
|
||||||
@Secured(USER)
|
@Secured(UserGrade.ROLES.USER)
|
||||||
public ResponseEntity<PaymentReadyDTO> ready(@RequestBody @Valid PaymentReadyRequest request) {
|
public ResponseEntity<PaymentReadyDTO> ready(@RequestBody @Valid PaymentReadyRequest request) {
|
||||||
PaymentReadyDTO paymentReadyDto = paymentApisService.ready(request.getTicketIds());
|
PaymentReadyDTO paymentReadyDto = paymentApisService.ready(request.getTicketIds());
|
||||||
|
|
||||||
@@ -75,7 +66,7 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/complete")
|
@GetMapping("/complete")
|
||||||
@Secured(USER)
|
@Secured(UserGrade.ROLES.USER)
|
||||||
public ResponseEntity<PaymentCompleteResponse> complete(
|
public ResponseEntity<PaymentCompleteResponse> complete(
|
||||||
@AuthenticationPrincipal UserDetails userRequest,
|
@AuthenticationPrincipal UserDetails userRequest,
|
||||||
@RequestParam("pg_token") String pgToken) {
|
@RequestParam("pg_token") String pgToken) {
|
||||||
@@ -86,7 +77,7 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/cancel")
|
@GetMapping("/cancel")
|
||||||
@Secured(USER)
|
@Secured(UserGrade.ROLES.USER)
|
||||||
public ResponseEntity<PaymentCancelResponse> cancel(@AuthenticationPrincipal UserDetails userRequest) {
|
public ResponseEntity<PaymentCancelResponse> cancel(@AuthenticationPrincipal UserDetails userRequest) {
|
||||||
PaymentCancelDTO paymentCancelDto = paymentApisService.cancel(userRequest.getUsername());
|
PaymentCancelDTO paymentCancelDto = paymentApisService.cancel(userRequest.getUsername());
|
||||||
|
|
||||||
@@ -94,22 +85,4 @@ public class PaymentController {
|
|||||||
.body(paymentCancelDto.toResponse());
|
.body(paymentCancelDto.toResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/refund")
|
|
||||||
@Secured(USER)
|
|
||||||
public ResponseEntity<PaymentRefundResponse> refund(@RequestBody @Valid PaymentRefundRequest request) {
|
|
||||||
PaymentRefundDTO paymentRefundDto = myKakaoPayRefundService.refund(request.getPaymentId());
|
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
|
||||||
.body(paymentRefundDto.toResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/staff/refund")
|
|
||||||
@Secured(STAFF)
|
|
||||||
public ResponseEntity<PaymentRefundResponse> adminRefund(@RequestBody @Valid PaymentRefundRequest request) {
|
|
||||||
PaymentRefundDTO paymentRefundDto = adminKakaoPayRefundService.refund(request.getPaymentId());
|
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
|
||||||
.body(paymentRefundDto.toResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.ticketing.server.payment.application.request;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class PaymentRefundRequest {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Long paymentId;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.ticketing.server.payment.application.response;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PaymentRefundResponse {
|
|
||||||
|
|
||||||
private Long paymentId;
|
|
||||||
private List<Long> ticketIds;
|
|
||||||
private String movieTitle;
|
|
||||||
private Integer cancelAmount;
|
|
||||||
private LocalDateTime canceledAt;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -82,7 +82,4 @@ public class Payment extends AbstractEntity {
|
|||||||
this.totalPrice = totalPrice;
|
this.totalPrice = totalPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refund() {
|
|
||||||
status = PaymentStatus.REFUNDED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.ticketing.server.payment.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.ErrorCode;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketsRefundResponse;
|
|
||||||
import com.ticketing.server.payment.api.KakaoPayClient;
|
|
||||||
import com.ticketing.server.payment.api.KakaoPayProperties;
|
|
||||||
import com.ticketing.server.payment.api.MovieClient;
|
|
||||||
import com.ticketing.server.payment.api.impl.TicketsRefundRequest;
|
|
||||||
import com.ticketing.server.payment.domain.Payment;
|
|
||||||
import com.ticketing.server.payment.domain.repository.PaymentRepository;
|
|
||||||
import com.ticketing.server.payment.service.interfaces.AbstractKakaoPayRefund;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class AdminKakaoPayRefundService extends AbstractKakaoPayRefund {
|
|
||||||
|
|
||||||
private final PaymentRepository paymentRepository;
|
|
||||||
private final MovieClient movieClient;
|
|
||||||
|
|
||||||
public AdminKakaoPayRefundService(KakaoPayClient kakaoPayClient, KakaoPayProperties kakaoPayProperties, PaymentRepository paymentRepository, MovieClient movieClient) {
|
|
||||||
super(kakaoPayClient, kakaoPayProperties);
|
|
||||||
this.paymentRepository = paymentRepository;
|
|
||||||
this.movieClient = movieClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Payment getPayment(Long paymentId) {
|
|
||||||
return paymentRepository.findById(paymentId)
|
|
||||||
.orElseThrow(ErrorCode::throwPaymentIdNotFound);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TicketsRefundResponse movieAndPaymentRefund(Payment payment) {
|
|
||||||
TicketsRefundResponse refundResponse = movieClient.ticketRefund(new TicketsRefundRequest(payment.getId()));
|
|
||||||
payment.refund();
|
|
||||||
|
|
||||||
return refundResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package com.ticketing.server.payment.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.ErrorCode;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketsRefundResponse;
|
|
||||||
import com.ticketing.server.payment.api.KakaoPayClient;
|
|
||||||
import com.ticketing.server.payment.api.KakaoPayProperties;
|
|
||||||
import com.ticketing.server.payment.api.MovieClient;
|
|
||||||
import com.ticketing.server.payment.api.UserClient;
|
|
||||||
import com.ticketing.server.payment.api.dto.response.UserDetailResponse;
|
|
||||||
import com.ticketing.server.payment.api.impl.TicketsRefundRequest;
|
|
||||||
import com.ticketing.server.payment.domain.Payment;
|
|
||||||
import com.ticketing.server.payment.domain.repository.PaymentRepository;
|
|
||||||
import com.ticketing.server.payment.service.interfaces.AbstractKakaoPayRefund;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class MyKakaoPayRefundService extends AbstractKakaoPayRefund {
|
|
||||||
|
|
||||||
private final PaymentRepository paymentRepository;
|
|
||||||
private final MovieClient movieClient;
|
|
||||||
private final UserClient userClient;
|
|
||||||
|
|
||||||
public MyKakaoPayRefundService(KakaoPayClient kakaoPayClient, KakaoPayProperties kakaoPayProperties, PaymentRepository paymentRepository,
|
|
||||||
MovieClient movieClient, UserClient userClient) {
|
|
||||||
super(kakaoPayClient, kakaoPayProperties);
|
|
||||||
this.paymentRepository = paymentRepository;
|
|
||||||
this.movieClient = movieClient;
|
|
||||||
this.userClient = userClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Payment getPayment(Long paymentId) {
|
|
||||||
UserDetailResponse userDetail = userClient.detail();
|
|
||||||
Payment payment = paymentRepository.findById(paymentId)
|
|
||||||
.orElseThrow(ErrorCode::throwPaymentIdNotFound);
|
|
||||||
|
|
||||||
if (userDetail.hasUserAlternateId(payment)) {
|
|
||||||
throw ErrorCode.throwValidUserId();
|
|
||||||
}
|
|
||||||
|
|
||||||
return payment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TicketsRefundResponse movieAndPaymentRefund(Payment payment) {
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
|
||||||
TicketsRefundResponse refundResponse = movieClient.ticketRefundByDateTime(new TicketsRefundRequest(payment.getId()), now);
|
|
||||||
payment.refund();
|
|
||||||
|
|
||||||
return refundResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -76,10 +76,6 @@ public class PaymentApisServiceImpl implements PaymentApisService {
|
|||||||
UserDetailResponse userResponse = userClient.detail();
|
UserDetailResponse userResponse = userClient.detail();
|
||||||
Long userAlternateId = userResponse.getUserAlternateId();
|
Long userAlternateId = userResponse.getUserAlternateId();
|
||||||
|
|
||||||
// 다른 결제중인 데이터가 있다면, 예외처리
|
|
||||||
paymentCacheRepository.findByEmail(userResponse.getEmail())
|
|
||||||
.ifPresent(paymentCache -> ErrorCode.throwBadRequestPaymentReady());
|
|
||||||
|
|
||||||
// Ticket 정보 조회 - 영화제목, 티켓가격이 필요함.
|
// Ticket 정보 조회 - 영화제목, 티켓가격이 필요함.
|
||||||
TicketReservationResponse ticketResponse = movieClient.ticketReservation(new TicketReservationRequest(ticketIds));
|
TicketReservationResponse ticketResponse = movieClient.ticketReservation(new TicketReservationRequest(ticketIds));
|
||||||
String movieTitle = ticketResponse.getMovieTitle();
|
String movieTitle = ticketResponse.getMovieTitle();
|
||||||
@@ -99,18 +95,21 @@ public class PaymentApisServiceImpl implements PaymentApisService {
|
|||||||
);
|
);
|
||||||
KakaoPayReadyResponse response = kakaoPayClient.ready(kakaoPayProperties.getAuthorization(), request);
|
KakaoPayReadyResponse response = kakaoPayClient.ready(kakaoPayProperties.getAuthorization(), request);
|
||||||
|
|
||||||
paymentCacheRepository.save(
|
PaymentCache paymentReady = new PaymentCache(
|
||||||
new PaymentCache(
|
userResponse.getEmail(),
|
||||||
userResponse.getEmail(),
|
movieTitle,
|
||||||
movieTitle,
|
response.getTid(),
|
||||||
response.getTid(),
|
ticketIds,
|
||||||
ticketIds,
|
userAlternateId,
|
||||||
userAlternateId,
|
paymentNumber
|
||||||
paymentNumber,
|
|
||||||
request.getTotalAmount()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
paymentCacheRepository.findByEmail(userResponse.getEmail())
|
||||||
|
.ifPresentOrElse(
|
||||||
|
paymentCache -> ErrorCode.throwBadRequestPaymentReady()
|
||||||
|
, () -> paymentCacheRepository.save(paymentReady)
|
||||||
|
);
|
||||||
|
|
||||||
return new PaymentReadyDTO(response);
|
return new PaymentReadyDTO(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,13 +119,6 @@ public class PaymentApisServiceImpl implements PaymentApisService {
|
|||||||
PaymentCache paymentCache = paymentCacheRepository.findByEmail(email)
|
PaymentCache paymentCache = paymentCacheRepository.findByEmail(email)
|
||||||
.orElseThrow(ErrorCode::throwBadRequestPaymentComplete);
|
.orElseThrow(ErrorCode::throwBadRequestPaymentComplete);
|
||||||
|
|
||||||
Payment payment = new Payment(paymentCache, PaymentType.KAKAO_PAY, PaymentStatus.SOLD, paymentCache.getTotalAmount());
|
|
||||||
payment = paymentRepository.save(payment);
|
|
||||||
|
|
||||||
movieClient.ticketSold(new TicketSoldRequest(payment.getId(), paymentCache.getTicketIds()));
|
|
||||||
paymentCacheRepository.delete(paymentCache);
|
|
||||||
|
|
||||||
// 카카오페이 결제완료
|
|
||||||
String paymentNumberToString = paymentCache.getPaymentNumber().toString();
|
String paymentNumberToString = paymentCache.getPaymentNumber().toString();
|
||||||
String userAlternateIdToString = paymentCache.getUserAlternateId().toString();
|
String userAlternateIdToString = paymentCache.getUserAlternateId().toString();
|
||||||
KakaoPayApproveRequest kakaoPayApproveRequest = new KakaoPayApproveRequest(
|
KakaoPayApproveRequest kakaoPayApproveRequest = new KakaoPayApproveRequest(
|
||||||
@@ -140,6 +132,12 @@ public class PaymentApisServiceImpl implements PaymentApisService {
|
|||||||
kakaoPayApproveRequest
|
kakaoPayApproveRequest
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Payment payment = new Payment(paymentCache, PaymentType.KAKAO_PAY, PaymentStatus.SOLD, kakaoPayApproveResponse.getTotalAmount());
|
||||||
|
payment = paymentRepository.save(payment);
|
||||||
|
|
||||||
|
movieClient.ticketSold(new TicketSoldRequest(payment.getId(), paymentCache.getTicketIds()));
|
||||||
|
paymentCacheRepository.delete(paymentCache);
|
||||||
|
|
||||||
return new PaymentCompleteDTO(email, kakaoPayApproveResponse);
|
return new PaymentCompleteDTO(email, kakaoPayApproveResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
package com.ticketing.server.payment.service.dto;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketsRefundResponse;
|
|
||||||
import com.ticketing.server.payment.api.dto.response.KakaoPayCancelResponse;
|
|
||||||
import com.ticketing.server.payment.application.response.PaymentRefundResponse;
|
|
||||||
import com.ticketing.server.payment.domain.Payment;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PaymentRefundDTO {
|
|
||||||
|
|
||||||
private Long paymentId;
|
|
||||||
private List<Long> ticketIds;
|
|
||||||
private String movieTitle;
|
|
||||||
private Integer cancelAmount;
|
|
||||||
private LocalDateTime canceledAt;
|
|
||||||
|
|
||||||
public PaymentRefundDTO(Payment payment, KakaoPayCancelResponse kakaoPayCancelResponse, TicketsRefundResponse refundResponse) {
|
|
||||||
this(
|
|
||||||
payment.getId(),
|
|
||||||
refundResponse.getTicketIds(),
|
|
||||||
kakaoPayCancelResponse.getItemName(),
|
|
||||||
kakaoPayCancelResponse.getTotalAmount(),
|
|
||||||
kakaoPayCancelResponse.getCanceledAt()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PaymentRefundResponse toResponse() {
|
|
||||||
return new PaymentRefundResponse(
|
|
||||||
paymentId,
|
|
||||||
ticketIds,
|
|
||||||
movieTitle,
|
|
||||||
cancelAmount,
|
|
||||||
canceledAt
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package com.ticketing.server.payment.service.interfaces;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketsRefundResponse;
|
|
||||||
import com.ticketing.server.payment.api.KakaoPayClient;
|
|
||||||
import com.ticketing.server.payment.api.KakaoPayProperties;
|
|
||||||
import com.ticketing.server.payment.api.dto.requset.KakaoPayCancelRequest;
|
|
||||||
import com.ticketing.server.payment.api.dto.response.KakaoPayCancelResponse;
|
|
||||||
import com.ticketing.server.payment.domain.Payment;
|
|
||||||
import com.ticketing.server.payment.service.dto.PaymentRefundDTO;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Validated
|
|
||||||
public abstract class AbstractKakaoPayRefund {
|
|
||||||
|
|
||||||
private final KakaoPayClient kakaoPayClient;
|
|
||||||
private final KakaoPayProperties kakaoPayProperties;
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public PaymentRefundDTO refund(@NotNull Long paymentId) {
|
|
||||||
Payment payment = getPayment(paymentId);
|
|
||||||
|
|
||||||
// 내부 환불
|
|
||||||
TicketsRefundResponse refundResponse = movieAndPaymentRefund(payment);
|
|
||||||
|
|
||||||
// 카카오페이 환불
|
|
||||||
KakaoPayCancelResponse kakaoPayCancelResponse = kakaoPayClient.cancel(
|
|
||||||
kakaoPayProperties.getAuthorization(),
|
|
||||||
new KakaoPayCancelRequest(payment.getTid(), payment.getTotalPrice())
|
|
||||||
);
|
|
||||||
|
|
||||||
return new PaymentRefundDTO(payment, kakaoPayCancelResponse, refundResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Payment getPayment(Long paymentId);
|
|
||||||
|
|
||||||
protected abstract TicketsRefundResponse movieAndPaymentRefund(Payment payment);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,13 +4,9 @@ import com.ticketing.server.user.domain.UserGrade;
|
|||||||
import javax.validation.constraints.Email;
|
import javax.validation.constraints.Email;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class UserChangeGradeRequest {
|
public class UserChangeGradeRequest {
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
@NotEmpty(message = "{validation.not.empty.email}")
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.ticketing.server.user.application.response;
|
package com.ticketing.server.user.application.response;
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.UserGrade;
|
import com.ticketing.server.user.domain.UserGrade;
|
||||||
|
import com.ticketing.server.user.service.dto.UserDetailDTO;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.ticketing.server.user.service;
|
package com.ticketing.server.user.service;
|
||||||
|
|
||||||
|
import com.ticketing.server.global.exception.ErrorCode;
|
||||||
import com.ticketing.server.user.domain.User;
|
import com.ticketing.server.user.domain.User;
|
||||||
import com.ticketing.server.user.domain.repository.UserRepository;
|
import com.ticketing.server.user.domain.repository.UserRepository;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -20,7 +21,7 @@ public class CustomUserDetailsService implements UserDetailsService {
|
|||||||
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
|
||||||
return userRepository.findByEmailAndDeletedAtNull(email)
|
return userRepository.findByEmailAndDeletedAtNull(email)
|
||||||
.map(this::createUserDetails)
|
.map(this::createUserDetails)
|
||||||
.orElseThrow(() -> new UsernameNotFoundException(email));
|
.orElseThrow(ErrorCode::throwEmailNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserDetails createUserDetails(User user) {
|
private UserDetails createUserDetails(User user) {
|
||||||
|
|||||||
@@ -1,120 +0,0 @@
|
|||||||
package com.ticketing.server.global.security.jwt;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.factory.YamlPropertySourceFactory;
|
|
||||||
import com.ticketing.server.user.domain.UserGrade;
|
|
||||||
import com.ticketing.server.user.domain.UserGrade.ROLES;
|
|
||||||
import com.ticketing.server.user.service.dto.TokenDTO;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.PropertySource;
|
|
||||||
import org.springframework.mock.web.MockFilterChain;
|
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
|
||||||
@EnableConfigurationProperties(value = JwtProperties.class)
|
|
||||||
@PropertySource(value = "classpath:application.yml", factory = YamlPropertySourceFactory.class)
|
|
||||||
class JwtFilterTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JwtProperties jwtProperties;
|
|
||||||
|
|
||||||
private MockHttpServletRequest mockRequest;
|
|
||||||
private MockHttpServletResponse mockResponse;
|
|
||||||
private MockFilterChain mockFilterChain;
|
|
||||||
|
|
||||||
private JwtFilter jwtFilter;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void init() {
|
|
||||||
mockRequest = new MockHttpServletRequest();
|
|
||||||
mockResponse = new MockHttpServletResponse();
|
|
||||||
mockFilterChain = new MockFilterChain();
|
|
||||||
|
|
||||||
JwtProvider jwtProvider = new JwtProvider(jwtProperties);
|
|
||||||
jwtFilter = new JwtFilter(jwtProperties, jwtProvider);
|
|
||||||
|
|
||||||
SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(UserGrade.USER.name());
|
|
||||||
Collection<SimpleGrantedAuthority> authorities = Collections.singleton(grantedAuthority);
|
|
||||||
User user = new User(
|
|
||||||
"kdhyo98@gmail.com",
|
|
||||||
"",
|
|
||||||
authorities
|
|
||||||
);
|
|
||||||
TokenDTO tokenDto = jwtProvider.generateTokenDto(new UsernamePasswordAuthenticationToken(user, null, authorities));
|
|
||||||
mockRequest.addHeader("Authorization", "Bearer " + tokenDto.getAccessToken());
|
|
||||||
|
|
||||||
SecurityContextHolder.clearContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@DisplayName("Header 정보가 올바르지 않을 경우")
|
|
||||||
@ValueSource(strings = {"Bearer tokenTest", "Bearer", "BearertokenTest"})
|
|
||||||
void validateToken(String authorization) {
|
|
||||||
// given
|
|
||||||
mockRequest.removeHeader("Authorization");
|
|
||||||
mockRequest.addHeader("Authorization", authorization);
|
|
||||||
|
|
||||||
// when
|
|
||||||
// then
|
|
||||||
assertThatThrownBy(() -> jwtFilter.doFilterInternal(mockRequest, mockResponse, mockFilterChain))
|
|
||||||
.isInstanceOf(RuntimeException.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("다음 필터 실행")
|
|
||||||
void continuesToNextFilter() throws ServletException, IOException {
|
|
||||||
// given
|
|
||||||
MockFilterChain mockFilterChainSpy = spy(this.mockFilterChain);
|
|
||||||
|
|
||||||
// when
|
|
||||||
jwtFilter.doFilter(mockRequest, mockResponse, mockFilterChainSpy);
|
|
||||||
|
|
||||||
// then
|
|
||||||
verify(mockFilterChainSpy, times(1)).doFilter(mockRequest, mockResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("setAuthentication 데이터 확인")
|
|
||||||
void setsAuthenticationInSecurityContext() throws ServletException, IOException {
|
|
||||||
// given
|
|
||||||
SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(ROLES.USER);
|
|
||||||
Collection<GrantedAuthority> authorities = Collections.singleton(grantedAuthority);
|
|
||||||
|
|
||||||
// when
|
|
||||||
jwtFilter.doFilter(mockRequest, mockResponse, mockFilterChain);
|
|
||||||
|
|
||||||
// then
|
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
||||||
User principal = (User) authentication.getPrincipal();
|
|
||||||
assertAll(
|
|
||||||
() -> assertThat(principal.getUsername()).isEqualTo("kdhyo98@gmail.com"),
|
|
||||||
() -> assertThat(principal.getAuthorities()).isEqualTo(authorities)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.ticketing.server.movie.aop;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class TicketLockAspectTest {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,6 @@ import static org.junit.jupiter.api.Assertions.assertAll;
|
|||||||
|
|
||||||
import com.ticketing.server.global.exception.ErrorCode;
|
import com.ticketing.server.global.exception.ErrorCode;
|
||||||
import com.ticketing.server.global.exception.TicketingException;
|
import com.ticketing.server.global.exception.TicketingException;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
@@ -166,94 +165,10 @@ public class TicketTest {
|
|||||||
ticket.makeSold(123L);
|
ticket.makeSold(123L);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThatThrownBy(ticket::cancel)
|
assertThatThrownBy(() -> ticket.cancel())
|
||||||
.isInstanceOf(TicketingException.class)
|
.isInstanceOf(TicketingException.class)
|
||||||
.extracting("errorCode")
|
.extracting("errorCode")
|
||||||
.isEqualTo(ErrorCode.BAD_REQUEST_PAYMENT_CANCEL);
|
.isEqualTo(ErrorCode.BAD_REQUEST_PAYMENT_CANCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("시간 비교 환불 성공")
|
|
||||||
void refundByDateTimeSuccess() {
|
|
||||||
// given
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
|
||||||
LocalDateTime dateTime = LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 7, 50);
|
|
||||||
Ticket ticket = tickets.get(0);
|
|
||||||
|
|
||||||
// when
|
|
||||||
ticket.makeSold(123L);
|
|
||||||
ticket.refund(dateTime);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertAll(
|
|
||||||
() -> assertThat(ticket.getStatus()).isEqualTo(TicketStatus.SALE),
|
|
||||||
() -> assertThat(ticket.getPaymentId()).isNull()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("시간 비교 환불 실패 - 상영시작 시간 10분보다 작을경우")
|
|
||||||
void refundByDateTimeFail() {
|
|
||||||
// given
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
|
||||||
LocalDateTime dateTime = LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 7, 51);
|
|
||||||
Ticket ticket = tickets.get(0);
|
|
||||||
|
|
||||||
// when
|
|
||||||
ticket.makeSold(123L);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThatThrownBy(() -> ticket.refund(dateTime))
|
|
||||||
.isInstanceOf(TicketingException.class)
|
|
||||||
.extracting("errorCode")
|
|
||||||
.isEqualTo(ErrorCode.NOT_REFUNDABLE_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 환불 성공")
|
|
||||||
void refundSuccess() {
|
|
||||||
// given
|
|
||||||
Ticket ticket = tickets.get(0);
|
|
||||||
|
|
||||||
// when
|
|
||||||
ticket.makeSold(123L);
|
|
||||||
ticket.refund();
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertAll(
|
|
||||||
() -> assertThat(ticket.getStatus()).isEqualTo(TicketStatus.SALE),
|
|
||||||
() -> assertThat(ticket.getPaymentId()).isNull()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 환불 실패 - 상태 SALE")
|
|
||||||
void refundFail_SALE() {
|
|
||||||
// given
|
|
||||||
Ticket ticket = tickets.get(0);
|
|
||||||
|
|
||||||
// when
|
|
||||||
// then
|
|
||||||
assertThatThrownBy(ticket::refund)
|
|
||||||
.isInstanceOf(TicketingException.class)
|
|
||||||
.extracting("errorCode")
|
|
||||||
.isEqualTo(ErrorCode.NOT_REFUNDABLE_SEAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 환불 실패 - 상태 RESERVATION")
|
|
||||||
void refundFail_RESERVATION() {
|
|
||||||
// given
|
|
||||||
Ticket ticket = tickets.get(0);
|
|
||||||
|
|
||||||
// when
|
|
||||||
ticket.makeReservation();
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThatThrownBy(ticket::refund)
|
|
||||||
.isInstanceOf(TicketingException.class)
|
|
||||||
.extracting("errorCode")
|
|
||||||
.isEqualTo(ErrorCode.NOT_REFUNDABLE_SEAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,15 @@
|
|||||||
package com.ticketing.server.movie.service;
|
package com.ticketing.server.movie.service;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.TicketingException;
|
|
||||||
import com.ticketing.server.movie.domain.Movie;
|
import com.ticketing.server.movie.domain.Movie;
|
||||||
import com.ticketing.server.movie.domain.repository.MovieRepository;
|
import com.ticketing.server.movie.domain.repository.MovieRepository;
|
||||||
import com.ticketing.server.movie.service.dto.DeletedMovieDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.MovieDTO;
|
import com.ticketing.server.movie.service.dto.MovieDTO;
|
||||||
import com.ticketing.server.movie.service.dto.RegisteredMovieDTO;
|
import com.ticketing.server.movie.service.dto.MovieListDTO;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
import org.hibernate.sql.Delete;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
@@ -28,7 +21,9 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|||||||
public class MovieServiceImplTest {
|
public class MovieServiceImplTest {
|
||||||
|
|
||||||
Movie movie;
|
Movie movie;
|
||||||
|
MovieDTO movieDto;
|
||||||
List<Movie> movies = new ArrayList<>();
|
List<Movie> movies = new ArrayList<>();
|
||||||
|
List<MovieDTO> movieDTOS = new ArrayList<>();
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
MovieRepository movieRepository;
|
MovieRepository movieRepository;
|
||||||
@@ -44,10 +39,10 @@ public class MovieServiceImplTest {
|
|||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<MovieDTO> movieDtos = movieService.getMovies();
|
MovieListDTO movieListDto = movieService.getMovies();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(movieDtos.isEmpty());
|
assertTrue(movieListDto.getMovieDtos().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -60,80 +55,11 @@ public class MovieServiceImplTest {
|
|||||||
when(movieRepository.findValidMovies())
|
when(movieRepository.findValidMovies())
|
||||||
.thenReturn(movies);
|
.thenReturn(movies);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<MovieDTO> movieDtos = movieService.getMovies();
|
MovieListDTO movieListDto = movieService.getMovies();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(!movieDtos.isEmpty());
|
assertTrue(!movieListDto.getMovieDtos().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Movie Service Test - register movie")
|
|
||||||
void shouldAbleToRegisterMovie() {
|
|
||||||
// given
|
|
||||||
String title = "추가할 영화 제목";
|
|
||||||
movie = new Movie(title, 100L);
|
|
||||||
|
|
||||||
when(movieRepository.findValidMovieWithTitle(title))
|
|
||||||
.thenReturn(Optional.empty());
|
|
||||||
when(movieRepository.save(any()))
|
|
||||||
.thenReturn(movie);
|
|
||||||
|
|
||||||
// when
|
|
||||||
RegisteredMovieDTO registeredMovieDto =
|
|
||||||
movieService.registerMovie(title, movie.getRunningTime());
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(registeredMovieDto).isNotNull();
|
|
||||||
assertTrue(registeredMovieDto.getTitle().equals(title));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Movie Service Test - register movie when there is same movie already")
|
|
||||||
void shouldThrowExceptionWhenRegistering() {
|
|
||||||
// given
|
|
||||||
String title = "이미 중복된 영화 제목";
|
|
||||||
|
|
||||||
Movie movie = new Movie(title, 100L);
|
|
||||||
|
|
||||||
when(movieRepository.findValidMovieWithTitle(title))
|
|
||||||
.thenReturn(Optional.of(movie));
|
|
||||||
|
|
||||||
// when
|
|
||||||
// then
|
|
||||||
assertThatThrownBy(() -> movieService.registerMovie(title, 100L))
|
|
||||||
.isInstanceOf(TicketingException.class);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Movie Service Test - delete movie")
|
|
||||||
void shouldAbleToDeleteMovie() {
|
|
||||||
// given
|
|
||||||
Movie movie = new Movie("삭제할 영화 제목", 100L);
|
|
||||||
|
|
||||||
when(movieRepository.findByIdAndDeletedAtNull(1L))
|
|
||||||
.thenReturn(Optional.of(movie));
|
|
||||||
|
|
||||||
// when
|
|
||||||
DeletedMovieDTO deletedMovieDto =
|
|
||||||
movieService.deleteMovie(1L);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertTrue(deletedMovieDto.getTitle().equals("삭제할 영화 제목"));
|
|
||||||
assertThat(deletedMovieDto.getDeletedAt()).isNotNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Movie Service Test - delete movie when there is no such movie")
|
|
||||||
void shouldThrowExceptionWhenDeleting() {
|
|
||||||
// given
|
|
||||||
when(movieRepository.findByIdAndDeletedAtNull(1L))
|
|
||||||
.thenReturn(Optional.empty());
|
|
||||||
|
|
||||||
// when
|
|
||||||
// then
|
|
||||||
assertThatThrownBy(() -> movieService.deleteMovie(1L))
|
|
||||||
.isInstanceOf(TicketingException.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,15 @@
|
|||||||
package com.ticketing.server.movie.service;
|
package com.ticketing.server.movie.service;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.TicketingException;
|
|
||||||
import com.ticketing.server.movie.domain.Movie;
|
import com.ticketing.server.movie.domain.Movie;
|
||||||
import com.ticketing.server.movie.domain.MovieTime;
|
import com.ticketing.server.movie.domain.MovieTime;
|
||||||
import com.ticketing.server.movie.domain.Theater;
|
import com.ticketing.server.movie.domain.Theater;
|
||||||
import com.ticketing.server.movie.domain.repository.MovieRepository;
|
import com.ticketing.server.movie.domain.repository.MovieRepository;
|
||||||
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
||||||
import com.ticketing.server.movie.domain.repository.TheaterRepository;
|
import com.ticketing.server.movie.service.dto.MovieTimeListDTO;
|
||||||
import com.ticketing.server.movie.service.dto.MovieTimeDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.MovieTimeRegisterDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.RegisteredMovieTimeDTO;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -35,15 +27,11 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|||||||
public class MovieTimeServiceImplTest {
|
public class MovieTimeServiceImplTest {
|
||||||
|
|
||||||
String title = "범죄도시2";
|
String title = "범죄도시2";
|
||||||
LocalDateTime startAt = LocalDateTime.now();
|
|
||||||
List<MovieTime> movieTimes = new ArrayList<>();
|
List<MovieTime> movieTimes = new ArrayList<>();
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
MovieRepository movieRepository;
|
MovieRepository movieRepository;
|
||||||
|
|
||||||
@Mock
|
|
||||||
TheaterRepository theaterRepository;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
MovieTimeRepository movieTimeRepository;
|
MovieTimeRepository movieTimeRepository;
|
||||||
|
|
||||||
@@ -51,7 +39,7 @@ public class MovieTimeServiceImplTest {
|
|||||||
MovieTimeServiceImpl movieTimeService;
|
MovieTimeServiceImpl movieTimeService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("MovieTime Service Test - get empty list when there is no valid movie time")
|
@DisplayName("MovieTime Service Test - get empty list when there are no valid movie times")
|
||||||
void shouldGetEmptyList() {
|
void shouldGetEmptyList() {
|
||||||
// given
|
// given
|
||||||
Movie movie = new Movie(title, 106L);
|
Movie movie = new Movie(title, 106L);
|
||||||
@@ -63,10 +51,10 @@ public class MovieTimeServiceImplTest {
|
|||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<MovieTimeDTO> movieTimeDtos = movieTimeService.getMovieTimes(any(), LocalDate.now());
|
MovieTimeListDTO movieTimeListDto = movieTimeService.getMovieTimes(any(), LocalDate.now());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(movieTimeDtos.isEmpty());
|
assertTrue(movieTimeListDto.getMovieTimeDtos().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -88,82 +76,10 @@ public class MovieTimeServiceImplTest {
|
|||||||
.thenReturn(movieTimes);
|
.thenReturn(movieTimes);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<MovieTimeDTO> movieTimeDtos = movieTimeService.getMovieTimes(any(), LocalDate.of(2022, 07, 01));
|
MovieTimeListDTO movieTimeListDto = movieTimeService.getMovieTimes(any(), LocalDate.of(2022, 07, 01));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(!movieTimeDtos.isEmpty());
|
assertTrue(!movieTimeListDto.getMovieTimeDtos().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("MovieTime Service Test - register movie time")
|
|
||||||
void shouldAbleToRegisterMovieTime() {
|
|
||||||
// given
|
|
||||||
Movie movie = new Movie(title, 100L);
|
|
||||||
Theater theater = new Theater(1);
|
|
||||||
MovieTime movieTime = new MovieTime(movie, theater, 1, startAt);
|
|
||||||
|
|
||||||
when(movieRepository.findByIdAndDeletedAtNull(anyLong()))
|
|
||||||
.thenReturn(Optional.of(movie));
|
|
||||||
|
|
||||||
when(theaterRepository.findByTheaterNumber(anyInt()))
|
|
||||||
.thenReturn(Optional.of(theater));
|
|
||||||
|
|
||||||
when(movieTimeRepository.findByMovieAndTheaterAndRoundAndDeletedAtNull(any(), any(), anyInt()))
|
|
||||||
.thenReturn(Optional.empty());
|
|
||||||
|
|
||||||
when(movieTimeRepository.save(any()))
|
|
||||||
.thenReturn(movieTime);
|
|
||||||
|
|
||||||
// when
|
|
||||||
RegisteredMovieTimeDTO registeredMovieTimeDto =
|
|
||||||
movieTimeService.registerMovieTime(
|
|
||||||
new MovieTimeRegisterDTO(1L, 1, 1, startAt)
|
|
||||||
);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(registeredMovieTimeDto).isNotNull();
|
|
||||||
assertTrue(registeredMovieTimeDto.getTheaterNumber() == 1);
|
|
||||||
assertTrue(registeredMovieTimeDto.getStartAt() == startAt);
|
|
||||||
assertTrue(registeredMovieTimeDto.getRound() == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("MovieTime Service Test - register movie time when there is same movie time already")
|
|
||||||
void shouldThrowExceptionWhenRegisteringDuplicateMovieTime() {
|
|
||||||
// given
|
|
||||||
Movie movie = new Movie(title, 100L);
|
|
||||||
Theater theater = new Theater(1);
|
|
||||||
MovieTime movieTime = new MovieTime(movie, theater, 1, startAt);
|
|
||||||
MovieTimeRegisterDTO movieTimeRegisterDto = new MovieTimeRegisterDTO(1L, 1, 1, startAt);
|
|
||||||
|
|
||||||
when(movieRepository.findByIdAndDeletedAtNull(anyLong()))
|
|
||||||
.thenReturn(Optional.of(movie));
|
|
||||||
|
|
||||||
when(theaterRepository.findByTheaterNumber(anyInt()))
|
|
||||||
.thenReturn(Optional.of(theater));
|
|
||||||
|
|
||||||
when(movieTimeRepository.findByMovieAndTheaterAndRoundAndDeletedAtNull(any(), any(), anyInt()))
|
|
||||||
.thenReturn(Optional.of(movieTime));
|
|
||||||
|
|
||||||
// when
|
|
||||||
// then
|
|
||||||
assertThatThrownBy(() -> movieTimeService.registerMovieTime(movieTimeRegisterDto))
|
|
||||||
.isInstanceOf(TicketingException.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("MovieTime Service Test - register movie time when there is no such movie")
|
|
||||||
void shouldThrowExceptionWhenRegisteringMovieTimeWithNoSuchMovie() {
|
|
||||||
// given
|
|
||||||
Theater theater = new Theater(1);
|
|
||||||
MovieTimeRegisterDTO movieTimeRegisterDto = new MovieTimeRegisterDTO(1L, 1, 1, startAt);
|
|
||||||
|
|
||||||
when(movieRepository.findByIdAndDeletedAtNull(1L))
|
|
||||||
.thenReturn(Optional.empty());
|
|
||||||
|
|
||||||
// when
|
|
||||||
// then
|
|
||||||
assertThatThrownBy(() -> movieTimeService.registerMovieTime(movieTimeRegisterDto))
|
|
||||||
.isInstanceOf(TicketingException.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service;
|
|
||||||
|
|
||||||
import static com.ticketing.server.movie.domain.TicketTest.setupTickets;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.ErrorCode;
|
|
||||||
import com.ticketing.server.global.exception.TicketingException;
|
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
|
||||||
import com.ticketing.server.movie.domain.repository.TicketRepository;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketIdsDTO;
|
|
||||||
import com.ticketing.server.movie.service.dto.TicketsReservationDTO;
|
|
||||||
import java.util.List;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
|
||||||
class TicketLockServiceTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
TicketRepository ticketRepository;
|
|
||||||
|
|
||||||
@InjectMocks
|
|
||||||
TicketLockService ticketLockService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("티켓목록 예약으로 변경 시 조회된 갯수랑 다른 경우")
|
|
||||||
void ticketReservationFail() {
|
|
||||||
// given
|
|
||||||
List<Ticket> tickets = setupTickets();
|
|
||||||
List<Ticket> list = List.of(tickets.get(0), tickets.get(1), tickets.get(2));
|
|
||||||
List<Long> ids = List.of(0L, 1L, 2L, 10000L);
|
|
||||||
TicketIdsDTO ticketIdsDto = new TicketIdsDTO(ids);
|
|
||||||
|
|
||||||
when(ticketRepository.findTicketFetchJoinByTicketIds(ids)).thenReturn(list);
|
|
||||||
|
|
||||||
// when
|
|
||||||
// then
|
|
||||||
assertThatThrownBy(() -> ticketLockService.ticketReservation(ticketIdsDto))
|
|
||||||
.isInstanceOf(TicketingException.class)
|
|
||||||
.extracting("errorCode")
|
|
||||||
.isEqualTo(ErrorCode.INVALID_TICKET_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("티켓목록 예약으로 변경 완료")
|
|
||||||
void ticketReservationSuccess() {
|
|
||||||
// given
|
|
||||||
List<Ticket> tickets = setupTickets();
|
|
||||||
List<Ticket> list = List.of(tickets.get(0), tickets.get(1), tickets.get(2));
|
|
||||||
List<Long> ids = List.of(0L, 1L, 2L);
|
|
||||||
TicketIdsDTO ticketIdsDto = new TicketIdsDTO(ids);
|
|
||||||
|
|
||||||
when(ticketRepository.findTicketFetchJoinByTicketIds(ids)).thenReturn(list);
|
|
||||||
|
|
||||||
// when
|
|
||||||
TicketsReservationDTO ticketReservationsDto = ticketLockService.ticketReservation(ticketIdsDto);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(ticketReservationsDto.getTicketReservationDtoList()).hasSize(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,8 @@ import com.ticketing.server.global.exception.ErrorCode;
|
|||||||
import com.ticketing.server.global.exception.TicketingException;
|
import com.ticketing.server.global.exception.TicketingException;
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
import com.ticketing.server.movie.domain.Ticket;
|
||||||
import com.ticketing.server.movie.domain.repository.TicketRepository;
|
import com.ticketing.server.movie.domain.repository.TicketRepository;
|
||||||
|
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||||
|
import com.ticketing.server.movie.service.dto.TicketsReservationDTO;
|
||||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -51,7 +53,8 @@ class TicketServiceImplTest {
|
|||||||
when(ticketRepository.findTicketFetchJoinByPaymentId(1L)).thenReturn(List.of(tickets.get(0)));
|
when(ticketRepository.findTicketFetchJoinByPaymentId(1L)).thenReturn(List.of(tickets.get(0)));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<TicketDetailDTO> ticketDetails = ticketService.findTicketsByPaymentId(1L);
|
TicketDetailsDTO ticketDetailDto = ticketService.findTicketsByPaymentId(1L);
|
||||||
|
List<TicketDetailDTO> ticketDetails = ticketDetailDto.getTicketDetails();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertAll(
|
assertAll(
|
||||||
@@ -60,4 +63,39 @@ class TicketServiceImplTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("티켓목록 예약으로 변경 시 조회된 갯수랑 다른 경우")
|
||||||
|
void ticketReservationFail() {
|
||||||
|
// given
|
||||||
|
List<Ticket> tickets = setupTickets();
|
||||||
|
List<Ticket> list = List.of(tickets.get(0), tickets.get(1), tickets.get(2));
|
||||||
|
List<Long> ids = List.of(0L, 1L, 2L, 10000L);
|
||||||
|
|
||||||
|
when(ticketRepository.findTicketFetchJoinByTicketIds(ids)).thenReturn(list);
|
||||||
|
|
||||||
|
// when
|
||||||
|
// then
|
||||||
|
assertThatThrownBy(() -> ticketService.ticketReservation(ids))
|
||||||
|
.isInstanceOf(TicketingException.class)
|
||||||
|
.extracting("errorCode")
|
||||||
|
.isEqualTo(ErrorCode.INVALID_TICKET_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("티켓목록 예약으로 변경 완료")
|
||||||
|
void ticketReservationSuccess() {
|
||||||
|
// given
|
||||||
|
List<Ticket> tickets = setupTickets();
|
||||||
|
List<Ticket> list = List.of(tickets.get(0), tickets.get(1), tickets.get(2));
|
||||||
|
List<Long> ids = List.of(0L, 1L, 2L);
|
||||||
|
|
||||||
|
when(ticketRepository.findTicketFetchJoinByTicketIds(ids)).thenReturn(list);
|
||||||
|
|
||||||
|
// when
|
||||||
|
TicketsReservationDTO ticketReservationsDto = ticketService.ticketReservation(ids);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(ticketReservationsDto.getTicketReservationDtoList()).hasSize(3);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ class PaymentServiceImplTest {
|
|||||||
"T2d03c9130bf237a97001",
|
"T2d03c9130bf237a97001",
|
||||||
List.of(3L),
|
List.of(3L),
|
||||||
userAlternateId,
|
userAlternateId,
|
||||||
1241242343245L,
|
1241242343245L
|
||||||
15_000
|
|
||||||
),
|
),
|
||||||
KAKAO_PAY,
|
KAKAO_PAY,
|
||||||
SOLD,
|
SOLD,
|
||||||
@@ -71,8 +70,7 @@ class PaymentServiceImplTest {
|
|||||||
"T2d03c9130bf237a97002",
|
"T2d03c9130bf237a97002",
|
||||||
List.of(3L),
|
List.of(3L),
|
||||||
userAlternateId,
|
userAlternateId,
|
||||||
12412343212445L,
|
12412343212445L
|
||||||
30_000
|
|
||||||
),
|
),
|
||||||
KAKAO_PAY,
|
KAKAO_PAY,
|
||||||
SOLD,
|
SOLD,
|
||||||
|
|||||||
@@ -76,8 +76,7 @@ class UserApisServiceImplTest {
|
|||||||
"T2d03c9130bf237a9700",
|
"T2d03c9130bf237a9700",
|
||||||
List.of(1L, 2L),
|
List.of(1L, 2L),
|
||||||
user.getAlternateId(),
|
user.getAlternateId(),
|
||||||
124124231513245L,
|
124124231513245L
|
||||||
15_000
|
|
||||||
),
|
),
|
||||||
KAKAO_PAY,
|
KAKAO_PAY,
|
||||||
SOLD,
|
SOLD,
|
||||||
@@ -92,8 +91,7 @@ class UserApisServiceImplTest {
|
|||||||
"T2d03c9130bf237a97001",
|
"T2d03c9130bf237a97001",
|
||||||
List.of(3L),
|
List.of(3L),
|
||||||
user.getAlternateId(),
|
user.getAlternateId(),
|
||||||
1241242343245L,
|
1241242343245L
|
||||||
15_000
|
|
||||||
),
|
),
|
||||||
KAKAO_PAY,
|
KAKAO_PAY,
|
||||||
SOLD,
|
SOLD,
|
||||||
|
|||||||
Reference in New Issue
Block a user