Compare commits
10 Commits
feature/ge
...
feature/ge
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6966e5e1e | ||
|
|
d4385d15a7 | ||
|
|
096b1dadf3 | ||
|
|
409b6f7f53 | ||
|
|
8b81fc0713 | ||
|
|
09cb4a3767 | ||
|
|
648638860c | ||
|
|
6f14c96931 | ||
|
|
e009c2786c | ||
|
|
cb79ec5e57 |
35
README.md
35
README.md
@@ -1,5 +1,5 @@
|
|||||||
# 🍿 Ticketing
|
# 🍿 Ticketing
|
||||||
영화 예매 서비스
|
영화 예매 사이트를 대용량 트래픽에 대응할 수 있도록 설계.
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
@@ -8,13 +8,37 @@
|
|||||||
- 기획 및 설계 : 22.04.13 ~
|
- 기획 및 설계 : 22.04.13 ~
|
||||||
- 프로젝트 구현 :
|
- 프로젝트 구현 :
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
<br/><br/>
|
## 🎯 프로젝트 주요 관심사
|
||||||
|
- OOP(객체 지향 프로그래밍)의 장점을 최대한 활용
|
||||||
|
- 테스트 코드를 통한 믿을 수 있는 코드 작성
|
||||||
|
- 대용량 트래픽을 고려한 확장 가능한 설계 및 성능 튜닝
|
||||||
|
- 코드리뷰를 통해 코드 품질 향상
|
||||||
|
- 코드 컨벤션 준수하여 코드 통일성 유지
|
||||||
|
|
||||||
## 🎯 프로젝트 목표
|
<br/>
|
||||||
|
|
||||||
|
## 🛠 기술스택
|
||||||
|
- Java 11
|
||||||
|
- Spring Boot 2.6.7 (당시 최신 GA 버전)
|
||||||
|
- Gradle Kotlin DSL
|
||||||
|
- Spring Security
|
||||||
|
- Junit 5
|
||||||
|
- Hibernate / SpringJPA
|
||||||
|
- MySQL 8.0
|
||||||
|
- Redis
|
||||||
|
|
||||||
<br/><br/>
|
<br/>
|
||||||
|
|
||||||
|
## Wiki
|
||||||
|
- [Git Branch 전략](https://github.com/f-lab-edu/Ticketing/wiki#-git-branch-%EC%A0%84%EB%9E%B5)
|
||||||
|
- [Code Convention](https://github.com/f-lab-edu/Ticketing/wiki#-code-convention)
|
||||||
|
- [패키지 구조](https://github.com/f-lab-edu/Ticketing/wiki#-%ED%8C%A8%ED%82%A4%EC%A7%80-%EA%B5%AC%EC%A1%B0)
|
||||||
|
- [Use Case](https://github.com/f-lab-edu/Ticketing/wiki/Use-Case)
|
||||||
|
- [Prototype](https://github.com/f-lab-edu/Ticketing/wiki/Prototype)
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
## 🧩 ERD
|
## 🧩 ERD
|
||||||
|
|
||||||
@@ -51,7 +75,6 @@ erDiagram
|
|||||||
bigint id PK "상영시간표 ID"
|
bigint id PK "상영시간표 ID"
|
||||||
bigint movie_id FK "영화 ID"
|
bigint movie_id FK "영화 ID"
|
||||||
bigint theater_id FK "상영관 ID"
|
bigint theater_id FK "상영관 ID"
|
||||||
date running_date "상영 날짜"
|
|
||||||
int round "회차"
|
int round "회차"
|
||||||
time start_at "시작 시간"
|
time start_at "시작 시간"
|
||||||
time end_at "종료 시간"
|
time end_at "종료 시간"
|
||||||
@@ -94,5 +117,3 @@ erDiagram
|
|||||||
datetime updated_at "수정일시"
|
datetime updated_at "수정일시"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<br/><br/>
|
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-security")
|
implementation("org.springframework.boot:spring-boot-starter-security")
|
||||||
@@ -32,14 +30,15 @@ dependencies {
|
|||||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-log4j2")
|
implementation("org.springframework.boot:spring-boot-starter-log4j2")
|
||||||
implementation("org.projectlombok:lombok:1.18.20")
|
implementation("org.projectlombok:lombok:1.18.24")
|
||||||
implementation("io.springfox:springfox-boot-starter:3.0.0")
|
implementation("io.springfox:springfox-boot-starter:3.0.0")
|
||||||
implementation("io.springfox:springfox-swagger-ui:3.0.0")
|
implementation("io.springfox:springfox-swagger-ui:3.0.0")
|
||||||
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
||||||
implementation("com.lmax:disruptor:3.4.2")
|
implementation("com.lmax:disruptor:3.4.4")
|
||||||
implementation("io.jsonwebtoken:jjwt-api:0.11.2")
|
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
|
||||||
implementation("com.googlecode.json-simple:json-simple:1.1.1")
|
implementation("com.googlecode.json-simple:json-simple:1.1.1")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-redis")
|
implementation("org.springframework.boot:spring-boot-starter-data-redis")
|
||||||
|
implementation("com.google.code.findbugs:jsr305:3.0.2")
|
||||||
|
|
||||||
modules {
|
modules {
|
||||||
module("org.springframework.boot:spring-boot-starter-logging") {
|
module("org.springframework.boot:spring-boot-starter-logging") {
|
||||||
@@ -47,18 +46,14 @@ dependencies {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
|
||||||
testImplementation("org.springframework.security:spring-security-test")
|
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
|
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok")
|
compileOnly("org.projectlombok:lombok")
|
||||||
runtimeOnly("mysql:mysql-connector-java")
|
runtimeOnly("mysql:mysql-connector-java")
|
||||||
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.2")
|
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5")
|
||||||
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.2")
|
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
|
||||||
annotationProcessor("org.projectlombok:lombok")
|
annotationProcessor("org.projectlombok:lombok")
|
||||||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
||||||
|
|
||||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
|
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
testImplementation("org.springframework.security:spring-security-test")
|
testImplementation("org.springframework.security:spring-security-test")
|
||||||
}
|
}
|
||||||
@@ -66,3 +61,28 @@ dependencies {
|
|||||||
tasks.withType<Test> {
|
tasks.withType<Test> {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
create("intTest") {
|
||||||
|
compileClasspath += sourceSets.main.get().output
|
||||||
|
runtimeClasspath += sourceSets.main.get().output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val intTestImplementation by configurations.getting {
|
||||||
|
extendsFrom(configurations.implementation.get())
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations["intTestRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get())
|
||||||
|
configurations["intTestImplementation"].extendsFrom(configurations.testImplementation.get())
|
||||||
|
|
||||||
|
val integrationTest = task<Test>("integrationTest") {
|
||||||
|
description = "Runs integration tests."
|
||||||
|
group = "verification"
|
||||||
|
|
||||||
|
testClassesDirs = sourceSets["intTest"].output.classesDirs
|
||||||
|
classpath = sourceSets["intTest"].runtimeClasspath
|
||||||
|
shouldRunAfter("test")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.check { dependsOn(integrationTest) }
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class AuthControllerTest {
|
|||||||
|
|
||||||
private static final String LOGIN_URL = "/api/auth/token";
|
private static final String LOGIN_URL = "/api/auth/token";
|
||||||
private static final String REGISTER_URL = "/api/users";
|
private static final String REGISTER_URL = "/api/users";
|
||||||
|
private static final String USER_EMAIL = "ticketing@gmail.com";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
WebApplicationContext context;
|
WebApplicationContext context;
|
||||||
@@ -53,7 +54,7 @@ class AuthControllerTest {
|
|||||||
@DisplayName("로그인 인증 성공")
|
@DisplayName("로그인 인증 성공")
|
||||||
void loginSuccess() throws Exception {
|
void loginSuccess() throws Exception {
|
||||||
// given
|
// given
|
||||||
LoginRequest request = new LoginRequest("ticketing@gmail.com", "qwe123");
|
LoginRequest request = new LoginRequest(USER_EMAIL, "qwe123");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
ResultActions actions = mvc.perform(post(LOGIN_URL)
|
ResultActions actions = mvc.perform(post(LOGIN_URL)
|
||||||
@@ -69,7 +70,7 @@ class AuthControllerTest {
|
|||||||
@DisplayName("로그인 패스워드 인증 실패")
|
@DisplayName("로그인 패스워드 인증 실패")
|
||||||
void loginPasswordFail() throws Exception {
|
void loginPasswordFail() throws Exception {
|
||||||
// given
|
// given
|
||||||
LoginRequest request = new LoginRequest("ticketing@gmail.com", "qwe1234");
|
LoginRequest request = new LoginRequest(USER_EMAIL, "qwe1234");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
ResultActions actions = mvc.perform(post(LOGIN_URL)
|
ResultActions actions = mvc.perform(post(LOGIN_URL)
|
||||||
@@ -81,10 +82,6 @@ class AuthControllerTest {
|
|||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isUnauthorized());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String asJsonString(Object object) throws JsonProcessingException {
|
|
||||||
return objectMapper.writeValueAsString(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void init() throws Exception {
|
void init() throws Exception {
|
||||||
mvc = MockMvcBuilders
|
mvc = MockMvcBuilders
|
||||||
@@ -92,7 +89,7 @@ class AuthControllerTest {
|
|||||||
.apply(springSecurity())
|
.apply(springSecurity())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
SignUpRequest signUpRequest = new SignUpRequest("ticketing", "ticketing@gmail.com", "qwe123", "010-2240-7920");
|
SignUpRequest signUpRequest = new SignUpRequest("ticketing", USER_EMAIL, "qwe123", "010-1234-5678");
|
||||||
|
|
||||||
mvc.perform(post(REGISTER_URL)
|
mvc.perform(post(REGISTER_URL)
|
||||||
.content(asJsonString(signUpRequest))
|
.content(asJsonString(signUpRequest))
|
||||||
@@ -104,4 +101,8 @@ class AuthControllerTest {
|
|||||||
refreshRedisRepository.deleteAll();
|
refreshRedisRepository.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String asJsonString(Object object) throws JsonProcessingException {
|
||||||
|
return objectMapper.writeValueAsString(object);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.ticketing.server.user.application;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class UserControllerTest {
|
||||||
|
|
||||||
|
}
|
||||||
37
server/src/intTest/resources/application.yml
Normal file
37
server/src/intTest/resources/application.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mysql://localhost:3306/ticketing_test?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
|
||||||
|
username: ENC(LowN1n4w0Ep/DqLD8+q5Bq6AXM4b8e3V)
|
||||||
|
password: ENC(OMvGcpZLpggFTiGNkqNe66Zq/SmJXF6o)
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
redis:
|
||||||
|
host: localhost
|
||||||
|
port: 6379
|
||||||
|
|
||||||
|
jpa:
|
||||||
|
properties:
|
||||||
|
hibernate:
|
||||||
|
show_sql: true
|
||||||
|
format_sql: true
|
||||||
|
hibernate:
|
||||||
|
ddl-auto: create
|
||||||
|
|
||||||
|
mvc:
|
||||||
|
pathmatch:
|
||||||
|
matching-strategy: ant_path_matcher
|
||||||
|
|
||||||
|
jasypt:
|
||||||
|
encryptor:
|
||||||
|
bean: jasyptStringEncryptor
|
||||||
|
|
||||||
|
jwt:
|
||||||
|
access-header: Authorization
|
||||||
|
refresh-header: REFRESH_TOKEN
|
||||||
|
prefix: Bearer
|
||||||
|
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK
|
||||||
|
access-token-validity-in-seconds: 60
|
||||||
|
refresh-token-validity-in-seconds: 259200
|
||||||
|
|
||||||
|
tmdb:
|
||||||
|
api-key: 0d1503b6dcbfe1c514299b5564c649b8
|
||||||
|
read-access-token: eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwZDE1MDNiNmRjYmZlMWM1MTQyOTliNTU2NGM2NDliOCIsInN1YiI6IjYyOWYwODRlNzI2ZmIxMTA2NDA4MjI2NCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.rs8KZea8QLyashILiggWFx2s46lgUtzo-xSWoDgE58A
|
||||||
@@ -19,6 +19,7 @@ public enum ErrorCode {
|
|||||||
|
|
||||||
/* 404 NOT_FOUND : Resource 를 찾을 수 없음 */
|
/* 404 NOT_FOUND : Resource 를 찾을 수 없음 */
|
||||||
EMAIL_NOT_FOUND(NOT_FOUND, "해당 이메일을 찾을 수 없습니다."),
|
EMAIL_NOT_FOUND(NOT_FOUND, "해당 이메일을 찾을 수 없습니다."),
|
||||||
|
MOVIE_NOT_FOUND(NOT_FOUND, "해당 제목의 영화를 찾을 수 없습니다."),
|
||||||
REFRESH_TOKEN_NOT_FOUND(NOT_FOUND, "리프레쉬 토큰을 찾을 수 없습니다."),
|
REFRESH_TOKEN_NOT_FOUND(NOT_FOUND, "리프레쉬 토큰을 찾을 수 없습니다."),
|
||||||
|
|
||||||
/* 409 CONFLICT : Resource 의 현재 상태와 충돌. 보통 중복된 데이터 존재 */
|
/* 409 CONFLICT : Resource 의 현재 상태와 충돌. 보통 중복된 데이터 존재 */
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.antMatchers(HttpMethod.POST, "/api/auth/refresh").permitAll()
|
.antMatchers(HttpMethod.POST, "/api/auth/refresh").permitAll()
|
||||||
.antMatchers(HttpMethod.POST, "/api/users").permitAll()
|
.antMatchers(HttpMethod.POST, "/api/users").permitAll()
|
||||||
.antMatchers("/api/movies/**").permitAll()
|
.antMatchers("/api/movies/**").permitAll()
|
||||||
|
.antMatchers("/api/movieTimes/**").permitAll()
|
||||||
.antMatchers("/l7check").permitAll()
|
.antMatchers("/l7check").permitAll()
|
||||||
.antMatchers("/actuator/**").permitAll()
|
.antMatchers("/actuator/**").permitAll()
|
||||||
.antMatchers("/api/v3/", "/swagger-ui/**", "/swagger/", "/swagger-resources/**", "/v3/api-docs").permitAll()
|
.antMatchers("/api/v3/", "/swagger-ui/**", "/swagger/", "/swagger-resources/**", "/v3/api-docs").permitAll()
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.ticketing.server.movie.application;
|
||||||
|
|
||||||
|
import com.ticketing.server.movie.application.response.MovieTimeListResponse;
|
||||||
|
import com.ticketing.server.movie.service.interfaces.MovieTimeService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/movieTimes")
|
||||||
|
@Api(value = "MovieTime API", tags = {"Movie Time"})
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class MovieTimeController {
|
||||||
|
|
||||||
|
private final MovieTimeService movieTimeService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@ApiOperation(value = "영화 시간표 조회")
|
||||||
|
@Validated
|
||||||
|
public ResponseEntity<MovieTimeListResponse> getMovieTimes(
|
||||||
|
@ApiParam(value = "영화 제목", required = true) @RequestParam String title,
|
||||||
|
@ApiParam(value = "상영 날짜", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate runningDate) {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(MovieTimeListResponse.from(movieTimeService.getMovieTimes(title, runningDate)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.ticketing.server.movie.application;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class MovieTimesController {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.ticketing.server.movie.application.response;
|
package com.ticketing.server.movie.application.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.ticketing.server.movie.service.dto.MovieDto;
|
import com.ticketing.server.movie.service.dto.MovieDto;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -13,7 +12,6 @@ import lombok.Getter;
|
|||||||
public class MovieListResponse {
|
public class MovieListResponse {
|
||||||
|
|
||||||
@ApiModelProperty(value = "영화 제목")
|
@ApiModelProperty(value = "영화 제목")
|
||||||
@JsonProperty
|
|
||||||
private List<MovieDto> movieDtos;
|
private List<MovieDto> movieDtos;
|
||||||
|
|
||||||
public static MovieListResponse from(List<MovieDto> movieDtos) {
|
public static MovieListResponse from(List<MovieDto> movieDtos) {
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.ticketing.server.movie.application.response;
|
||||||
|
|
||||||
|
import com.ticketing.server.movie.service.dto.MovieTimeDto;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public class MovieTimeListResponse {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "영화 시간표 정보")
|
||||||
|
private List<MovieTimeDto> movieTimeDtos;
|
||||||
|
|
||||||
|
public static MovieTimeListResponse from(List<MovieTimeDto> movieTimeDtos) {
|
||||||
|
return new MovieTimeListResponse(movieTimeDtos);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,8 +22,4 @@ public class Movie extends AbstractEntity {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private Integer runningTime;
|
private Integer runningTime;
|
||||||
|
|
||||||
public MovieDto toDto() {
|
|
||||||
return new MovieDto(this.title);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
package com.ticketing.server.movie.domain;
|
package com.ticketing.server.movie.domain;
|
||||||
|
|
||||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
||||||
import java.time.LocalDate;
|
import com.ticketing.server.movie.service.dto.MovieTimeDto;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Getter
|
@Getter
|
||||||
public class MovieTimes extends AbstractEntity {
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MovieTime extends AbstractEntity {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@@ -23,9 +27,6 @@ public class MovieTimes extends AbstractEntity {
|
|||||||
@JoinColumn(name = "theater_id", referencedColumnName = "id", updatable = false)
|
@JoinColumn(name = "theater_id", referencedColumnName = "id", updatable = false)
|
||||||
private Theater theater;
|
private Theater theater;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private LocalDate runningDate;
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Integer round;
|
private Integer round;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ public class Ticket extends AbstractEntity {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "movie_times_id", referencedColumnName = "id", updatable = false)
|
@JoinColumn(name = "movie_times_id", referencedColumnName = "id", updatable = false)
|
||||||
private MovieTimes movieTimes;
|
private MovieTime movieTime;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "payment_id", referencedColumnName = "id", updatable = false)
|
@JoinColumn(name = "payment_id", referencedColumnName = "id", updatable = false)
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.ticketing.server.movie.domain.repository;
|
||||||
|
|
||||||
|
import com.ticketing.server.movie.domain.Movie;
|
||||||
|
import com.ticketing.server.movie.domain.MovieTime;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface MovieTimeRepository extends JpaRepository<MovieTime, Long> {
|
||||||
|
|
||||||
|
@Query(value = "SELECT mt "
|
||||||
|
+ "FROM MovieTime mt "
|
||||||
|
+ "JOIN FETCH mt.movie "
|
||||||
|
+ "WHERE mt.movie = :movie "
|
||||||
|
+ "AND mt.startAt BETWEEN :startOfDay AND :endOfDay ")
|
||||||
|
List<MovieTime> findValidMovieTimes(Movie movie, LocalDateTime startOfDay, LocalDateTime endOfDay);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain.repository;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.domain.MovieTimes;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface MovieTimesRepository extends JpaRepository<MovieTimes, Long> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -21,7 +21,7 @@ public class MovieServiceImpl implements MovieService {
|
|||||||
List<Movie> movies = movieRepository.findValidMovies();
|
List<Movie> movies = movieRepository.findValidMovies();
|
||||||
|
|
||||||
return movies.stream()
|
return movies.stream()
|
||||||
.map(movie -> movie.toDto())
|
.map(MovieDto::from)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.ticketing.server.movie.service;
|
||||||
|
|
||||||
|
import static com.ticketing.server.global.exception.ErrorCode.MOVIE_NOT_FOUND;
|
||||||
|
|
||||||
|
import com.ticketing.server.global.exception.TicketingException;
|
||||||
|
import com.ticketing.server.movie.domain.Movie;
|
||||||
|
import com.ticketing.server.movie.domain.MovieTime;
|
||||||
|
import com.ticketing.server.movie.domain.repository.MovieRepository;
|
||||||
|
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
||||||
|
import com.ticketing.server.movie.service.dto.MovieTimeDto;
|
||||||
|
import com.ticketing.server.movie.service.interfaces.MovieTimeService;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class MovieTimeServiceImpl implements MovieTimeService {
|
||||||
|
|
||||||
|
private final MovieRepository movieRepository;
|
||||||
|
|
||||||
|
private final MovieTimeRepository movieTimeRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MovieTimeDto> getMovieTimes(String title, LocalDate runningDate) {
|
||||||
|
Movie movie = movieRepository.findByTitle(title)
|
||||||
|
.orElseThrow(MovieTimeServiceImpl::throwMovieNotFound);
|
||||||
|
|
||||||
|
LocalDateTime startOfDay = runningDate.atStartOfDay().plusHours(6);
|
||||||
|
LocalDateTime endOfDay = startOfDay.plusDays(1);
|
||||||
|
|
||||||
|
List<MovieTime> movieTimes = movieTimeRepository.findValidMovieTimes(movie, startOfDay, endOfDay);
|
||||||
|
|
||||||
|
return movieTimes.stream()
|
||||||
|
.map(MovieTimeDto::from)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RuntimeException throwMovieNotFound() {
|
||||||
|
throw new TicketingException(MOVIE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.interfaces.MovieTimesService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class MovieTimesServiceImpl implements MovieTimesService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.interfaces.TMDBService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class TMBDServiceImpl implements TMDBService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
package com.ticketing.server.movie.service.dto;
|
package com.ticketing.server.movie.service.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.ticketing.server.movie.domain.Movie;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@Getter
|
||||||
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class MovieDto {
|
public class MovieDto {
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
|
public static MovieDto from(Movie movie) {
|
||||||
|
return new MovieDto(movie.getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.ticketing.server.movie.service.dto;
|
||||||
|
|
||||||
|
import com.ticketing.server.movie.domain.MovieTime;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public class MovieTimeDto {
|
||||||
|
|
||||||
|
private Long movieTimeId;
|
||||||
|
|
||||||
|
private Integer theaterNumber;
|
||||||
|
|
||||||
|
private Integer round;
|
||||||
|
|
||||||
|
private LocalDateTime startAt;
|
||||||
|
|
||||||
|
private LocalDateTime endAt;
|
||||||
|
|
||||||
|
public static MovieTimeDto from(MovieTime movieTime) {
|
||||||
|
return new MovieTimeDto(movieTime.getId(), movieTime.getTheater().getTheaterNumber(),
|
||||||
|
movieTime.getRound(), movieTime.getStartAt(), movieTime.getEndAt());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.ticketing.server.movie.service.interfaces;
|
||||||
|
|
||||||
|
import com.ticketing.server.movie.service.dto.MovieTimeDto;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface MovieTimeService {
|
||||||
|
|
||||||
|
List<MovieTimeDto> getMovieTimes(String title, LocalDate runningDate);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.interfaces;
|
|
||||||
|
|
||||||
public interface MovieTimesService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.interfaces;
|
|
||||||
|
|
||||||
public interface TMDBService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.ticketing.server;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class ServerApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.ticketing.server.movie.domain.repository;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import org.junit.jupiter.api.MethodOrderer;
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@Transactional
|
||||||
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
|
public class MovieTimeRepositoryTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
MovieTimeRepository movieTimeRepository;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -35,14 +35,14 @@ public class MovieServiceImplTest {
|
|||||||
@DisplayName("Movie Service Test - get movies when there is no movie")
|
@DisplayName("Movie Service Test - get movies when there is no movie")
|
||||||
void shouldGetEmptyList() {
|
void shouldGetEmptyList() {
|
||||||
// given
|
// given
|
||||||
when(movieRepository.findValidMovies()).thenReturn(Collections.emptyList());
|
when(movieRepository.findValidMovies())
|
||||||
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<MovieDto> movieDtoList = movieService.getMovies();
|
List<MovieDto> movieDtoList = movieService.getMovies();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(movieDtoList.isEmpty());
|
assertTrue(movieDtoList.isEmpty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -50,11 +50,12 @@ public class MovieServiceImplTest {
|
|||||||
void shouldAbleToGetMovies() {
|
void shouldAbleToGetMovies() {
|
||||||
// given
|
// given
|
||||||
movie = new Movie("범죄도시2", 106);
|
movie = new Movie("범죄도시2", 106);
|
||||||
movieDto = movie.toDto();
|
movieDto = movieDto.from(movie);
|
||||||
movies.add(movie);
|
movies.add(movie);
|
||||||
movieDtos.add(movieDto);
|
movieDtos.add(movieDto);
|
||||||
|
|
||||||
when(movieRepository.findValidMovies()).thenReturn(movies);
|
when(movieRepository.findValidMovies())
|
||||||
|
.thenReturn(movies);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<MovieDto> movieDtoList = movieService.getMovies();
|
List<MovieDto> movieDtoList = movieService.getMovies();
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.ticketing.server.movie.service;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
|
||||||
|
import com.ticketing.server.movie.domain.Movie;
|
||||||
|
import com.ticketing.server.movie.domain.MovieTime;
|
||||||
|
import com.ticketing.server.movie.domain.Theater;
|
||||||
|
import com.ticketing.server.movie.domain.repository.MovieRepository;
|
||||||
|
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
||||||
|
import com.ticketing.server.movie.service.dto.MovieTimeDto;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
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)
|
||||||
|
public class MovieTimeServiceImplTest {
|
||||||
|
|
||||||
|
String title = "범죄도시2";
|
||||||
|
List<MovieTime> movieTimes = new ArrayList<>();
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
MovieRepository movieRepository;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
MovieTimeRepository movieTimeRepository;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
MovieTimeServiceImpl movieTimeService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("MovieTime Service Test - get empty list when there is no valid movie times")
|
||||||
|
void shouldGetEmptyList() {
|
||||||
|
// given
|
||||||
|
Movie movie = new Movie(title, 106);
|
||||||
|
|
||||||
|
when(movieRepository.findByTitle(title))
|
||||||
|
.thenReturn(Optional.of(movie));
|
||||||
|
|
||||||
|
when(movieTimeRepository.findValidMovieTimes(any(), any(), any()))
|
||||||
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
|
// when
|
||||||
|
List<MovieTimeDto> movieTimeDtoList = movieTimeService.getMovieTimes(title, LocalDate.now());
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertTrue(movieTimeDtoList.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("MovieTime Service Test - get list when there is valid movie times")
|
||||||
|
void shouldGetMovieTimeList() {
|
||||||
|
// given
|
||||||
|
Movie movie = new Movie(title, 106);
|
||||||
|
Theater theater = new Theater(1, 100);
|
||||||
|
MovieTime movieTime = new MovieTime(movie, theater, 1,
|
||||||
|
LocalDateTime.of(2022, 7, 1, 17, 0, 0),
|
||||||
|
LocalDateTime.of(2022, 7, 1, 18, 56, 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
movieTimes.add(movieTime);
|
||||||
|
|
||||||
|
when(movieRepository.findByTitle(title))
|
||||||
|
.thenReturn(Optional.of(movie));
|
||||||
|
|
||||||
|
when(movieTimeRepository.findValidMovieTimes(any(), any(), any()))
|
||||||
|
.thenReturn(movieTimes);
|
||||||
|
|
||||||
|
// when
|
||||||
|
List<MovieTimeDto> movieTimeDtoList = movieTimeService.getMovieTimes(title, LocalDate.of(2022, 07, 01));
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertTrue(!movieTimeDtoList.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.ticketing.server.user.domain.repository;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.domain.UserGrade;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@Transactional
|
|
||||||
class UserRepositoryTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
UserRepository userRepository;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void 유저레포지토리테스트() {
|
|
||||||
// given
|
|
||||||
User user = new User("유저1", "email@gmail.com", "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
|
||||||
|
|
||||||
// when
|
|
||||||
userRepository.save(user);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(user).isNotNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,28 +1,3 @@
|
|||||||
spring:
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://localhost:3306/ticketing_test?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
|
|
||||||
username: ENC(LowN1n4w0Ep/DqLD8+q5Bq6AXM4b8e3V)
|
|
||||||
password: ENC(OMvGcpZLpggFTiGNkqNe66Zq/SmJXF6o)
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
redis:
|
|
||||||
host: localhost
|
|
||||||
port: 6379
|
|
||||||
|
|
||||||
jpa:
|
|
||||||
properties:
|
|
||||||
hibernate:
|
|
||||||
show_sql: true
|
|
||||||
format_sql: true
|
|
||||||
hibernate:
|
|
||||||
ddl-auto: create
|
|
||||||
|
|
||||||
mvc:
|
|
||||||
pathmatch:
|
|
||||||
matching-strategy: ant_path_matcher
|
|
||||||
|
|
||||||
jasypt:
|
|
||||||
encryptor:
|
|
||||||
bean: jasyptStringEncryptor
|
|
||||||
|
|
||||||
jwt:
|
jwt:
|
||||||
access-header: Authorization
|
access-header: Authorization
|
||||||
@@ -31,7 +6,3 @@ jwt:
|
|||||||
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK
|
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK
|
||||||
access-token-validity-in-seconds: 60
|
access-token-validity-in-seconds: 60
|
||||||
refresh-token-validity-in-seconds: 259200
|
refresh-token-validity-in-seconds: 259200
|
||||||
|
|
||||||
tmdb:
|
|
||||||
api-key: 0d1503b6dcbfe1c514299b5564c649b8
|
|
||||||
read-access-token: eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwZDE1MDNiNmRjYmZlMWM1MTQyOTliNTU2NGM2NDliOCIsInN1YiI6IjYyOWYwODRlNzI2ZmIxMTA2NDA4MjI2NCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.rs8KZea8QLyashILiggWFx2s46lgUtzo-xSWoDgE58A
|
|
||||||
|
|||||||
Reference in New Issue
Block a user