Compare commits
16 Commits
feature/cr
...
feature/in
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15f93eec52 | ||
|
|
60ff034171 | ||
|
|
c23714f404 | ||
|
|
1bc78fa605 | ||
|
|
1dca969907 | ||
|
|
b92f6e7a6f | ||
|
|
aa666bd847 | ||
|
|
08ce8e6904 | ||
|
|
3cbb3f0ee8 | ||
|
|
58900e2331 | ||
|
|
358bbadf32 | ||
|
|
c816994d8c | ||
|
|
0a54967bbf | ||
|
|
7e2ef8c876 | ||
|
|
a310d2c059 | ||
|
|
cdfea7f6ac |
15
README.md
15
README.md
@@ -51,10 +51,10 @@ 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 "상영 날짜"
|
date date "상영 날짜"
|
||||||
int round "회차"
|
int round "회차"
|
||||||
time start_at "시작 시간"
|
time start_time "시작 시간"
|
||||||
time end_at "종료 시간"
|
time end_time "종료 시간"
|
||||||
datetime created_at "등록일시"
|
datetime created_at "등록일시"
|
||||||
datetime updated_at "수정일시"
|
datetime updated_at "수정일시"
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ erDiagram
|
|||||||
bigint seat_id FK "좌석 ID"
|
bigint seat_id FK "좌석 ID"
|
||||||
bigint movie_times_id FK "상영시간표 ID"
|
bigint movie_times_id FK "상영시간표 ID"
|
||||||
bigint payment_id FK "결제 ID"
|
bigint payment_id FK "결제 ID"
|
||||||
varchar status "상태 - 구매가능/예약진행중/판매완료"
|
varchar ticket_status "상태 - 구매가능/예약진행중/판매완료"
|
||||||
int ticket_price "가격"
|
int ticket_price "가격"
|
||||||
datetime created_at "등록일시"
|
datetime created_at "등록일시"
|
||||||
datetime updated_at "수정일시"
|
datetime updated_at "수정일시"
|
||||||
@@ -73,8 +73,8 @@ erDiagram
|
|||||||
bigint id PK "결제 ID"
|
bigint id PK "결제 ID"
|
||||||
bigint user_id FK "유저ID"
|
bigint user_id FK "유저ID"
|
||||||
varchar type "결제 타입 - 예) 네이버페이, 카카오페이"
|
varchar type "결제 타입 - 예) 네이버페이, 카카오페이"
|
||||||
varchar status "상태 - 완료/환불/실패"
|
varchar payment_status "상태 - 완료/환불/실패"
|
||||||
varchar failed_message "실패사유 - 컬럼명을 알아보기 쉬운가?"
|
varchar failed_reason "실패사유 - 컬럼명을 알아보기 쉬운가?"
|
||||||
varchar payment_number "예매번호"
|
varchar payment_number "예매번호"
|
||||||
int total_price "결제 금액"
|
int total_price "결제 금액"
|
||||||
datetime created_at "결제일시"
|
datetime created_at "결제일시"
|
||||||
@@ -83,10 +83,9 @@ erDiagram
|
|||||||
USER ||--o{ PAYMENT : ""
|
USER ||--o{ PAYMENT : ""
|
||||||
USER {
|
USER {
|
||||||
bigint id "회원"
|
bigint id "회원"
|
||||||
varchar name "이름"
|
|
||||||
varchar email "이메일"
|
|
||||||
varchar password "비밀번호"
|
varchar password "비밀번호"
|
||||||
varchar grade "등급 - 고객/임직원"
|
varchar grade "등급 - 고객/임직원"
|
||||||
|
varchar email "이메일"
|
||||||
varchar phone "휴대폰 번호"
|
varchar phone "휴대폰 번호"
|
||||||
boolean is_deleted "탈퇴여부"
|
boolean is_deleted "탈퇴여부"
|
||||||
datetime deleted_at "탈퇴일시"
|
datetime deleted_at "탈퇴일시"
|
||||||
|
|||||||
3
server/.gitignore
vendored
3
server/.gitignore
vendored
@@ -200,7 +200,4 @@ gradle-app.setting
|
|||||||
# JDT-specific (Eclipse Java Development Tools)
|
# JDT-specific (Eclipse Java Development Tools)
|
||||||
.classpath
|
.classpath
|
||||||
|
|
||||||
# log
|
|
||||||
/logs
|
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,visualstudiocode
|
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,visualstudiocode
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
id("org.springframework.boot") version "2.6.7"
|
id ("org.springframework.boot") version "2.6.7"
|
||||||
id("io.spring.dependency-management") version "1.0.11.RELEASE"
|
id ("io.spring.dependency-management") version "1.0.11.RELEASE"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "com.ticketing"
|
group = "com.ticketing"
|
||||||
@@ -26,14 +26,14 @@ repositories {
|
|||||||
|
|
||||||
|
|
||||||
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")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
implementation ("org.springframework.boot:spring-boot-starter-validation")
|
||||||
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("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
implementation ("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-log4j2")
|
implementation ("org.springframework.boot:spring-boot-starter-log4j2")
|
||||||
implementation("com.lmax:disruptor:3.4.2")
|
implementation ("com.lmax:disruptor:3.4.2")
|
||||||
|
|
||||||
modules {
|
modules {
|
||||||
module("org.springframework.boot:spring-boot-starter-logging") {
|
module("org.springframework.boot:spring-boot-starter-logging") {
|
||||||
@@ -41,12 +41,12 @@ dependencies {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok")
|
compileOnly ("org.projectlombok:lombok")
|
||||||
runtimeOnly("mysql:mysql-connector-java")
|
runtimeOnly ("mysql:mysql-connector-java")
|
||||||
annotationProcessor("org.projectlombok:lombok")
|
annotationProcessor ("org.projectlombok:lombok")
|
||||||
|
|
||||||
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")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<Test> {
|
tasks.withType<Test> {
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.ticketing.server.global.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
|
||||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class MessagesConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ResourceBundleMessageSource messageSource() {
|
|
||||||
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
|
|
||||||
messageSource.setBasename("i18n/messages");
|
|
||||||
messageSource.setDefaultEncoding("UTF-8");
|
|
||||||
|
|
||||||
return messageSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public LocalValidatorFactoryBean getValidator() {
|
|
||||||
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
|
|
||||||
factoryBean.setValidationMessageSource(messageSource());
|
|
||||||
|
|
||||||
return factoryBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.ticketing.server.global.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableWebSecurity
|
|
||||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public PasswordEncoder passwordEncoder() {
|
|
||||||
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
|
||||||
http
|
|
||||||
.cors().disable()
|
|
||||||
.csrf().disable()
|
|
||||||
.formLogin().disable()
|
|
||||||
.headers().frameOptions().disable();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.ticketing.server.global.validator.constraints;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.validator.constraintvalidators.PhoneValidator;
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
import javax.validation.Constraint;
|
|
||||||
import javax.validation.Payload;
|
|
||||||
|
|
||||||
@Target(ElementType.FIELD)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Constraint(validatedBy = {PhoneValidator.class})
|
|
||||||
@Documented
|
|
||||||
public @interface Phone {
|
|
||||||
|
|
||||||
String message() default "{validation.phone}";
|
|
||||||
|
|
||||||
Class<?>[] groups() default {};
|
|
||||||
|
|
||||||
Class<? extends Payload>[] payload() default {};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.ticketing.server.global.validator.constraintvalidators;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.validator.constraints.Phone;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import javax.validation.ConstraintValidator;
|
|
||||||
import javax.validation.ConstraintValidatorContext;
|
|
||||||
|
|
||||||
public class PhoneValidator implements ConstraintValidator<Phone, String> {
|
|
||||||
|
|
||||||
private static final String PATTERN = "\\d{3}-\\d{4}-\\d{4}";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
|
||||||
if (value == null || value.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Pattern.matches(PATTERN, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,36 +1,8 @@
|
|||||||
package com.ticketing.server.user.application;
|
package com.ticketing.server.user.application;
|
||||||
|
|
||||||
import com.ticketing.server.user.application.request.SignUpRequest;
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.service.UserServiceImpl;
|
|
||||||
import java.util.Optional;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
|
||||||
@RequestMapping("/user")
|
|
||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
private final UserServiceImpl userService;
|
|
||||||
private final PasswordEncoder passwordEncoder;
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public ResponseEntity<Object> register(@RequestBody @Valid SignUpRequest signUpRequest) {
|
|
||||||
Optional<User> user = userService.register(signUpRequest.toSignUp(passwordEncoder));
|
|
||||||
|
|
||||||
if (user.isEmpty()) {
|
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.ticketing.server.user.application.request;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.validator.constraints.Phone;
|
|
||||||
import com.ticketing.server.user.service.dto.SignUp;
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class SignUpRequest {
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.name}")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
|
||||||
@Phone
|
|
||||||
private String phone;
|
|
||||||
|
|
||||||
public SignUp toSignUp(PasswordEncoder passwordEncoder) {
|
|
||||||
return new SignUp(name, email, getEncodePassword(passwordEncoder), phone);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getEncodePassword(PasswordEncoder passwordEncoder) {
|
|
||||||
return passwordEncoder.encode(password);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,12 @@
|
|||||||
package com.ticketing.server.user.domain;
|
package com.ticketing.server.user.domain;
|
||||||
|
|
||||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
||||||
import com.ticketing.server.global.validator.constraints.Phone;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
import javax.persistence.Enumerated;
|
import javax.persistence.Enumerated;
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@@ -18,34 +15,28 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class User extends AbstractEntity {
|
public class User extends AbstractEntity {
|
||||||
|
|
||||||
@Column(name = "name")
|
@NotNull
|
||||||
@NotEmpty(message = "{validation.not.empty.name}")
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(name = "email")
|
@NotNull
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@Column(name = "password")
|
@NotNull
|
||||||
@NotEmpty(message = "{validation.not.empty.password}")
|
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@Column(name = "grade")
|
@NotNull
|
||||||
@NotNull(message = "{validation.not.empty.grade}")
|
|
||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private UserGrade grade = UserGrade.GUEST;
|
private UserGrade grade;
|
||||||
|
|
||||||
@Column(name = "phone")
|
@NotNull
|
||||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
|
||||||
@Phone
|
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
private boolean isDeleted = false;
|
private boolean isDeleted = false;
|
||||||
|
|
||||||
private LocalDateTime deletedAt;
|
private LocalDateTime deletedAt;
|
||||||
|
|
||||||
public User(String name, String email, String password, UserGrade grade, String phone) {
|
@Builder
|
||||||
|
protected User(String name, String email, String password, UserGrade grade, String phone) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package com.ticketing.server.user.domain.repository;
|
package com.ticketing.server.user.domain.repository;
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
import com.ticketing.server.user.domain.User;
|
||||||
import java.util.Optional;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserRepository extends JpaRepository<User, Long> {
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
|
|
||||||
Optional<User> findByEmail(String email);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,9 @@
|
|||||||
package com.ticketing.server.user.service;
|
package com.ticketing.server.user.service;
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.domain.repository.UserRepository;
|
|
||||||
import com.ticketing.server.user.service.dto.SignUp;
|
|
||||||
import com.ticketing.server.user.service.interfaces.UserService;
|
import com.ticketing.server.user.service.interfaces.UserService;
|
||||||
import java.util.Optional;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
@Validated
|
|
||||||
@Slf4j
|
|
||||||
public class UserServiceImpl implements UserService {
|
public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public Optional<User> register(@Valid SignUp signUpDto) {
|
|
||||||
Optional<User> user = userRepository.findByEmail(signUpDto.getEmail());
|
|
||||||
if (user.isPresent()) {
|
|
||||||
log.error("이미 존재하는 이메일이기 때문에 신규 회원가입을 진행할 수 없습니다. :: {}", signUpDto);
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
User newUser = userRepository.save(signUpDto.toUser());
|
|
||||||
return Optional.of(newUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
package com.ticketing.server.user.service.dto;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.validator.constraints.Phone;
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.domain.UserGrade;
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class SignUp {
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.name}")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
|
||||||
@Phone
|
|
||||||
private String phone;
|
|
||||||
|
|
||||||
public SignUp(String name, String email, String password, String phone) {
|
|
||||||
this.name = name;
|
|
||||||
this.email = email;
|
|
||||||
this.password = password;
|
|
||||||
this.phone = phone;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User toUser() {
|
|
||||||
return new User(this.name, this.email, password, UserGrade.GUEST, this.phone);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SignUp{" +
|
|
||||||
"name='" + name + '\'' +
|
|
||||||
", email='" + email + '\'' +
|
|
||||||
", phone='" + phone + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,5 @@
|
|||||||
package com.ticketing.server.user.service.interfaces;
|
package com.ticketing.server.user.service.interfaces;
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.service.dto.SignUp;
|
|
||||||
import java.util.Optional;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
|
|
||||||
Optional<User> register(@Valid SignUp signUpDto);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
validation.not.empty.name="\uC774\uB984\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.email="\uC774\uBA54\uC77C\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.password="\uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.grade="\uC0AC\uC6A9\uC790 \uB4F1\uAE09\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.phone="\uD734\uB300\uBC88\uD638\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.email="\uC774\uBA54\uC77C\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
||||||
validation.phone="\uD734\uB300\uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
validation.not.empty.name="name is required."
|
|
||||||
validation.not.empty.email="email is required."
|
|
||||||
validation.not.empty.password="password is required."
|
|
||||||
validation.not.empty.grade="user grade is required."
|
|
||||||
validation.not.empty.phone="phone is required."
|
|
||||||
validation.email="email is not valid."
|
|
||||||
validation.phone="phone is not valid."
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
validation.not.empty.name="\uC774\uB984\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.email="\uC774\uBA54\uC77C\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.password="\uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.grade="\uC0AC\uC6A9\uC790 \uB4F1\uAE09\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.phone="\uD734\uB300\uBC88\uD638\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.email="\uC774\uBA54\uC77C\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
||||||
validation.phone="\uD734\uB300\uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
||||||
@@ -2,8 +2,10 @@ package com.ticketing.server;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
@EnableJpaAuditing
|
||||||
class ServerApplicationTests {
|
class ServerApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,138 +0,0 @@
|
|||||||
package com.ticketing.server.user.domain;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import javax.validation.ConstraintViolation;
|
|
||||||
import javax.validation.Validation;
|
|
||||||
import javax.validation.Validator;
|
|
||||||
import javax.validation.ValidatorFactory;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.NullAndEmptySource;
|
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
|
||||||
|
|
||||||
class UserTest {
|
|
||||||
|
|
||||||
private static Validator validator;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void init() {
|
|
||||||
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
|
|
||||||
validator = factory.getValidator();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("유저 검증 성공")
|
|
||||||
void validateSuccess() {
|
|
||||||
// given
|
|
||||||
User user = new User("유저1", "email@gmail.com", "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
|
||||||
|
|
||||||
// when
|
|
||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(constraintViolations).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@NullAndEmptySource
|
|
||||||
@DisplayName("name null 혹은 빈값 검증")
|
|
||||||
void nameNullOrEmpty(String name) {
|
|
||||||
// given
|
|
||||||
User user = new User(name, "email@gmail.com", "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
|
||||||
|
|
||||||
// when
|
|
||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(constraintViolations).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@NullAndEmptySource
|
|
||||||
@DisplayName("email null or empty 검증")
|
|
||||||
void emailNullOrEmpty(String email) {
|
|
||||||
// given
|
|
||||||
User user = new User("유저1", email, "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
|
||||||
|
|
||||||
// when
|
|
||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(constraintViolations).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@ValueSource(strings = {"email", "@hello.com", "12Bye#domain.com"})
|
|
||||||
@DisplayName("email 실패 검증")
|
|
||||||
void emailValid(String email) {
|
|
||||||
// given
|
|
||||||
User user = new User("유저1", email, "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
|
||||||
|
|
||||||
// when
|
|
||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(constraintViolations).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@NullAndEmptySource
|
|
||||||
@DisplayName("password null 혹은 빈값 검증")
|
|
||||||
void passwordNullOrEmpty(String password) {
|
|
||||||
// given
|
|
||||||
User user = new User("유저1", "email@gmail.com", password, UserGrade.GUEST, "010-1234-5678");
|
|
||||||
|
|
||||||
// when
|
|
||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(constraintViolations).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("grade null 검증")
|
|
||||||
void gradeNull() {
|
|
||||||
// given
|
|
||||||
User user = new User("유저1", "email@gmail.com", "testPassword01", null, "010-1234-5678");
|
|
||||||
|
|
||||||
// when
|
|
||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(constraintViolations).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@DisplayName("phone null or empty 검증")
|
|
||||||
@NullAndEmptySource
|
|
||||||
void phoneNullOrEmpty(String phone) {
|
|
||||||
// given
|
|
||||||
User user = new User("유저1", "email@gmail.com", "testPassword01", UserGrade.GUEST, phone);
|
|
||||||
|
|
||||||
// when
|
|
||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(constraintViolations).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@DisplayName("phone 실패 검증")
|
|
||||||
@ValueSource(strings = {"010-123-1234", "02-0444-4044", "033-7953", "033-0455-504"})
|
|
||||||
void phoneValid(String phone) {
|
|
||||||
// given
|
|
||||||
User user = new User("유저1", "email@gmail.com", "testPassword01", UserGrade.GUEST, phone);
|
|
||||||
|
|
||||||
// when
|
|
||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(constraintViolations).hasSize(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,13 @@ class UserRepositoryTest {
|
|||||||
@Test
|
@Test
|
||||||
void 유저레포지토리테스트() {
|
void 유저레포지토리테스트() {
|
||||||
// given
|
// given
|
||||||
User user = new User("유저1", "email@gmail.com", "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
User user = User.builder()
|
||||||
|
.name("동효")
|
||||||
|
.password("test")
|
||||||
|
.email("test@test.com")
|
||||||
|
.grade(UserGrade.GUEST)
|
||||||
|
.phone("010-1234-5678")
|
||||||
|
.build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
package com.ticketing.server.user.service;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.domain.UserGrade;
|
|
||||||
import com.ticketing.server.user.domain.repository.UserRepository;
|
|
||||||
import com.ticketing.server.user.service.dto.SignUp;
|
|
||||||
import java.util.Optional;
|
|
||||||
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.mockito.InjectMocks;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
|
||||||
class UserServiceImplTest {
|
|
||||||
|
|
||||||
User user;
|
|
||||||
SignUp signUp;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
UserRepository userRepository;
|
|
||||||
|
|
||||||
@InjectMocks
|
|
||||||
UserServiceImpl userService;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void init() {
|
|
||||||
|
|
||||||
signUp = new SignUp("유저", "ticketing@gmail.com", "123456", "010-1234-5678");
|
|
||||||
user = new User("유저", "ticketing@gmail.com", "123456", UserGrade.GUEST, "010-1234-5678");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("이미 동일한 이메일이 있을 경우")
|
|
||||||
void duplicateEmailException() {
|
|
||||||
// given
|
|
||||||
when(userRepository.findByEmail("ticketing@gmail.com")).thenReturn(Optional.of(user));
|
|
||||||
|
|
||||||
// when
|
|
||||||
Optional<User> user = userService.register(signUp);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(user).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("회원가입 성공했을 경우")
|
|
||||||
void UserServiceImplTest() {
|
|
||||||
// given
|
|
||||||
when(userRepository.findByEmail("ticketing@gmail.com")).thenReturn(Optional.empty());
|
|
||||||
when(userRepository.save(any())).thenReturn(user);
|
|
||||||
|
|
||||||
// when
|
|
||||||
Optional<User> user = userService.register(signUp);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(user).isPresent();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.ticketing.server.user.service.dto;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class SignUpTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("toUser 메소드로 User 객체 생성")
|
|
||||||
void toUser() {
|
|
||||||
// given
|
|
||||||
SignUp signUp = new SignUp("유저1", "ticketing@gmail.com", "123456", "010-1234-5678");
|
|
||||||
|
|
||||||
// when
|
|
||||||
User user = signUp.toUser();
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(user).isInstanceOf(User.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user