Compare commits
13 Commits
feature/pa
...
feature/ve
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a14020dfb5 | ||
|
|
975e03b7bd | ||
|
|
657c9e7f7d | ||
|
|
c5b779fda7 | ||
|
|
b7057cfc73 | ||
|
|
42a00d20d0 | ||
|
|
b3842d93b4 | ||
|
|
58bed5565f | ||
|
|
28874b1b1c | ||
|
|
656e5e25e8 | ||
|
|
f1382597de | ||
|
|
a2cfd7ab15 | ||
|
|
61f6636653 |
@@ -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,10 +101,11 @@ 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 "삭제일시"
|
||||||
|
|||||||
12
server/Dockerfile
Normal file
12
server/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
FROM openjdk:11-jre-slim
|
||||||
|
|
||||||
|
ENV APP_HOME=/usr/app/
|
||||||
|
|
||||||
|
WORKDIR $APP_HOME
|
||||||
|
|
||||||
|
COPY build/libs/server-0.0.1-SNAPSHOT.jar application.jar
|
||||||
|
|
||||||
|
EXPOSE 8443
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
CMD ["java", "-jar", "application.jar"]
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
|
import Dependencies.AnnotationProcessorLib
|
||||||
|
import Dependencies.DependencyManagementLib
|
||||||
|
import Dependencies.ModuleLib
|
||||||
|
import Dependencies.RuntimeOnlyLib
|
||||||
|
import Dependencies.TestLib
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
id("org.springframework.boot") version "2.6.7"
|
id("org.springframework.boot") version Versions.SPRING_BOOT_STARTER
|
||||||
id("io.spring.dependency-management") version "1.0.11.RELEASE"
|
id("io.spring.dependency-management") version Versions.SPRING_DEPENDENCY_MANAGEMENT
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "com.ticketing"
|
group = "com.ticketing"
|
||||||
@@ -23,48 +29,50 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
extra["springCloudVersion"] = "2021.0.3"
|
extra["springCloudVersion"] = Versions.SPRING_CLOUD
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
implementation(Dependencies.SPRING_BOOT_STARTER_DATA_JPA)
|
||||||
implementation("org.springframework.boot:spring-boot-starter-security")
|
implementation(Dependencies.SPRING_BOOT_STARTER_SECURITY)
|
||||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
implementation(Dependencies.SPRING_BOOT_STARTER_VALIDATION)
|
||||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
implementation(Dependencies.SPRING_BOOT_STARTER_WEB)
|
||||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
implementation(Dependencies.SPRING_BOOT_STARTER_ACTUATOR)
|
||||||
implementation("org.springframework.boot:spring-boot-starter-log4j2")
|
implementation(Dependencies.SPRING_BOOT_STARTER_LOG4J2)
|
||||||
implementation("org.projectlombok:lombok:1.18.24")
|
implementation(Dependencies.LOMBOK)
|
||||||
implementation("io.springfox:springfox-boot-starter:3.0.0")
|
implementation(Dependencies.SPRING_FOX_STARTER)
|
||||||
implementation("io.springfox:springfox-swagger-ui:3.0.0")
|
implementation(Dependencies.SWAGGER)
|
||||||
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
implementation(Dependencies.JASYPT_SPRING_BOOT_STARTER)
|
||||||
implementation("com.lmax:disruptor:3.4.4")
|
implementation(Dependencies.DISRUPTOR)
|
||||||
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
|
implementation(Dependencies.JJWT)
|
||||||
implementation("com.googlecode.json-simple:json-simple:1.1.1")
|
implementation(Dependencies.JSON_SIMPLE)
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-redis")
|
implementation(Dependencies.SPRING_BOOT_STARTER_REDIS)
|
||||||
implementation("com.google.code.findbugs:jsr305:3.0.2")
|
implementation(Dependencies.JSR350)
|
||||||
implementation ("org.springframework.cloud:spring-cloud-starter-config")
|
implementation(Dependencies.SPRING_CLOUD_STARTER)
|
||||||
implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
|
implementation(Dependencies.SPRING_CLOUD_FEIGN)
|
||||||
|
implementation(Dependencies.MICROMETER_CORE)
|
||||||
|
implementation(Dependencies.MICROMETER_REGISTRY_PROMETHEUS)
|
||||||
|
|
||||||
modules {
|
modules {
|
||||||
module("org.springframework.boot:spring-boot-starter-logging") {
|
module(ModuleLib.SPRING_BOOT_STARTER_LOGGING) {
|
||||||
replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback")
|
replacedBy(ModuleLib.SPRING_BOOT_STARTER_LOG4J2, "Use Log4j2 instead of Logback")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok")
|
compileOnly(Dependencies.LOMBOK)
|
||||||
runtimeOnly("mysql:mysql-connector-java")
|
runtimeOnly(RuntimeOnlyLib.MYSQL)
|
||||||
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5")
|
runtimeOnly(RuntimeOnlyLib.JJWT_IMPL)
|
||||||
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
|
runtimeOnly(RuntimeOnlyLib.JJWT_JACKSON)
|
||||||
annotationProcessor("org.projectlombok:lombok")
|
annotationProcessor(Dependencies.LOMBOK)
|
||||||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
annotationProcessor(AnnotationProcessorLib.SPRING_BOOT_PROCESSOR)
|
||||||
|
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
|
testImplementation(TestLib.JUPITER)
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
testImplementation(TestLib.SPRING_BOOT_STARTER)
|
||||||
testImplementation("org.springframework.security:spring-security-test")
|
testImplementation(TestLib.SPRING_SECURITY)
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencyManagement {
|
dependencyManagement {
|
||||||
imports {
|
imports {
|
||||||
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
|
mavenBom(DependencyManagementLib.SPRING_CLOUD)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
server/buildSrc/build.gradle.kts
Normal file
8
server/buildSrc/build.gradle.kts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
plugins {
|
||||||
|
`kotlin-dsl`
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
56
server/buildSrc/src/main/kotlin/Dependencies.kt
Normal file
56
server/buildSrc/src/main/kotlin/Dependencies.kt
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
object Dependencies {
|
||||||
|
|
||||||
|
const val SPRING_BOOT_STARTER_DATA_JPA = "org.springframework.boot:spring-boot-starter-data-jpa:${Versions.SPRING_BOOT_STARTER}"
|
||||||
|
const val SPRING_BOOT_STARTER_SECURITY = "org.springframework.boot:spring-boot-starter-security:${Versions.SPRING_BOOT_STARTER}"
|
||||||
|
const val SPRING_BOOT_STARTER_VALIDATION = "org.springframework.boot:spring-boot-starter-validation:${Versions.SPRING_BOOT_STARTER}"
|
||||||
|
const val SPRING_BOOT_STARTER_WEB = "org.springframework.boot:spring-boot-starter-web:${Versions.SPRING_BOOT_STARTER}"
|
||||||
|
const val SPRING_BOOT_STARTER_ACTUATOR = "org.springframework.boot:spring-boot-starter-actuator:${Versions.SPRING_BOOT_STARTER}"
|
||||||
|
const val SPRING_BOOT_STARTER_LOG4J2 = "org.springframework.boot:spring-boot-starter-log4j2:${Versions.SPRING_BOOT_STARTER}"
|
||||||
|
const val SPRING_BOOT_STARTER_REDIS = "org.springframework.boot:spring-boot-starter-data-redis:${Versions.SPRING_BOOT_STARTER}"
|
||||||
|
|
||||||
|
const val SPRING_CLOUD_STARTER = "org.springframework.cloud:spring-cloud-starter-config:${Versions.SPRING_CLOUD_STARTER}"
|
||||||
|
const val SPRING_CLOUD_FEIGN = "org.springframework.cloud:spring-cloud-starter-openfeign:${Versions.SPRING_CLOUD_STARTER}"
|
||||||
|
|
||||||
|
const val LOMBOK = "org.projectlombok:lombok:${Versions.LOMBOK}"
|
||||||
|
|
||||||
|
const val SPRING_FOX_STARTER = "io.springfox:springfox-boot-starter:${Versions.SPRING_FOX}"
|
||||||
|
const val SWAGGER = "io.springfox:springfox-swagger-ui:${Versions.SPRING_FOX}"
|
||||||
|
|
||||||
|
const val JASYPT_SPRING_BOOT_STARTER = "com.github.ulisesbocchio:jasypt-spring-boot-starter:${Versions.JASYPT}"
|
||||||
|
|
||||||
|
const val DISRUPTOR = "com.lmax:disruptor:${Versions.DISRUPTOR}"
|
||||||
|
|
||||||
|
const val JJWT = "io.jsonwebtoken:jjwt-api:${Versions.JJWT}"
|
||||||
|
const val JSON_SIMPLE = "com.googlecode.json-simple:json-simple:${Versions.JSON_SIMPLE}"
|
||||||
|
|
||||||
|
const val MICROMETER_CORE = "io.micrometer:micrometer-core:${Versions.MICROMETER}"
|
||||||
|
const val MICROMETER_REGISTRY_PROMETHEUS = "io.micrometer:micrometer-registry-prometheus:${Versions.MICROMETER}"
|
||||||
|
|
||||||
|
const val JSR350 = "com.google.code.findbugs:jsr305:${Versions.JSR350}"
|
||||||
|
|
||||||
|
object ModuleLib {
|
||||||
|
const val SPRING_BOOT_STARTER_LOGGING = "org.springframework.boot:spring-boot-starter-logging"
|
||||||
|
const val SPRING_BOOT_STARTER_LOG4J2 = "org.springframework.boot:spring-boot-starter-log4j2"
|
||||||
|
}
|
||||||
|
|
||||||
|
object RuntimeOnlyLib {
|
||||||
|
const val MYSQL = "mysql:mysql-connector-java:${Versions.MYSQL_CONNECTOR_JAVA}"
|
||||||
|
const val JJWT_IMPL = "io.jsonwebtoken:jjwt-impl:${Versions.JJWT}"
|
||||||
|
const val JJWT_JACKSON = "io.jsonwebtoken:jjwt-jackson:${Versions.JJWT}"
|
||||||
|
}
|
||||||
|
|
||||||
|
object AnnotationProcessorLib {
|
||||||
|
const val SPRING_BOOT_PROCESSOR = "org.springframework.boot:spring-boot-configuration-processor:${Versions.SPRING_BOOT_STARTER}"
|
||||||
|
}
|
||||||
|
|
||||||
|
object TestLib {
|
||||||
|
const val JUPITER = "org.junit.jupiter:junit-jupiter-api:${Versions.JUPITER}"
|
||||||
|
const val SPRING_BOOT_STARTER = "org.springframework.boot:spring-boot-starter-test:${Versions.SPRING_BOOT_STARTER}"
|
||||||
|
const val SPRING_SECURITY = "org.springframework.security:spring-security-test:${Versions.SECURITY}"
|
||||||
|
}
|
||||||
|
|
||||||
|
object DependencyManagementLib {
|
||||||
|
const val SPRING_CLOUD = "org.springframework.cloud:spring-cloud-dependencies:${Versions.SPRING_CLOUD}"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
23
server/buildSrc/src/main/kotlin/Versions.kt
Normal file
23
server/buildSrc/src/main/kotlin/Versions.kt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
object Versions {
|
||||||
|
|
||||||
|
const val SPRING_BOOT_STARTER = "2.6.7"
|
||||||
|
const val SPRING_DEPENDENCY_MANAGEMENT = "1.0.11.RELEASE"
|
||||||
|
|
||||||
|
const val SPRING_CLOUD_STARTER = "3.1.3"
|
||||||
|
const val SPRING_CLOUD = "2021.0.3"
|
||||||
|
|
||||||
|
const val MYSQL_CONNECTOR_JAVA = "8.0.28"
|
||||||
|
|
||||||
|
const val LOMBOK = "1.18.24"
|
||||||
|
const val SPRING_FOX = "3.0.0"
|
||||||
|
const val JASYPT = "3.0.4"
|
||||||
|
const val DISRUPTOR = "3.4.4"
|
||||||
|
const val JJWT = "0.11.5"
|
||||||
|
const val JSON_SIMPLE = "1.1.1"
|
||||||
|
const val MICROMETER = "1.8.5"
|
||||||
|
const val JSR350 = "3.0.2"
|
||||||
|
|
||||||
|
const val JUPITER = "5.8.1"
|
||||||
|
const val SECURITY = "5.6.3"
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
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,7 +1,242 @@
|
|||||||
package com.ticketing.server.user.application;
|
package com.ticketing.server.user.application;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
||||||
|
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,6 +20,9 @@ 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,7 +5,6 @@ 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;
|
||||||
@@ -24,6 +23,11 @@ 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, "해당 정보에 접근 권한이 존재하지 않습니다."),
|
||||||
@@ -46,7 +50,7 @@ public enum ErrorCode {
|
|||||||
DELETED_MOVIE(CONFLICT, "이미 삭제된 영화 입니다.");
|
DELETED_MOVIE(CONFLICT, "이미 삭제된 영화 입니다.");
|
||||||
|
|
||||||
private final HttpStatus httpStatus;
|
private final HttpStatus httpStatus;
|
||||||
private String detail;
|
private final String detail;
|
||||||
|
|
||||||
/* 400 BAD_REQUEST : 잘못된 요청 */
|
/* 400 BAD_REQUEST : 잘못된 요청 */
|
||||||
public static TicketingException throwMismatchPassword() {
|
public static TicketingException throwMismatchPassword() {
|
||||||
@@ -65,14 +69,6 @@ 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);
|
||||||
}
|
}
|
||||||
@@ -81,19 +77,12 @@ 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);
|
||||||
@@ -103,10 +92,6 @@ public enum ErrorCode {
|
|||||||
throw new TicketingException(MOVIE_NOT_FOUND);
|
throw new TicketingException(MOVIE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TicketingException throwMovieTimeNotFound() {
|
|
||||||
throw new TicketingException(MOVIE_TIME_NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TicketingException throwRefreshTokenNotFound() {
|
public static TicketingException throwRefreshTokenNotFound() {
|
||||||
throw new TicketingException(REFRESH_TOKEN_NOT_FOUND);
|
throw new TicketingException(REFRESH_TOKEN_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ 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;
|
||||||
@@ -211,6 +212,17 @@ 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,12 +33,15 @@ public class PaymentCache {
|
|||||||
|
|
||||||
private Long paymentNumber;
|
private Long paymentNumber;
|
||||||
|
|
||||||
public PaymentCache(String email, String movieTitle, String tid, List<Long> ticketIds, Long userAlternateId, Long paymentNumber) {
|
private Integer totalAmount;
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ public class RefreshToken {
|
|||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeToken(String token) {
|
public RefreshToken changeToken(String token) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class JwtProvider {
|
|||||||
|
|
||||||
private static final String AUTHORITIES_KEY = "auth";
|
private static final String AUTHORITIES_KEY = "auth";
|
||||||
private static final String AUTHORITIES_DELIMITER = ",";
|
private static final String AUTHORITIES_DELIMITER = ",";
|
||||||
|
private static final String ROLE = "ROLE_";
|
||||||
|
|
||||||
private final Key key;
|
private final Key key;
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
@@ -89,7 +90,7 @@ public class JwtProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String makeRoleName(String role) {
|
private String makeRoleName(String role) {
|
||||||
return "ROLE_" + role.toUpperCase();
|
return role.contains(ROLE) ? role.toUpperCase() : ROLE + role.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Authentication getAuthentication(String token) {
|
public Authentication getAuthentication(String token) {
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
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,11 +8,12 @@ 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.MovieListDTO;
|
import com.ticketing.server.movie.service.dto.MovieDTO;
|
||||||
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;
|
||||||
@@ -51,11 +52,11 @@ public class MovieController {
|
|||||||
@GetMapping()
|
@GetMapping()
|
||||||
@ApiOperation(value = "영화 목록 조회")
|
@ApiOperation(value = "영화 목록 조회")
|
||||||
public ResponseEntity<MovieListResponse> getMovies() {
|
public ResponseEntity<MovieListResponse> getMovies() {
|
||||||
MovieListDTO movieListDto = movieService.getMovies();
|
List<MovieDTO> movieDtos = movieService.getMovies();
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(
|
.body(
|
||||||
movieListDto.toResponse()
|
new MovieListResponse(movieDtos)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ 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.MovieTimeListDTO;
|
import com.ticketing.server.movie.service.dto.MovieTimeDTO;
|
||||||
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;
|
||||||
@@ -58,11 +59,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) {
|
||||||
MovieTimeListDTO movieTimeListDto = movieTimeService.getMovieTimes(movieId, runningDate);
|
List<MovieTimeDTO> movieTimeDtos = movieTimeService.getMovieTimes(movieId, runningDate);
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(
|
.body(
|
||||||
movieTimeListDto.toResponse()
|
new MovieTimeListResponse(movieTimeDtos)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ 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.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.dto.TicketListDTO;
|
|
||||||
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 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;
|
||||||
@@ -32,23 +33,23 @@ public class TicketController {
|
|||||||
@Secured(USER)
|
@Secured(USER)
|
||||||
public ResponseEntity<TicketListResponse> getTickets(
|
public ResponseEntity<TicketListResponse> getTickets(
|
||||||
@ApiParam(value = "영화 시간표 ID", required = true) @RequestParam @NotNull Long movieTimeId) {
|
@ApiParam(value = "영화 시간표 ID", required = true) @RequestParam @NotNull Long movieTimeId) {
|
||||||
TicketListDTO ticketListDto = ticketService.getTickets(movieTimeId);
|
List<TicketDTO> tickets = ticketService.getTickets(movieTimeId);
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(
|
.body(
|
||||||
ticketListDto.toResponse()
|
new TicketListResponse(tickets)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("payments/{paymentId}")
|
@GetMapping("/payments/{paymentId}")
|
||||||
@Secured(USER)
|
@Secured(USER)
|
||||||
public ResponseEntity<TicketDetailsResponse> findTicketsByPaymentId(
|
public ResponseEntity<TicketDetailsResponse> findTicketsByPaymentId(
|
||||||
@PathVariable("paymentId") @NotNull Long paymentId) {
|
@PathVariable("paymentId") @NotNull Long paymentId) {
|
||||||
TicketDetailsDTO tickets = ticketService.findTicketsByPaymentId(paymentId);
|
List<TicketDetailDTO> tickets = ticketService.findTicketsByPaymentId(paymentId);
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(
|
.body(
|
||||||
tickets.toResponse()
|
new TicketDetailsResponse(tickets)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
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;
|
||||||
@@ -55,7 +62,7 @@ public class Ticket extends AbstractEntity {
|
|||||||
|
|
||||||
public Ticket makeReservation() {
|
public Ticket makeReservation() {
|
||||||
if (!TicketStatus.SALE.equals(status)) {
|
if (!TicketStatus.SALE.equals(status)) {
|
||||||
throw ErrorCode.throwDuplicatePayment();
|
throw new TicketingException(DUPLICATE_PAYMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = TicketStatus.RESERVATION;
|
status = TicketStatus.RESERVATION;
|
||||||
@@ -64,7 +71,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 ErrorCode.throwDuplicatePayment();
|
throw new TicketingException(DUPLICATE_PAYMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = TicketStatus.SOLD;
|
status = TicketStatus.SOLD;
|
||||||
@@ -74,10 +81,30 @@ public class Ticket extends AbstractEntity {
|
|||||||
|
|
||||||
public Ticket cancel() {
|
public Ticket cancel() {
|
||||||
if (!TicketStatus.RESERVATION.equals(status)) {
|
if (!TicketStatus.RESERVATION.equals(status)) {
|
||||||
throw ErrorCode.throwBadRequestPaymentCancel();
|
throw new TicketingException(BAD_REQUEST_PAYMENT_CANCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
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,7 +1,6 @@
|
|||||||
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;
|
||||||
@@ -17,8 +16,8 @@ public interface MovieRepository extends JpaRepository<Movie, Long> {
|
|||||||
|
|
||||||
@Query(value = "SELECT m "
|
@Query(value = "SELECT m "
|
||||||
+ "FROM Movie m "
|
+ "FROM Movie m "
|
||||||
+ "WHERE title = :title "
|
+ "WHERE m.title = :title "
|
||||||
+ "AND deleted_at IS NULL")
|
+ "AND m.deletedAt IS NULL")
|
||||||
Optional<Movie> findValidMovieWithTitle(String title);
|
Optional<Movie> findValidMovieWithTitle(String title);
|
||||||
|
|
||||||
@Query(value = "SELECT * "
|
@Query(value = "SELECT * "
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ 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;
|
||||||
@@ -39,14 +38,12 @@ public class MovieServiceImpl implements MovieService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MovieListDTO getMovies() {
|
public List<MovieDTO> getMovies() {
|
||||||
List<Movie> movies = movieRepository.findValidMovies();
|
List<Movie> movies = movieRepository.findValidMovies();
|
||||||
|
|
||||||
List<MovieDTO> movieDtos = movies.stream()
|
return movies.stream()
|
||||||
.map(movie -> movie.toMovieDTO())
|
.map(movie -> movie.toMovieDTO())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
return new MovieListDTO(movieDtos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ 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;
|
||||||
@@ -56,7 +54,7 @@ public class MovieTimeServiceImpl implements MovieTimeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MovieTimeListDTO getMovieTimes(Long movieId, LocalDate runningDate) {
|
public List<MovieTimeDTO> 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);
|
||||||
@@ -64,11 +62,9 @@ public class MovieTimeServiceImpl implements MovieTimeService {
|
|||||||
|
|
||||||
List<MovieTime> movieTimes = movieTimeRepository.findValidMovieTimes(movie, startOfDay, endOfDay);
|
List<MovieTime> movieTimes = movieTimeRepository.findValidMovieTimes(movie, startOfDay, endOfDay);
|
||||||
|
|
||||||
List<MovieTimeDTO> movieTimeDtos = movieTimes.stream()
|
return movieTimes.stream()
|
||||||
.map(movieTime -> movieTime.toMovieTimeDTO())
|
.map(movieTime -> movieTime.toMovieTimeDTO())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
return new MovieTimeListDTO(movieTimeDtos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
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,22 +1,25 @@
|
|||||||
package com.ticketing.server.movie.service;
|
package com.ticketing.server.movie.service;
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.ErrorCode;
|
import static com.ticketing.server.global.exception.ErrorCode.INVALID_TICKET_ID;
|
||||||
import com.ticketing.server.movie.domain.MovieTime;
|
import static com.ticketing.server.global.exception.ErrorCode.MOVIE_TIME_NOT_FOUND;
|
||||||
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
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.TicketDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
import com.ticketing.server.movie.service.dto.TicketIdsDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketListDTO;
|
import com.ticketing.server.movie.service.dto.TicketRefundDTO;
|
||||||
import com.ticketing.server.movie.service.dto.TicketReservationDTO;
|
|
||||||
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;
|
||||||
@@ -33,66 +36,44 @@ 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 MovieTimeRepository movieTimeRepository;
|
||||||
|
private final TicketLockService ticketLockService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TicketListDTO getTickets(@NotNull Long movieTimeId) {
|
public List<TicketDTO> getTickets(@NotNull Long movieTimeId) {
|
||||||
MovieTime movieTime = movieTimeRepository.findById(movieTimeId)
|
MovieTime movieTime = movieTimeRepository.findById(movieTimeId)
|
||||||
.orElseThrow(ErrorCode::throwMovieTimeNotFound);
|
.orElseThrow(() -> new TicketingException(MOVIE_TIME_NOT_FOUND));
|
||||||
|
|
||||||
List<TicketDTO> tickets = ticketRepository.findValidTickets(movieTime)
|
return ticketRepository.findValidTickets(movieTime)
|
||||||
.stream()
|
.stream()
|
||||||
.map(TicketDTO::new)
|
.map(TicketDTO::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
return new TicketListDTO(tickets);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TicketDetailsDTO findTicketsByPaymentId(@NotNull Long paymentId) {
|
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 ErrorCode.throwPaymentIdNotFound();
|
throw new TicketingException(PAYMENT_ID_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TicketDetailsDTO(ticketDetails);
|
return ticketDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public TicketsReservationDTO ticketReservation(@NotEmptyCollection List<Long> ticketIds) {
|
public TicketsReservationDTO ticketReservation(@NotEmptyCollection List<Long> ticketIds) {
|
||||||
List<Ticket> tickets = getTicketsByInTicketIds(ticketIds);
|
return ticketLockService.ticketReservation(new TicketIdsDTO(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) {
|
||||||
List<Ticket> tickets = getTicketsByInTicketIds(ticketIds);
|
return ticketLockService.ticketSold(paymentId, new TicketIdsDTO(ticketIds));
|
||||||
|
|
||||||
List<TicketSoldDTO> soldDtoList = tickets.stream()
|
|
||||||
.map(ticket -> ticket.makeSold(paymentId))
|
|
||||||
.map(TicketSoldDTO::new)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
return new TicketsSoldDTO(paymentId, soldDtoList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,27 +82,28 @@ 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(ticketIds);
|
return new TicketsCancelDTO(tickets);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 ErrorCode.throwInvalidTicketId();
|
throw new TicketingException(INVALID_TICKET_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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,18 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
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,18 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.dto;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.application.response.TicketListResponse;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class TicketListDTO {
|
|
||||||
|
|
||||||
private final List<TicketDTO> ticketDtos;
|
|
||||||
|
|
||||||
public TicketListResponse toResponse() {
|
|
||||||
return new TicketListResponse(ticketDtos);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
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,16 +1,22 @@
|
|||||||
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 lombok.AllArgsConstructor;
|
import java.util.stream.Collectors;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
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,14 +1,15 @@
|
|||||||
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.MovieListDTO;
|
import com.ticketing.server.movie.service.dto.MovieDTO;
|
||||||
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);
|
||||||
|
|
||||||
MovieListDTO getMovies();
|
List<MovieDTO> getMovies();
|
||||||
|
|
||||||
DeletedMovieDTO deleteMovie(Long id);
|
DeletedMovieDTO deleteMovie(Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,18 @@ 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.MovieTimeListDTO;
|
import com.ticketing.server.movie.service.dto.MovieTimeDTO;
|
||||||
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);
|
||||||
|
|
||||||
MovieTimeListDTO getMovieTimes(Long movieId, LocalDate runningDate);
|
List<MovieTimeDTO> getMovieTimes(Long movieId, LocalDate runningDate);
|
||||||
|
|
||||||
Movie findMovieById(Long movieId);
|
Movie findMovieById(Long movieId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
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.service.dto.TicketDetailsDTO;
|
import com.ticketing.server.movie.domain.Ticket;
|
||||||
import com.ticketing.server.movie.service.dto.TicketListDTO;
|
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 {
|
||||||
|
|
||||||
TicketListDTO getTickets(@NotNull Long movieTimeId);
|
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);
|
||||||
|
|
||||||
@@ -21,4 +26,6 @@ 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,7 +125,8 @@ 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,8 +3,10 @@ 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;
|
||||||
@@ -23,4 +25,8 @@ 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,11 +2,14 @@ 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 {
|
||||||
@@ -18,4 +21,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
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,12 +7,17 @@ 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.service.dto.TicketDetailsDTO;
|
import com.ticketing.server.movie.domain.Ticket;
|
||||||
|
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;
|
||||||
@@ -27,8 +32,8 @@ public class MovieClientImpl implements MovieClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TicketDetailsResponse getTicketsByPaymentId(@NotNull Long paymentId) {
|
public TicketDetailsResponse getTicketsByPaymentId(@NotNull Long paymentId) {
|
||||||
TicketDetailsDTO ticketDetails = ticketService.findTicketsByPaymentId(paymentId);
|
List<TicketDetailDTO> ticketDetails = ticketService.findTicketsByPaymentId(paymentId);
|
||||||
return ticketDetails.toResponse();
|
return new TicketDetailsResponse(ticketDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -49,4 +54,16 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.ticketing.server.payment.api.impl;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class TicketsRefundRequest {
|
||||||
|
|
||||||
|
private final Long paymentId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,18 +1,25 @@
|
|||||||
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.response.PaymentDetailResponse;
|
import com.ticketing.server.payment.application.request.PaymentRefundRequest;
|
||||||
import com.ticketing.server.payment.application.response.SimplePaymentsResponse;
|
|
||||||
import com.ticketing.server.payment.service.dto.PaymentCancelDTO;
|
|
||||||
import com.ticketing.server.payment.application.response.PaymentCancelResponse;
|
import com.ticketing.server.payment.application.response.PaymentCancelResponse;
|
||||||
import com.ticketing.server.payment.service.dto.PaymentCompleteDTO;
|
|
||||||
import com.ticketing.server.payment.application.response.PaymentCompleteResponse;
|
import com.ticketing.server.payment.application.response.PaymentCompleteResponse;
|
||||||
|
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.service.AdminKakaoPayRefundService;
|
||||||
|
import com.ticketing.server.payment.service.MyKakaoPayRefundService;
|
||||||
|
import com.ticketing.server.payment.service.dto.PaymentCancelDTO;
|
||||||
|
import com.ticketing.server.payment.service.dto.PaymentCompleteDTO;
|
||||||
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;
|
||||||
@@ -37,9 +44,11 @@ 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(UserGrade.ROLES.USER)
|
@Secured(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);
|
||||||
|
|
||||||
@@ -48,7 +57,7 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/detail")
|
@GetMapping("/detail")
|
||||||
@Secured(UserGrade.ROLES.USER)
|
@Secured(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);
|
||||||
|
|
||||||
@@ -57,7 +66,7 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/ready")
|
@PostMapping("/ready")
|
||||||
@Secured(UserGrade.ROLES.USER)
|
@Secured(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());
|
||||||
|
|
||||||
@@ -66,7 +75,7 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/complete")
|
@GetMapping("/complete")
|
||||||
@Secured(UserGrade.ROLES.USER)
|
@Secured(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) {
|
||||||
@@ -77,7 +86,7 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/cancel")
|
@GetMapping("/cancel")
|
||||||
@Secured(UserGrade.ROLES.USER)
|
@Secured(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());
|
||||||
|
|
||||||
@@ -85,4 +94,22 @@ 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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.ticketing.server.payment.application.request;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class PaymentRefundRequest {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long paymentId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
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,4 +82,7 @@ public class Payment extends AbstractEntity {
|
|||||||
this.totalPrice = totalPrice;
|
this.totalPrice = totalPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refund() {
|
||||||
|
status = PaymentStatus.REFUNDED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
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,6 +76,10 @@ 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();
|
||||||
@@ -95,21 +99,18 @@ public class PaymentApisServiceImpl implements PaymentApisService {
|
|||||||
);
|
);
|
||||||
KakaoPayReadyResponse response = kakaoPayClient.ready(kakaoPayProperties.getAuthorization(), request);
|
KakaoPayReadyResponse response = kakaoPayClient.ready(kakaoPayProperties.getAuthorization(), request);
|
||||||
|
|
||||||
PaymentCache paymentReady = new PaymentCache(
|
paymentCacheRepository.save(
|
||||||
userResponse.getEmail(),
|
new PaymentCache(
|
||||||
movieTitle,
|
userResponse.getEmail(),
|
||||||
response.getTid(),
|
movieTitle,
|
||||||
ticketIds,
|
response.getTid(),
|
||||||
userAlternateId,
|
ticketIds,
|
||||||
paymentNumber
|
userAlternateId,
|
||||||
|
paymentNumber,
|
||||||
|
request.getTotalAmount()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
paymentCacheRepository.findByEmail(userResponse.getEmail())
|
|
||||||
.ifPresentOrElse(
|
|
||||||
paymentCache -> ErrorCode.throwBadRequestPaymentReady()
|
|
||||||
, () -> paymentCacheRepository.save(paymentReady)
|
|
||||||
);
|
|
||||||
|
|
||||||
return new PaymentReadyDTO(response);
|
return new PaymentReadyDTO(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +120,13 @@ 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(
|
||||||
@@ -132,12 +140,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
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,9 +4,13 @@ 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,8 +1,6 @@
|
|||||||
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;
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import com.ticketing.server.global.redis.RefreshRedisRepository;
|
|||||||
import com.ticketing.server.global.redis.RefreshToken;
|
import com.ticketing.server.global.redis.RefreshToken;
|
||||||
import com.ticketing.server.global.security.jwt.JwtProperties;
|
import com.ticketing.server.global.security.jwt.JwtProperties;
|
||||||
import com.ticketing.server.global.security.jwt.JwtProvider;
|
import com.ticketing.server.global.security.jwt.JwtProvider;
|
||||||
import com.ticketing.server.user.service.dto.TokenDTO;
|
|
||||||
import com.ticketing.server.user.service.dto.DeleteRefreshTokenDTO;
|
import com.ticketing.server.user.service.dto.DeleteRefreshTokenDTO;
|
||||||
|
import com.ticketing.server.user.service.dto.TokenDTO;
|
||||||
import com.ticketing.server.user.service.interfaces.AuthenticationService;
|
import com.ticketing.server.user.service.interfaces.AuthenticationService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
@@ -40,8 +40,14 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
|||||||
// refresh 토큰이 있으면 수정, 없으면 생성
|
// refresh 토큰이 있으면 수정, 없으면 생성
|
||||||
refreshRedisRepository.findByEmail(email)
|
refreshRedisRepository.findByEmail(email)
|
||||||
.ifPresentOrElse(
|
.ifPresentOrElse(
|
||||||
tokenEntity -> tokenEntity.changeToken(tokenDto.getRefreshToken()),
|
tokenEntity -> refreshRedisRepository.save(
|
||||||
() -> refreshRedisRepository.save(new RefreshToken(email, tokenDto.getRefreshToken()))
|
tokenEntity.changeToken(
|
||||||
|
tokenDto.getRefreshToken()
|
||||||
|
)
|
||||||
|
),
|
||||||
|
() -> refreshRedisRepository.save(
|
||||||
|
new RefreshToken(email, tokenDto.getRefreshToken())
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return tokenDto;
|
return tokenDto;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@@ -21,7 +20,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(ErrorCode::throwEmailNotFound);
|
.orElseThrow(() -> new UsernameNotFoundException(email));
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserDetails createUserDetails(User user) {
|
private UserDetails createUserDetails(User user) {
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
server:
|
||||||
|
port: 8443
|
||||||
|
address: 0.0.0.0
|
||||||
|
|
||||||
|
http:
|
||||||
|
port: 8080
|
||||||
|
|
||||||
|
ssl:
|
||||||
|
key-store: classpath:keystore/ticketing.p12
|
||||||
|
key-store-password: ENC(OMvGcpZLpggFTiGNkqNe66Zq/SmJXF6o)
|
||||||
|
key-store-type: PKCS12
|
||||||
|
|
||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mysql://ticketing-db/ticketing?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
|
||||||
|
username: ENC(LowN1n4w0Ep/DqLD8+q5Bq6AXM4b8e3V)
|
||||||
|
password: ENC(OMvGcpZLpggFTiGNkqNe66Zq/SmJXF6o)
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
|
||||||
|
jpa:
|
||||||
|
properties:
|
||||||
|
hibernate:
|
||||||
|
show_sql: true
|
||||||
|
format_sql: true
|
||||||
|
hibernate:
|
||||||
|
ddl-auto: validate
|
||||||
|
|
||||||
|
redis:
|
||||||
|
host: 172.18.0.3
|
||||||
|
port: 6379
|
||||||
|
|
||||||
|
application:
|
||||||
|
name: monitoring
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,24 @@ spring:
|
|||||||
config:
|
config:
|
||||||
import: "optional:configserver:"
|
import: "optional:configserver:"
|
||||||
|
|
||||||
|
application:
|
||||||
|
name: monitoring
|
||||||
|
|
||||||
|
management:
|
||||||
|
endpoint:
|
||||||
|
metrics:
|
||||||
|
enabled: true
|
||||||
|
prometheus:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: health, info, metrics, prometheus
|
||||||
|
|
||||||
|
metrics:
|
||||||
|
tags:
|
||||||
|
application: ${spring.application.name}
|
||||||
|
|
||||||
jasypt:
|
jasypt:
|
||||||
encryptor:
|
encryptor:
|
||||||
|
|||||||
BIN
server/src/main/resources/keystore/ticketing.p12
Normal file
BIN
server/src/main/resources/keystore/ticketing.p12
Normal file
Binary file not shown.
@@ -0,0 +1,120 @@
|
|||||||
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.ticketing.server.movie.aop;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class TicketLockAspectTest {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ 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;
|
||||||
@@ -165,10 +166,94 @@ 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,15 +1,22 @@
|
|||||||
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.MovieListDTO;
|
import com.ticketing.server.movie.service.dto.RegisteredMovieDTO;
|
||||||
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;
|
||||||
@@ -21,9 +28,7 @@ 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;
|
||||||
@@ -39,10 +44,10 @@ public class MovieServiceImplTest {
|
|||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
MovieListDTO movieListDto = movieService.getMovies();
|
List<MovieDTO> movieDtos = movieService.getMovies();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(movieListDto.getMovieDtos().isEmpty());
|
assertTrue(movieDtos.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -55,11 +60,80 @@ public class MovieServiceImplTest {
|
|||||||
when(movieRepository.findValidMovies())
|
when(movieRepository.findValidMovies())
|
||||||
.thenReturn(movies);
|
.thenReturn(movies);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
MovieListDTO movieListDto = movieService.getMovies();
|
List<MovieDTO> movieDtos = movieService.getMovies();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(!movieListDto.getMovieDtos().isEmpty());
|
assertTrue(!movieDtos.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,15 +1,23 @@
|
|||||||
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.service.dto.MovieTimeListDTO;
|
import com.ticketing.server.movie.domain.repository.TheaterRepository;
|
||||||
|
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;
|
||||||
@@ -27,11 +35,15 @@ 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;
|
||||||
|
|
||||||
@@ -39,7 +51,7 @@ public class MovieTimeServiceImplTest {
|
|||||||
MovieTimeServiceImpl movieTimeService;
|
MovieTimeServiceImpl movieTimeService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("MovieTime Service Test - get empty list when there are no valid movie times")
|
@DisplayName("MovieTime Service Test - get empty list when there is no valid movie time")
|
||||||
void shouldGetEmptyList() {
|
void shouldGetEmptyList() {
|
||||||
// given
|
// given
|
||||||
Movie movie = new Movie(title, 106L);
|
Movie movie = new Movie(title, 106L);
|
||||||
@@ -51,10 +63,10 @@ public class MovieTimeServiceImplTest {
|
|||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
MovieTimeListDTO movieTimeListDto = movieTimeService.getMovieTimes(any(), LocalDate.now());
|
List<MovieTimeDTO> movieTimeDtos = movieTimeService.getMovieTimes(any(), LocalDate.now());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(movieTimeListDto.getMovieTimeDtos().isEmpty());
|
assertTrue(movieTimeDtos.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -76,10 +88,82 @@ public class MovieTimeServiceImplTest {
|
|||||||
.thenReturn(movieTimes);
|
.thenReturn(movieTimes);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
MovieTimeListDTO movieTimeListDto = movieTimeService.getMovieTimes(any(), LocalDate.of(2022, 07, 01));
|
List<MovieTimeDTO> movieTimeDtos = movieTimeService.getMovieTimes(any(), LocalDate.of(2022, 07, 01));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(!movieTimeListDto.getMovieTimeDtos().isEmpty());
|
assertTrue(!movieTimeDtos.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
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,8 +10,6 @@ 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;
|
||||||
@@ -53,8 +51,7 @@ class TicketServiceImplTest {
|
|||||||
when(ticketRepository.findTicketFetchJoinByPaymentId(1L)).thenReturn(List.of(tickets.get(0)));
|
when(ticketRepository.findTicketFetchJoinByPaymentId(1L)).thenReturn(List.of(tickets.get(0)));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TicketDetailsDTO ticketDetailDto = ticketService.findTicketsByPaymentId(1L);
|
List<TicketDetailDTO> ticketDetails = ticketService.findTicketsByPaymentId(1L);
|
||||||
List<TicketDetailDTO> ticketDetails = ticketDetailDto.getTicketDetails();
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertAll(
|
assertAll(
|
||||||
@@ -63,39 +60,4 @@ 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,7 +57,8 @@ class PaymentServiceImplTest {
|
|||||||
"T2d03c9130bf237a97001",
|
"T2d03c9130bf237a97001",
|
||||||
List.of(3L),
|
List.of(3L),
|
||||||
userAlternateId,
|
userAlternateId,
|
||||||
1241242343245L
|
1241242343245L,
|
||||||
|
15_000
|
||||||
),
|
),
|
||||||
KAKAO_PAY,
|
KAKAO_PAY,
|
||||||
SOLD,
|
SOLD,
|
||||||
@@ -70,7 +71,8 @@ class PaymentServiceImplTest {
|
|||||||
"T2d03c9130bf237a97002",
|
"T2d03c9130bf237a97002",
|
||||||
List.of(3L),
|
List.of(3L),
|
||||||
userAlternateId,
|
userAlternateId,
|
||||||
12412343212445L
|
12412343212445L,
|
||||||
|
30_000
|
||||||
),
|
),
|
||||||
KAKAO_PAY,
|
KAKAO_PAY,
|
||||||
SOLD,
|
SOLD,
|
||||||
|
|||||||
@@ -76,7 +76,8 @@ 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,
|
||||||
@@ -91,7 +92,8 @@ 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