Compare commits
7 Commits
feature/fi
...
feature/im
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39bba383d9 | ||
|
|
db5e8272b6 | ||
|
|
9780a84609 | ||
|
|
7283eeb5d3 | ||
|
|
0521b85dd9 | ||
|
|
b836598be3 | ||
|
|
0173fc92ed |
11
README.md
11
README.md
@@ -37,6 +37,7 @@
|
||||
- [패키지 구조](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)
|
||||
- [Issue Posting](https://github.com/f-lab-edu/Ticketing/wiki/Issue-Posting)
|
||||
|
||||
<br/>
|
||||
|
||||
@@ -49,6 +50,7 @@ erDiagram
|
||||
bigint id PK "영화 ID"
|
||||
varchar title "영화제목"
|
||||
int running_time "러닝타임"
|
||||
datetime deleted_at "삭제일시"
|
||||
datetime created_at "등록일시"
|
||||
datetime updated_at "수정일시"
|
||||
}
|
||||
@@ -58,6 +60,7 @@ erDiagram
|
||||
bigint id PK "상영관 ID"
|
||||
int theater_number "상영관 번호"
|
||||
int seat_count "좌석수"
|
||||
datetime deleted_at "삭제일시"
|
||||
datetime created_at "등록일시"
|
||||
datetime updated_at "수정일시"
|
||||
}
|
||||
@@ -67,6 +70,7 @@ erDiagram
|
||||
bigint theater_id FK "상영관 ID"
|
||||
int column "열"
|
||||
int row "행"
|
||||
datetime deleted_at "삭제일시"
|
||||
datetime created_at "등록일시"
|
||||
datetime updated_at "수정일시"
|
||||
}
|
||||
@@ -78,6 +82,7 @@ erDiagram
|
||||
int round "회차"
|
||||
time start_at "시작 시간"
|
||||
time end_at "종료 시간"
|
||||
datetime deleted_at "삭제일시"
|
||||
datetime created_at "등록일시"
|
||||
datetime updated_at "수정일시"
|
||||
}
|
||||
@@ -88,31 +93,33 @@ erDiagram
|
||||
bigint payment_id "결제 ID"
|
||||
varchar status "상태 - 구매가능/예약진행중/판매완료"
|
||||
int ticket_price "가격"
|
||||
datetime deleted_at "삭제일시"
|
||||
datetime created_at "등록일시"
|
||||
datetime updated_at "수정일시"
|
||||
}
|
||||
TICKET }|--|| PAYMENT : ""
|
||||
PAYMENT {
|
||||
bigint id PK "결제 ID"
|
||||
bigint user_id "유저ID"
|
||||
bigint user_alternate_id "유저 대체ID"
|
||||
varchar movie_title "영화제목"
|
||||
varchar type "결제 타입 - 예) 네이버페이, 카카오페이"
|
||||
varchar status "상태 - 완료/환불/실패"
|
||||
varchar failed_message "실패사유 - 컬럼명을 알아보기 쉬운가?"
|
||||
varchar payment_number "예매번호"
|
||||
int total_price "결제 금액"
|
||||
datetime deleted_at "삭제일시"
|
||||
datetime created_at "결제일시"
|
||||
datetime updated_at "수정일시"
|
||||
}
|
||||
USER ||--o{ PAYMENT : ""
|
||||
USER {
|
||||
bigint id "회원"
|
||||
bigint alternate_id "대체ID"
|
||||
varchar name "이름"
|
||||
varchar email "이메일"
|
||||
varchar password "비밀번호"
|
||||
varchar grade "등급 - 고객/임직원"
|
||||
varchar phone "휴대폰 번호"
|
||||
boolean is_deleted "탈퇴여부"
|
||||
datetime deleted_at "탈퇴일시"
|
||||
datetime created_at "가입일시"
|
||||
datetime updated_at "수정일시"
|
||||
|
||||
@@ -19,15 +19,15 @@ public abstract class AbstractEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
protected Long id;
|
||||
|
||||
@Column(nullable = false, updatable = false)
|
||||
@CreatedDate
|
||||
private LocalDateTime createdAt;
|
||||
protected LocalDateTime createdAt;
|
||||
|
||||
@LastModifiedDate
|
||||
private LocalDateTime updatedAt;
|
||||
protected LocalDateTime updatedAt;
|
||||
|
||||
private LocalDateTime deletedAt;
|
||||
protected LocalDateTime deletedAt;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ticketing.server.global.exception;
|
||||
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CONFLICT;
|
||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -16,15 +17,21 @@ public enum ErrorCode {
|
||||
MISMATCH_PASSWORD(BAD_REQUEST, "비밀번호가 일치하지 않습니다."),
|
||||
TOKEN_TYPE(BAD_REQUEST, "토큰 타입이 올바르지 않습니다."),
|
||||
UNAVAILABLE_REFRESH_TOKEN(BAD_REQUEST, "사용할 수 없는 토큰 입니다."),
|
||||
UNABLE_CHANGE_GRADE(BAD_REQUEST, "동일한 등급으로 변경할 수 없습니다."),
|
||||
|
||||
/* 403 FORBIDDEN : 접근 권한 제한 */
|
||||
VALID_USER_ID(FORBIDDEN, "해당 정보에 접근 권한이 존재하지 않습니다."),
|
||||
|
||||
/* 404 NOT_FOUND : Resource 를 찾을 수 없음 */
|
||||
USER_NOT_FOUND(NOT_FOUND, "해당 유저 정보를 찾을 수 없습니다."),
|
||||
EMAIL_NOT_FOUND(NOT_FOUND, "해당 이메일을 찾을 수 없습니다."),
|
||||
MOVIE_NOT_FOUND(NOT_FOUND, "해당 제목의 영화를 찾을 수 없습니다."),
|
||||
REFRESH_TOKEN_NOT_FOUND(NOT_FOUND, "리프레쉬 토큰을 찾을 수 없습니다."),
|
||||
PAYMENT_ID_NOT_FOUND(NOT_FOUND, "결제정보를 찾을 수 없습니다."),
|
||||
|
||||
/* 409 CONFLICT : Resource 의 현재 상태와 충돌. 보통 중복된 데이터 존재 */
|
||||
DUPLICATE_EMAIL(CONFLICT, "이메일이 이미 존재합니다."),
|
||||
DUPLICATE_PAYMENT(CONFLICT, "해당 좌석은 현재 판매된 좌석입니다."),
|
||||
DUPLICATE_MOVIE(CONFLICT, "해당 영화 정보가 이미 존재합니다."),
|
||||
DELETED_EMAIL(CONFLICT, "이미 삭제된 이메일 입니다.");
|
||||
|
||||
@@ -44,6 +51,15 @@ public enum ErrorCode {
|
||||
throw new TicketingException(UNAVAILABLE_REFRESH_TOKEN);
|
||||
}
|
||||
|
||||
public static TicketingException throwUnableChangeGrade() {
|
||||
throw new TicketingException(UNABLE_CHANGE_GRADE);
|
||||
}
|
||||
|
||||
/* 403 FORBIDDEN : 접근 권한 제한 */
|
||||
public static TicketingException throwValidUserId() {
|
||||
throw new TicketingException(VALID_USER_ID);
|
||||
}
|
||||
|
||||
/* 404 NOT_FOUND : Resource 를 찾을 수 없음 */
|
||||
public static TicketingException throwUserNotFound() {
|
||||
throw new TicketingException(USER_NOT_FOUND);
|
||||
@@ -61,11 +77,19 @@ public enum ErrorCode {
|
||||
throw new TicketingException(REFRESH_TOKEN_NOT_FOUND);
|
||||
}
|
||||
|
||||
public static TicketingException throwPaymentIdNotFound() {
|
||||
throw new TicketingException(PAYMENT_ID_NOT_FOUND);
|
||||
}
|
||||
|
||||
/* 409 CONFLICT : Resource 의 현재 상태와 충돌. 보통 중복된 데이터 존재 */
|
||||
public static TicketingException throwDuplicateEmail() {
|
||||
throw new TicketingException(DUPLICATE_EMAIL);
|
||||
}
|
||||
|
||||
public static TicketingException throwDuplicatePayment() {
|
||||
throw new TicketingException(DUPLICATE_PAYMENT);
|
||||
}
|
||||
|
||||
public static TicketingException throwDuplicateMovie() {
|
||||
throw new TicketingException(DUPLICATE_MOVIE);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import static org.springframework.http.HttpStatus.UNAUTHORIZED;
|
||||
import static org.springframework.http.HttpStatus.UNSUPPORTED_MEDIA_TYPE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@@ -53,7 +54,8 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
|
||||
|
||||
List<String> errors = generateErrors(ex);
|
||||
ErrorResponse response = new ErrorResponse(BAD_REQUEST, ex.getLocalizedMessage(), errors);
|
||||
return handleExceptionInternal(ex, response, headers, response.getStatus(), request);
|
||||
|
||||
return ResponseEntity.status(response.getStatus()).headers(headers).body(response);
|
||||
}
|
||||
|
||||
/***
|
||||
@@ -66,7 +68,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
|
||||
|
||||
List<String> errors = generateErrors(ex);
|
||||
ErrorResponse response = new ErrorResponse(BAD_REQUEST, ex.getLocalizedMessage(), errors);
|
||||
return handleExceptionInternal(ex, response, headers, response.getStatus(), request);
|
||||
return ResponseEntity.status(response.getStatus()).headers(headers).body(response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +240,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
|
||||
List<ObjectError> allErrors = ex.getBindingResult().getAllErrors();
|
||||
|
||||
for (ObjectError error : allErrors) {
|
||||
errors.add(((FieldError) error).getField() + ": " + error.getDefaultMessage());
|
||||
errors.add(error.getDefaultMessage());
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.ticketing.server.global.security.jwt;
|
||||
|
||||
import com.ticketing.server.user.application.response.TokenDto;
|
||||
import com.ticketing.server.user.service.dto.TokenDTO;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
@@ -42,12 +42,12 @@ public class JwtProvider {
|
||||
this.refreshTokenValidityInMilliseconds = jwtProperties.getRefreshTokenValidityInSeconds() * 1000L;
|
||||
}
|
||||
|
||||
public TokenDto generateTokenDto(Authentication authentication) {
|
||||
public TokenDTO generateTokenDto(Authentication authentication) {
|
||||
String accessToken = createAccessToken(authentication);
|
||||
String refreshToken = createRefreshToken(authentication);
|
||||
long expiresIn = accessTokenValidityInMilliseconds / 1000L;
|
||||
|
||||
return TokenDto.of(accessToken, refreshToken, prefix, expiresIn);
|
||||
return new TokenDTO(accessToken, refreshToken, prefix, expiresIn);
|
||||
}
|
||||
|
||||
private String createAccessToken(Authentication authentication) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.ticketing.server.global.security.jwt.handle;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
@@ -23,4 +22,5 @@ public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
|
||||
resolver.resolveException(request, response, null, authException);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import javax.validation.Payload;
|
||||
@Documented
|
||||
public @interface FieldsValueNotMatch {
|
||||
|
||||
String message();
|
||||
String message() default "validation.password.not.change";
|
||||
|
||||
String field();
|
||||
|
||||
|
||||
@@ -1,8 +1,30 @@
|
||||
package com.ticketing.server.movie.application;
|
||||
|
||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||
import com.ticketing.server.movie.service.interfaces.TicketService;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/tickets")
|
||||
@Validated
|
||||
public class TicketController {
|
||||
|
||||
private final TicketService ticketService;
|
||||
|
||||
@GetMapping("payments/{paymentId}")
|
||||
public ResponseEntity<TicketDetailsResponse> findTicketsByPaymentId(@PathVariable("paymentId") @NotNull Long paymentId) {
|
||||
TicketDetailsDTO tickets = ticketService.findTicketsByPaymentId(paymentId);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(tickets.toResponse());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ticketing.server.movie.application.response;
|
||||
|
||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class TicketDetailsResponse {
|
||||
|
||||
private final List<TicketDetailDTO> ticketDetails;
|
||||
|
||||
public TicketDetailsResponse(List<TicketDetailDTO> ticketDetails) {
|
||||
this.ticketDetails = ticketDetails;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,13 +4,14 @@ import com.ticketing.server.global.dto.repository.AbstractEntity;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
@AllArgsConstructor
|
||||
public class Movie extends AbstractEntity {
|
||||
|
||||
@@ -21,4 +22,10 @@ public class Movie extends AbstractEntity {
|
||||
@NotNull
|
||||
private Long runningTime;
|
||||
|
||||
Movie(Long id, String title, Long runningTime) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.runningTime = runningTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,25 +6,27 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class MovieTime extends AbstractEntity {
|
||||
|
||||
@NotNull
|
||||
@ManyToOne
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "movie_id", referencedColumnName = "id", updatable = false)
|
||||
private Movie movie;
|
||||
|
||||
@NotNull
|
||||
@ManyToOne
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "theater_id", referencedColumnName = "id", updatable = false)
|
||||
private Theater theater;
|
||||
|
||||
@@ -40,19 +42,30 @@ public class MovieTime extends AbstractEntity {
|
||||
@OneToMany(mappedBy = "movieTime", cascade = CascadeType.ALL)
|
||||
private List<Ticket> tickets = new ArrayList<>();
|
||||
|
||||
private MovieTime(Movie movie, Theater theater, int round, LocalDateTime startAt, LocalDateTime endAt) {
|
||||
public MovieTime(Movie movie, Theater theater, int round, LocalDateTime startAt) {
|
||||
this.movie = movie;
|
||||
this.theater = theater;
|
||||
this.round = round;
|
||||
this.startAt = startAt;
|
||||
this.endAt = endAt;
|
||||
this.endAt = generateEndAt(startAt);
|
||||
}
|
||||
|
||||
public static MovieTime of(Movie movie, Theater theater, int round, LocalDateTime startAt) {
|
||||
Long runningTime = movie.getRunningTime();
|
||||
LocalDateTime endAt = startAt.plusMinutes(runningTime);
|
||||
MovieTime(Long id, Movie movie, Theater theater, int round, LocalDateTime startAt) {
|
||||
this.id = id;
|
||||
this.movie = movie;
|
||||
this.theater = theater;
|
||||
this.round = round;
|
||||
this.startAt = startAt;
|
||||
this.endAt = generateEndAt(startAt);
|
||||
}
|
||||
|
||||
return new MovieTime(movie, theater, round, startAt, endAt);
|
||||
private LocalDateTime generateEndAt(LocalDateTime startAt) {
|
||||
Long runningTime = movie.getRunningTime();
|
||||
return startAt.plusMinutes(runningTime);
|
||||
}
|
||||
|
||||
public String getMovieTitle() {
|
||||
return this.movie.getTitle();
|
||||
}
|
||||
|
||||
public List<Seat> getSeats() {
|
||||
|
||||
@@ -2,31 +2,40 @@ package com.ticketing.server.movie.domain;
|
||||
|
||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class Seat extends AbstractEntity {
|
||||
|
||||
@NotNull
|
||||
@ManyToOne
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "theater_id", referencedColumnName = "id", updatable = false)
|
||||
private Theater theater;
|
||||
|
||||
@NotNull
|
||||
private Integer seatRow;
|
||||
|
||||
@NotNull
|
||||
private Integer seatColumn;
|
||||
|
||||
public Seat(Integer seatRow, Integer seatColumn, Theater theater) {
|
||||
this.seatRow = seatRow;
|
||||
@NotNull
|
||||
private Integer seatRow;
|
||||
|
||||
public Seat(Integer seatColumn, Integer seatRow, Theater theater) {
|
||||
this.seatColumn = seatColumn;
|
||||
this.seatRow = seatRow;
|
||||
setTheater(theater);
|
||||
}
|
||||
|
||||
Seat(Long id, int column, int row, Theater theater) {
|
||||
this.id = id;
|
||||
this.seatColumn = column;
|
||||
this.seatRow = row;
|
||||
setTheater(theater);
|
||||
}
|
||||
|
||||
@@ -34,4 +43,9 @@ public class Seat extends AbstractEntity {
|
||||
this.theater = theater;
|
||||
theater.addSeat(this);
|
||||
}
|
||||
|
||||
public Integer getTheaterNumber() {
|
||||
return this.theater.getTheaterNumber();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,12 +7,13 @@ import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class Theater extends AbstractEntity {
|
||||
|
||||
@NotNull
|
||||
@@ -21,6 +22,11 @@ public class Theater extends AbstractEntity {
|
||||
@OneToMany(mappedBy = "theater", cascade = CascadeType.ALL)
|
||||
private List<Seat> seats = new ArrayList<>();
|
||||
|
||||
Theater(Long id, Integer theaterNumber) {
|
||||
this.id = id;
|
||||
this.theaterNumber = theaterNumber;
|
||||
}
|
||||
|
||||
public Theater(Integer theaterNumber) {
|
||||
this.theaterNumber = theaterNumber;
|
||||
}
|
||||
|
||||
@@ -1,27 +1,31 @@
|
||||
package com.ticketing.server.movie.domain;
|
||||
|
||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import java.time.LocalDateTime;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class Ticket extends AbstractEntity {
|
||||
|
||||
@NotNull
|
||||
@ManyToOne
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "seat_id", referencedColumnName = "id", updatable = false)
|
||||
private Seat seat;
|
||||
|
||||
@NotNull
|
||||
@ManyToOne
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "movie_times_id", referencedColumnName = "id", updatable = false)
|
||||
private MovieTime movieTime;
|
||||
|
||||
@@ -34,15 +38,52 @@ public class Ticket extends AbstractEntity {
|
||||
@NotNull
|
||||
private Integer ticketPrice;
|
||||
|
||||
private Ticket(Seat seat, MovieTime movieTime, Integer ticketPrice) {
|
||||
public Ticket(Seat seat, MovieTime movieTime, Integer ticketPrice) {
|
||||
this.seat = seat;
|
||||
this.movieTime = movieTime;
|
||||
this.ticketPrice = ticketPrice;
|
||||
this.status = TicketStatus.SALE;
|
||||
}
|
||||
|
||||
public static Ticket of(Seat seat, MovieTime movieTime, Integer ticketPrice) {
|
||||
return new Ticket(seat, movieTime, ticketPrice);
|
||||
Ticket(Long id, Seat seat, MovieTime movieTime, Integer ticketPrice) {
|
||||
this.id = id;
|
||||
this.seat = seat;
|
||||
this.movieTime = movieTime;
|
||||
this.ticketPrice = ticketPrice;
|
||||
this.status = TicketStatus.SALE;
|
||||
}
|
||||
|
||||
public Integer getColumn() {
|
||||
return this.seat.getSeatColumn();
|
||||
}
|
||||
|
||||
public Integer getRow() {
|
||||
return this.seat.getSeatRow();
|
||||
}
|
||||
|
||||
public LocalDateTime getStartAt() {
|
||||
return this.movieTime.getStartAt();
|
||||
}
|
||||
|
||||
public LocalDateTime getEndAt() {
|
||||
return this.movieTime.getEndAt();
|
||||
}
|
||||
|
||||
public Integer getTheaterNumber() {
|
||||
return this.seat.getTheaterNumber();
|
||||
}
|
||||
|
||||
public String getMovieTitle() {
|
||||
return this.movieTime.getMovieTitle();
|
||||
}
|
||||
|
||||
public void registerPayment(Long id) {
|
||||
if (this.paymentId != null) {
|
||||
throw ErrorCode.throwDuplicatePayment();
|
||||
}
|
||||
|
||||
this.paymentId = id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
package com.ticketing.server.movie.domain.repository;
|
||||
|
||||
import com.ticketing.server.movie.domain.Ticket;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface TicketRepository extends JpaRepository<Ticket, Long> {
|
||||
|
||||
@Query(
|
||||
value =
|
||||
"SELECT t "
|
||||
+ "FROM Ticket t "
|
||||
+ "JOIN FETCH t.movieTime mt "
|
||||
+ "JOIN FETCH t.seat s "
|
||||
+ "JOIN FETCH s.theater th "
|
||||
+ "WHERE t.paymentId = :paymentId "
|
||||
)
|
||||
List<Ticket> findTicketFetchJoinByPaymentId(@Param("paymentId") Long paymentId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,40 @@
|
||||
package com.ticketing.server.movie.service;
|
||||
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.movie.domain.repository.TicketRepository;
|
||||
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||
import com.ticketing.server.movie.service.interfaces.TicketService;
|
||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class TicketServiceImpl implements TicketService {
|
||||
|
||||
private final TicketRepository ticketRepository;
|
||||
|
||||
@Override
|
||||
public TicketDetailsDTO findTicketsByPaymentId(@NotNull Long paymentId) {
|
||||
List<TicketDetailDTO> ticketDetails = ticketRepository.findTicketFetchJoinByPaymentId(paymentId)
|
||||
.stream()
|
||||
.map(TicketDetailDTO::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (ticketDetails.isEmpty()) {
|
||||
throw ErrorCode.throwPaymentIdNotFound();
|
||||
}
|
||||
|
||||
return new TicketDetailsDTO(ticketDetails);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.ticketing.server.movie.service.dto;
|
||||
|
||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class TicketDetailsDTO {
|
||||
|
||||
private final List<TicketDetailDTO> ticketDetails;
|
||||
|
||||
public TicketDetailsResponse toResponse() {
|
||||
return new TicketDetailsResponse(ticketDetails);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.ticketing.server.movie.service.interfaces;
|
||||
|
||||
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public interface TicketService {
|
||||
|
||||
TicketDetailsDTO findTicketsByPaymentId(@NotNull Long paymentId);
|
||||
|
||||
}
|
||||
|
||||
@@ -9,11 +9,20 @@ import com.ticketing.server.movie.domain.repository.MovieRepository;
|
||||
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
||||
import com.ticketing.server.movie.domain.repository.TheaterRepository;
|
||||
import com.ticketing.server.movie.domain.repository.TicketRepository;
|
||||
import com.ticketing.server.payment.domain.Payment;
|
||||
import com.ticketing.server.payment.domain.PaymentStatus;
|
||||
import com.ticketing.server.payment.domain.PaymentType;
|
||||
import com.ticketing.server.payment.domain.repository.PaymentRepository;
|
||||
import com.ticketing.server.payment.service.dto.CreatePaymentDTO;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import com.ticketing.server.user.domain.repository.UserRepository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -22,10 +31,14 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class
|
||||
MovieSetupService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final MovieRepository movieRepository;
|
||||
private final MovieTimeRepository movieTimeRepository;
|
||||
private final TheaterRepository theaterRepository;
|
||||
private final TicketRepository ticketRepository;
|
||||
private final PaymentRepository paymentRepository;
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@Transactional
|
||||
public void init() {
|
||||
@@ -33,6 +46,7 @@ MovieSetupService {
|
||||
initTheater();
|
||||
initMovieTime();
|
||||
initTicket();
|
||||
initPayment();
|
||||
}
|
||||
|
||||
private void initMovie() {
|
||||
@@ -54,9 +68,9 @@ MovieSetupService {
|
||||
);
|
||||
|
||||
for (Theater theater : theaters) {
|
||||
for (int row = 1; row <= 2; row++) {
|
||||
for (int col = 1; col <= 10; col++) {
|
||||
new Seat(row, col, theater);
|
||||
for (int col = 1; col <= 2; col++) {
|
||||
for (int row = 1; row <= 10; row++) {
|
||||
new Seat(col, row, theater);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,14 +86,14 @@ MovieSetupService {
|
||||
|
||||
List<MovieTime> movieTimes = new ArrayList<>();
|
||||
for (Theater theater : theaters) {
|
||||
movieTimes.add(MovieTime.of(movies.get(0), theater, 1, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 8, 0)));
|
||||
movieTimes.add(MovieTime.of(movies.get(0), theater, 3, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 12, 0)));
|
||||
movieTimes.add(MovieTime.of(movies.get(1), theater, 2, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 10, 0)));
|
||||
movieTimes.add(MovieTime.of(movies.get(2), theater, 4, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 14, 0)));
|
||||
movieTimes.add(MovieTime.of(movies.get(0), theater, 5, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 16, 0)));
|
||||
movieTimes.add(MovieTime.of(movies.get(3), theater, 6, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 18, 0)));
|
||||
movieTimes.add(MovieTime.of(movies.get(0), theater, 7, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 21, 0)));
|
||||
movieTimes.add(MovieTime.of(movies.get(4), theater, 8, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 23, 0)));
|
||||
movieTimes.add(new MovieTime(movies.get(0), theater, 1, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 8, 0)));
|
||||
movieTimes.add(new MovieTime(movies.get(0), theater, 3, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 12, 0)));
|
||||
movieTimes.add(new MovieTime(movies.get(1), theater, 2, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 10, 0)));
|
||||
movieTimes.add(new MovieTime(movies.get(2), theater, 4, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 14, 0)));
|
||||
movieTimes.add(new MovieTime(movies.get(0), theater, 5, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 16, 0)));
|
||||
movieTimes.add(new MovieTime(movies.get(3), theater, 6, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 18, 0)));
|
||||
movieTimes.add(new MovieTime(movies.get(0), theater, 7, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 21, 0)));
|
||||
movieTimes.add(new MovieTime(movies.get(4), theater, 8, LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 23, 0)));
|
||||
}
|
||||
|
||||
movieTimeRepository.saveAll(movieTimes);
|
||||
@@ -92,11 +106,26 @@ MovieSetupService {
|
||||
Integer ticketPrice = 15_000;
|
||||
for (MovieTime movieTime : movieTimes) {
|
||||
for (Seat seat : movieTime.getSeats()) {
|
||||
tickets.add(Ticket.of(seat, movieTime, ticketPrice));
|
||||
tickets.add(new Ticket(seat, movieTime, ticketPrice));
|
||||
}
|
||||
}
|
||||
|
||||
ticketRepository.saveAll(tickets);
|
||||
}
|
||||
|
||||
private void initPayment() {
|
||||
User user = userRepository.save(new User(123L, "김동효", "kdhyo98@gmail.com", passwordEncoder.encode("123123"), UserGrade.USER, "010-1234-5678"));
|
||||
|
||||
List<Ticket> tickets = ticketRepository.findAll();
|
||||
Ticket ticket = tickets.get(0);
|
||||
String title = ticket.getMovieTime().getMovie().getTitle();
|
||||
CreatePaymentDTO createPaymentDto = new CreatePaymentDTO(user.getAlternateId(), title, PaymentType.KAKAO_PAY, PaymentStatus.COMPLETED, "2022-0710-4142", 30_000);
|
||||
Payment payment = createPaymentDto.toEntity();
|
||||
|
||||
paymentRepository.save(payment);
|
||||
|
||||
ticket.registerPayment(payment.getId());
|
||||
tickets.get(1).registerPayment(payment.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ticketing.server.payment.api;
|
||||
|
||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public interface MovieClient {
|
||||
|
||||
TicketDetailsResponse getTicketsByPaymentId(@NotNull Long paymentId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.ticketing.server.payment.api;
|
||||
|
||||
import com.ticketing.server.payment.api.dto.response.UserDetailResponse;
|
||||
|
||||
public interface UserClient {
|
||||
|
||||
UserDetailResponse detail();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ticketing.server.payment.api.dto.response;
|
||||
|
||||
import com.ticketing.server.payment.domain.Payment;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import com.ticketing.server.user.service.dto.UserDetailDTO;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class UserDetailResponse {
|
||||
|
||||
private final Long userAlternateId;
|
||||
private final String name;
|
||||
private final String email;
|
||||
private final UserGrade grade;
|
||||
private final String phone;
|
||||
|
||||
public UserDetailResponse(UserDetailDTO userDetailDto) {
|
||||
this(
|
||||
userDetailDto.getAlternateId(),
|
||||
userDetailDto.getName(),
|
||||
userDetailDto.getEmail(),
|
||||
userDetailDto.getGrade(),
|
||||
userDetailDto.getPhone()
|
||||
);
|
||||
}
|
||||
|
||||
public boolean hasUserAlternateId(Payment payment) {
|
||||
return userAlternateId.equals(payment.getUserAlternateId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ticketing.server.payment.api.impl;
|
||||
|
||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||
import com.ticketing.server.movie.service.interfaces.TicketService;
|
||||
import com.ticketing.server.payment.api.MovieClient;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Validated
|
||||
public class MovieClientImpl implements MovieClient {
|
||||
|
||||
private final TicketService ticketService;
|
||||
|
||||
@Override
|
||||
public TicketDetailsResponse getTicketsByPaymentId(@NotNull Long paymentId) {
|
||||
TicketDetailsDTO ticketDetails = ticketService.findTicketsByPaymentId(paymentId);
|
||||
return ticketDetails.toResponse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ticketing.server.payment.api.impl;
|
||||
|
||||
import com.ticketing.server.payment.api.UserClient;
|
||||
import com.ticketing.server.payment.api.dto.response.UserDetailResponse;
|
||||
import com.ticketing.server.user.service.dto.UserDetailDTO;
|
||||
import com.ticketing.server.user.service.interfaces.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserClientImpl implements UserClient {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
@Override
|
||||
public UserDetailResponse detail() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
UserDetails details = (UserDetails) authentication.getPrincipal();
|
||||
|
||||
UserDetailDTO userDetail = userService.findDetailByEmail(details.getUsername());
|
||||
return new UserDetailResponse(userDetail);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,47 @@
|
||||
package com.ticketing.server.payment.application;
|
||||
|
||||
import com.ticketing.server.payment.application.response.PaymentDetailResponse;
|
||||
import com.ticketing.server.payment.application.response.SimplePaymentsResponse;
|
||||
import com.ticketing.server.payment.service.dto.PaymentDetailDTO;
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentsDTO;
|
||||
import com.ticketing.server.payment.service.interfaces.PaymentApisService;
|
||||
import com.ticketing.server.payment.service.interfaces.PaymentService;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
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.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/payments")
|
||||
@Validated
|
||||
public class PaymentController {
|
||||
|
||||
private final PaymentApisService paymentApisService;
|
||||
private final PaymentService paymentService;
|
||||
|
||||
@GetMapping
|
||||
@Secured(UserGrade.ROLES.USER)
|
||||
public ResponseEntity<SimplePaymentsResponse> simplePayments(@NotNull Long userAlternateId) {
|
||||
SimplePaymentsDTO simplePayments = paymentService.findSimplePayments(userAlternateId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(simplePayments.toResponse());
|
||||
}
|
||||
|
||||
@GetMapping("/detail")
|
||||
@Secured(UserGrade.ROLES.USER)
|
||||
public ResponseEntity<PaymentDetailResponse> detail(@NotNull Long paymentId) {
|
||||
PaymentDetailDTO paymentDetail = paymentApisService.findPaymentDetail(paymentId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(paymentDetail.toResponse());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.ticketing.server.payment.application.response;
|
||||
|
||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class PaymentDetailResponse {
|
||||
|
||||
private Long paymentId;
|
||||
private String movieTitle;
|
||||
private String paymentNumber;
|
||||
private Integer totalPrice;
|
||||
private LocalDateTime createdAt;
|
||||
private List<TicketDetailDTO> tickets;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ticketing.server.payment.application.response;
|
||||
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentDTO;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class SimplePaymentsResponse {
|
||||
|
||||
private final Long userAlternateId;
|
||||
private final List<SimplePaymentDTO> payments;
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.ticketing.server.payment.domain;
|
||||
|
||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
||||
import com.ticketing.server.payment.service.dto.CreatePaymentDto;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
@@ -17,29 +17,36 @@ import lombok.NoArgsConstructor;
|
||||
public class Payment extends AbstractEntity {
|
||||
|
||||
@NotNull
|
||||
private Long userId;
|
||||
@Column(name = "user_alternate_id", nullable = false)
|
||||
private Long userAlternateId;
|
||||
|
||||
@NotEmpty
|
||||
@Column(name = "movie_title", nullable = false)
|
||||
private String movieTitle;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "type", nullable = false)
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
private PaymentType type;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "status", nullable = false)
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
private PaymentStatus status;
|
||||
|
||||
@Column(name = "failed_message")
|
||||
private String failedMessage;
|
||||
|
||||
@NotEmpty
|
||||
@Column(name = "payment_number", nullable = false)
|
||||
private String paymentNumber;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "total_price", nullable = false)
|
||||
private Integer totalPrice;
|
||||
|
||||
private Payment(Long userId, String movieTitle, PaymentType type, PaymentStatus status, String paymentNumber, Integer totalPrice) {
|
||||
this.userId = userId;
|
||||
public Payment(Long userAlternateId, String movieTitle, PaymentType type, PaymentStatus status, String paymentNumber, Integer totalPrice) {
|
||||
this.userAlternateId = userAlternateId;
|
||||
this.movieTitle = movieTitle;
|
||||
this.type = type;
|
||||
this.status = status;
|
||||
@@ -47,13 +54,14 @@ public class Payment extends AbstractEntity {
|
||||
this.totalPrice = totalPrice;
|
||||
}
|
||||
|
||||
public static Payment from(CreatePaymentDto dto) {
|
||||
return new Payment(dto.getUserId(),
|
||||
dto.getMovieTitle(),
|
||||
dto.getType(),
|
||||
dto.getStatus(),
|
||||
dto.getPaymentNumber(),
|
||||
dto.getTotalPrice());
|
||||
Payment(Long id, Long userAlternateId, String movieTitle, PaymentType type, PaymentStatus status, String paymentNumber, Integer totalPrice) {
|
||||
this.id = id;
|
||||
this.userAlternateId = userAlternateId;
|
||||
this.movieTitle = movieTitle;
|
||||
this.type = type;
|
||||
this.status = status;
|
||||
this.paymentNumber = paymentNumber;
|
||||
this.totalPrice = totalPrice;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ import org.springframework.stereotype.Repository;
|
||||
@Repository
|
||||
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
||||
|
||||
List<Payment> findByUserId(Long userId);
|
||||
List<Payment> findByUserAlternateId(Long userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.ticketing.server.payment.service;
|
||||
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||
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.domain.Payment;
|
||||
import com.ticketing.server.payment.domain.repository.PaymentRepository;
|
||||
import com.ticketing.server.payment.service.dto.PaymentDetailDTO;
|
||||
import com.ticketing.server.payment.service.interfaces.PaymentApisService;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class PaymentApisServiceImpl implements PaymentApisService {
|
||||
|
||||
private final PaymentRepository paymentRepository;
|
||||
private final MovieClient movieClient;
|
||||
private final UserClient userClient;
|
||||
|
||||
@Override
|
||||
public PaymentDetailDTO findPaymentDetail(@NotNull Long paymentId) {
|
||||
Payment payment = paymentRepository.findById(paymentId)
|
||||
.orElseThrow(ErrorCode::throwPaymentIdNotFound);
|
||||
|
||||
UserDetailResponse userDetail = userClient.detail();
|
||||
if (!userDetail.hasUserAlternateId(payment)) {
|
||||
throw ErrorCode.throwValidUserId();
|
||||
}
|
||||
|
||||
TicketDetailsResponse tickets = movieClient.getTicketsByPaymentId(payment.getId());
|
||||
return new PaymentDetailDTO(payment, tickets);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +1,37 @@
|
||||
package com.ticketing.server.payment.service;
|
||||
|
||||
import com.ticketing.server.payment.domain.repository.PaymentRepository;
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentDto;
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentDTO;
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentsDTO;
|
||||
import com.ticketing.server.payment.service.interfaces.PaymentService;
|
||||
import com.ticketing.server.user.api.dto.response.SimplePaymentsResponse;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class PaymentServiceImpl implements PaymentService {
|
||||
|
||||
private final PaymentRepository paymentRepository;
|
||||
|
||||
@Override
|
||||
public SimplePaymentsResponse findSimplePayments(Long userId) {
|
||||
return paymentRepository.findByUserId(userId)
|
||||
public SimplePaymentsDTO findSimplePayments(@NotNull Long userAlternateId) {
|
||||
return paymentRepository.findByUserAlternateId(userAlternateId)
|
||||
.stream()
|
||||
.map(SimplePaymentDto::from)
|
||||
.collect(Collectors.collectingAndThen(Collectors.toList()
|
||||
, list -> SimplePaymentsResponse.from(userId, list)));
|
||||
.map(SimplePaymentDTO::new)
|
||||
.collect(Collectors
|
||||
.collectingAndThen(
|
||||
Collectors.toList()
|
||||
, payments -> new SimplePaymentsDTO(userAlternateId, payments)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.ticketing.server.payment.service.dto;
|
||||
|
||||
import com.ticketing.server.payment.domain.Payment;
|
||||
import com.ticketing.server.payment.domain.PaymentStatus;
|
||||
import com.ticketing.server.payment.domain.PaymentType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class CreatePaymentDTO {
|
||||
|
||||
private final Long userAlternateId;
|
||||
private final String movieTitle;
|
||||
private final PaymentType type;
|
||||
private final PaymentStatus status;
|
||||
private final String paymentNumber;
|
||||
private final Integer totalPrice;
|
||||
|
||||
public Payment toEntity() {
|
||||
return new Payment
|
||||
(
|
||||
this.getUserAlternateId(),
|
||||
this.getMovieTitle(),
|
||||
this.getType(),
|
||||
this.getStatus(),
|
||||
this.getPaymentNumber(),
|
||||
this.getTotalPrice()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.ticketing.server.payment.service.dto;
|
||||
|
||||
import com.ticketing.server.payment.domain.PaymentStatus;
|
||||
import com.ticketing.server.payment.domain.PaymentType;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class CreatePaymentDto {
|
||||
|
||||
private Long userId;
|
||||
private String movieTitle;
|
||||
private PaymentType type;
|
||||
private PaymentStatus status;
|
||||
private String paymentNumber;
|
||||
private Integer totalPrice;
|
||||
|
||||
public static CreatePaymentDto of(
|
||||
Long userId,
|
||||
String movieTitle,
|
||||
PaymentType type,
|
||||
PaymentStatus status,
|
||||
String paymentNumber,
|
||||
Integer totalPrice) {
|
||||
return new CreatePaymentDto(userId, movieTitle, type, status, paymentNumber, totalPrice);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.ticketing.server.payment.service.dto;
|
||||
|
||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||
import com.ticketing.server.payment.application.response.PaymentDetailResponse;
|
||||
import com.ticketing.server.payment.domain.Payment;
|
||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class PaymentDetailDTO {
|
||||
|
||||
private final Long paymentId;
|
||||
private final String movieTitle;
|
||||
private final String paymentNumber;
|
||||
private final Integer totalPrice;
|
||||
private final LocalDateTime createdAt;
|
||||
private final List<TicketDetailDTO> tickets;
|
||||
|
||||
public PaymentDetailDTO(Payment payment, TicketDetailsResponse ticketDetails) {
|
||||
this(
|
||||
payment.getId(),
|
||||
payment.getMovieTitle(),
|
||||
payment.getPaymentNumber(),
|
||||
payment.getTotalPrice(),
|
||||
payment.getCreatedAt(),
|
||||
ticketDetails.getTicketDetails()
|
||||
);
|
||||
}
|
||||
|
||||
public PaymentDetailResponse toResponse() {
|
||||
return new PaymentDetailResponse(paymentId, movieTitle, paymentNumber, totalPrice, createdAt, tickets);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,15 +7,15 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class SimplePaymentDto {
|
||||
public class SimplePaymentDTO {
|
||||
|
||||
private Long paymentId;
|
||||
private String movieTitle;
|
||||
private String paymentNumber;
|
||||
private Integer totalPrice;
|
||||
private final Long paymentId;
|
||||
private final String movieTitle;
|
||||
private final String paymentNumber;
|
||||
private final Integer totalPrice;
|
||||
|
||||
public static SimplePaymentDto from(Payment payment) {
|
||||
return new SimplePaymentDto(
|
||||
public SimplePaymentDTO(Payment payment) {
|
||||
this(
|
||||
payment.getId(),
|
||||
payment.getMovieTitle(),
|
||||
payment.getPaymentNumber(),
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ticketing.server.payment.service.dto;
|
||||
|
||||
import com.ticketing.server.payment.application.response.SimplePaymentsResponse;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class SimplePaymentsDTO {
|
||||
|
||||
private final Long userAlternateId;
|
||||
private final List<SimplePaymentDTO> payments;
|
||||
|
||||
public SimplePaymentsResponse toResponse() {
|
||||
return new SimplePaymentsResponse(userAlternateId, payments);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.ticketing.server.payment.service.dto;
|
||||
|
||||
import com.ticketing.server.movie.domain.Ticket;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class TicketDetailDTO {
|
||||
|
||||
private final Integer price;
|
||||
private final Integer theaterNumber;
|
||||
private final Integer column;
|
||||
private final Integer row;
|
||||
private final LocalDateTime startAt;
|
||||
private final LocalDateTime endAt;
|
||||
|
||||
public TicketDetailDTO(Ticket ticket) {
|
||||
this(
|
||||
ticket.getTicketPrice(),
|
||||
ticket.getTheaterNumber(),
|
||||
ticket.getColumn(),
|
||||
ticket.getRow(),
|
||||
ticket.getStartAt(),
|
||||
ticket.getEndAt()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.ticketing.server.payment.service.interfaces;
|
||||
|
||||
import com.ticketing.server.payment.service.dto.PaymentDetailDTO;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public interface PaymentApisService {
|
||||
|
||||
PaymentDetailDTO findPaymentDetail(@NotNull Long paymentId);
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.ticketing.server.payment.service.interfaces;
|
||||
|
||||
import com.ticketing.server.user.api.dto.response.SimplePaymentsResponse;
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentsDTO;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public interface PaymentService {
|
||||
|
||||
SimplePaymentsResponse findSimplePayments(Long userId);
|
||||
SimplePaymentsDTO findSimplePayments(@NotNull Long userAlternateId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.ticketing.server.user.api;
|
||||
|
||||
import com.ticketing.server.user.api.dto.request.SimplePaymentsRequest;
|
||||
import com.ticketing.server.user.api.dto.response.SimplePaymentsResponse;
|
||||
import com.ticketing.server.payment.application.response.SimplePaymentsResponse;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public interface PaymentClient {
|
||||
|
||||
SimplePaymentsResponse getSimplePayments(SimplePaymentsRequest request);
|
||||
SimplePaymentsResponse getPayments(@NotNull Long alternateId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.ticketing.server.user.api.dto.request;
|
||||
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class SimplePaymentsRequest {
|
||||
|
||||
private Long userId;
|
||||
|
||||
public static SimplePaymentsRequest from(User user) {
|
||||
return new SimplePaymentsRequest(user.getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.ticketing.server.user.api.dto.response;
|
||||
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentDto;
|
||||
import java.util.List;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class SimplePaymentsResponse {
|
||||
|
||||
private Long userId;
|
||||
|
||||
private List<SimplePaymentDto> payments;
|
||||
|
||||
public static SimplePaymentsResponse from(Long userId, List<SimplePaymentDto> simplePayments) {
|
||||
return new SimplePaymentsResponse(userId, simplePayments);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.ticketing.server.user.api.impl;
|
||||
|
||||
import com.ticketing.server.payment.service.PaymentServiceImpl;
|
||||
import com.ticketing.server.payment.application.response.SimplePaymentsResponse;
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentsDTO;
|
||||
import com.ticketing.server.payment.service.interfaces.PaymentService;
|
||||
import com.ticketing.server.user.api.PaymentClient;
|
||||
import com.ticketing.server.user.api.dto.request.SimplePaymentsRequest;
|
||||
import com.ticketing.server.user.api.dto.response.SimplePaymentsResponse;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -11,11 +12,12 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class PaymentClientImpl implements PaymentClient {
|
||||
|
||||
private final PaymentServiceImpl paymentService;
|
||||
private final PaymentService paymentService;
|
||||
|
||||
@Override
|
||||
public SimplePaymentsResponse getSimplePayments(SimplePaymentsRequest request) {
|
||||
return paymentService.findSimplePayments(request.getUserId());
|
||||
public SimplePaymentsResponse getPayments(@NotNull Long alternateId) {
|
||||
SimplePaymentsDTO payments = paymentService.findSimplePayments(alternateId);
|
||||
return payments.toResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.ticketing.server.user.application;
|
||||
|
||||
import com.ticketing.server.user.application.request.LoginRequest;
|
||||
import com.ticketing.server.user.application.response.LogoutResponse;
|
||||
import com.ticketing.server.user.application.response.TokenDto;
|
||||
import com.ticketing.server.user.service.dto.TokenDTO;
|
||||
import com.ticketing.server.user.application.response.TokenResponse;
|
||||
import com.ticketing.server.user.service.dto.DeleteRefreshTokenDTO;
|
||||
import com.ticketing.server.user.service.interfaces.AuthenticationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -26,29 +28,29 @@ public class AuthController {
|
||||
private final AuthenticationService authenticationService;
|
||||
|
||||
@PostMapping("/token")
|
||||
public ResponseEntity<TokenDto> login(@RequestBody LoginRequest loginRequest) {
|
||||
TokenDto tokenDto = authenticationService.generateTokenDto(loginRequest.toAuthentication());
|
||||
public ResponseEntity<TokenResponse> login(@RequestBody LoginRequest loginRequest) {
|
||||
TokenDTO tokenDto = authenticationService.generateTokenDto(loginRequest.toAuthentication());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.headers(getHttpHeaders())
|
||||
.body(tokenDto);
|
||||
.body(tokenDto.toResponse());
|
||||
}
|
||||
|
||||
@PostMapping("/refresh")
|
||||
public ResponseEntity<TokenDto> refreshToken(@RequestParam("refreshToken") String refreshToken) {
|
||||
TokenDto tokenDto = authenticationService.reissueTokenDto(refreshToken);
|
||||
public ResponseEntity<TokenResponse> refreshToken(@RequestParam("refreshToken") String refreshToken) {
|
||||
TokenDTO tokenDto = authenticationService.reissueTokenDto(refreshToken);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.headers(getHttpHeaders())
|
||||
.body(tokenDto);
|
||||
.body(tokenDto.toResponse());
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
public ResponseEntity<LogoutResponse> logout(@AuthenticationPrincipal UserDetails userRequest) {
|
||||
LogoutResponse logoutResponse = authenticationService.deleteRefreshToken(userRequest.getUsername());
|
||||
DeleteRefreshTokenDTO refreshToken = authenticationService.deleteRefreshToken(userRequest.getUsername());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(logoutResponse);
|
||||
.body(refreshToken.toResponse());
|
||||
}
|
||||
|
||||
private HttpHeaders getHttpHeaders() {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ticketing.server.user.application;
|
||||
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class UserChangeGradeResponse {
|
||||
|
||||
private String email;
|
||||
|
||||
private UserGrade beforeGrade;
|
||||
|
||||
private UserGrade afterGrade;
|
||||
|
||||
}
|
||||
@@ -1,16 +1,26 @@
|
||||
package com.ticketing.server.user.application;
|
||||
|
||||
import static com.ticketing.server.user.domain.UserGrade.ROLES.ADMIN;
|
||||
import static com.ticketing.server.user.domain.UserGrade.ROLES.USER;
|
||||
|
||||
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.application.response.PaymentsResponse;
|
||||
import com.ticketing.server.user.application.response.SignUpResponse;
|
||||
import com.ticketing.server.user.application.response.SimplePaymentDetailsResponse;
|
||||
import com.ticketing.server.user.application.response.UserChangePasswordResponse;
|
||||
import com.ticketing.server.user.application.response.UserDeleteResponse;
|
||||
import com.ticketing.server.user.application.response.UserDetailResponse;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import com.ticketing.server.user.service.UserServiceImpl;
|
||||
import com.ticketing.server.user.domain.ChangeGradeDTO;
|
||||
import com.ticketing.server.user.service.dto.ChangePasswordDTO;
|
||||
import com.ticketing.server.user.service.dto.ChangedPasswordUserDTO;
|
||||
import com.ticketing.server.user.service.dto.CreatedUserDTO;
|
||||
import com.ticketing.server.user.service.dto.DeletedUserDTO;
|
||||
import com.ticketing.server.user.service.dto.PaymentsDTO;
|
||||
import com.ticketing.server.user.service.dto.UserDetailDTO;
|
||||
import com.ticketing.server.user.service.interfaces.UserApisService;
|
||||
import com.ticketing.server.user.service.interfaces.UserService;
|
||||
import javax.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -34,43 +44,64 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
public class UserController {
|
||||
|
||||
private final UserServiceImpl userService;
|
||||
private final UserService userService;
|
||||
private final UserApisService userApisService;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<SignUpResponse> register(@RequestBody @Valid SignUpRequest request) {
|
||||
User user = userService.register(request.toSignUpDto(passwordEncoder));
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(SignUpResponse.from(user));
|
||||
CreatedUserDTO createdUserDto = userService.register(request.toSignUpDto(passwordEncoder));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(createdUserDto.toResponse());
|
||||
}
|
||||
|
||||
@GetMapping("/details")
|
||||
@Secured("ROLE_GUEST")
|
||||
@Secured(USER)
|
||||
public ResponseEntity<UserDetailResponse> details(@AuthenticationPrincipal UserDetails userRequest) {
|
||||
User user = userService.findByEmail(userRequest.getUsername());
|
||||
return ResponseEntity.status(HttpStatus.OK).body(UserDetailResponse.from(user));
|
||||
UserDetailDTO userDetail = userService.findDetailByEmail(userRequest.getUsername());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(userDetail.toResponse());
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Secured(UserGrade.ROLES.GUEST)
|
||||
@Secured(USER)
|
||||
public ResponseEntity<UserDeleteResponse> deleteUser(@RequestBody @Valid UserDeleteRequest request) {
|
||||
User user = userService.delete(request.toDeleteUserDto(passwordEncoder));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(UserDeleteResponse.from(user));
|
||||
DeletedUserDTO deletedUserDto = userService.delete(request.toDeleteUserDto(passwordEncoder));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(deletedUserDto.toResponse());
|
||||
}
|
||||
|
||||
@PutMapping("/password")
|
||||
@Secured(UserGrade.ROLES.GUEST)
|
||||
@Secured(USER)
|
||||
public ResponseEntity<UserChangePasswordResponse> changePassword(
|
||||
@AuthenticationPrincipal UserDetails userRequest,
|
||||
@RequestBody @Valid UserChangePasswordRequest request) {
|
||||
User user = userService.changePassword(request.toChangePasswordDto(userRequest.getUsername(), passwordEncoder));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(UserChangePasswordResponse.from(user));
|
||||
ChangePasswordDTO changePasswordDto = request.toChangePasswordDto(userRequest.getUsername(), passwordEncoder);
|
||||
ChangedPasswordUserDTO changedUserDto = userService.changePassword(changePasswordDto);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(changedUserDto.toResponse());
|
||||
}
|
||||
|
||||
@PostMapping("/grade")
|
||||
@Secured(ADMIN)
|
||||
public ResponseEntity<UserChangeGradeResponse> changeGrade(@RequestBody @Valid UserChangeGradeRequest request) {
|
||||
ChangeGradeDTO changeGradeDto = userService.changeGrade(request.getEmail(), request.getAfterGrade());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(changeGradeDto.toResponse());
|
||||
}
|
||||
|
||||
@GetMapping("/payments")
|
||||
@Secured("ROLE_GUEST")
|
||||
public ResponseEntity<SimplePaymentDetailsResponse> getPayments(@AuthenticationPrincipal UserDetails userRequest) {
|
||||
SimplePaymentDetailsResponse paymentDetails = userService.findSimplePaymentDetails(userRequest.getUsername());
|
||||
return ResponseEntity.status(HttpStatus.OK).body(paymentDetails);
|
||||
@Secured(USER)
|
||||
public ResponseEntity<PaymentsResponse> getPayments(@AuthenticationPrincipal UserDetails userRequest) {
|
||||
PaymentsDTO paymentsDto = userApisService.findPaymentsByEmail(userRequest.getUsername());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(paymentsDto.toResponse());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ticketing.server.user.application.request;
|
||||
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class UserChangeGradeRequest {
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.email}")
|
||||
@Email(message = "{validation.email}")
|
||||
private String email;
|
||||
|
||||
@NotNull(message = "{validation.not.null.grade}")
|
||||
private UserGrade afterGrade;
|
||||
|
||||
}
|
||||
@@ -1,28 +1,14 @@
|
||||
package com.ticketing.server.user.application.response;
|
||||
|
||||
import com.ticketing.server.global.redis.RefreshToken;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@AllArgsConstructor
|
||||
public class LogoutResponse {
|
||||
|
||||
private Long refreshTokenId;
|
||||
private String email;
|
||||
private String refreshToken;
|
||||
|
||||
private LogoutResponse(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public static LogoutResponse from(String email) {
|
||||
return new LogoutResponse(email);
|
||||
}
|
||||
|
||||
public static LogoutResponse from(RefreshToken refreshToken) {
|
||||
return new LogoutResponse(refreshToken.getId(), refreshToken.getEmail(), refreshToken.getToken());
|
||||
}
|
||||
private final Long refreshTokenId;
|
||||
private final String email;
|
||||
private final String refreshToken;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ticketing.server.user.application.response;
|
||||
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentDTO;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class PaymentsResponse {
|
||||
|
||||
private final String email;
|
||||
private final List<SimplePaymentDTO> payments;
|
||||
|
||||
}
|
||||
@@ -1,20 +1,13 @@
|
||||
package com.ticketing.server.user.application.response;
|
||||
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@AllArgsConstructor
|
||||
public class SignUpResponse {
|
||||
|
||||
private String name;
|
||||
|
||||
private String email;
|
||||
|
||||
public static SignUpResponse from(User user) {
|
||||
return new SignUpResponse(user.getName(), user.getEmail());
|
||||
}
|
||||
private final String name;
|
||||
private final String email;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.ticketing.server.user.application.response;
|
||||
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentDto;
|
||||
import com.ticketing.server.user.api.dto.response.SimplePaymentsResponse;
|
||||
import java.util.List;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class SimplePaymentDetailsResponse {
|
||||
|
||||
private String email;
|
||||
private List<SimplePaymentDto> payments;
|
||||
|
||||
public static SimplePaymentDetailsResponse of(String email, SimplePaymentsResponse paymentsResponse) {
|
||||
return new SimplePaymentDetailsResponse(email, paymentsResponse.getPayments());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.ticketing.server.user.application.response;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class TokenDto {
|
||||
|
||||
private final String accessToken;
|
||||
private final String refreshToken;
|
||||
private final String tokenType;
|
||||
private final long expiresIn;
|
||||
|
||||
public static TokenDto of(String accessToken, String refreshToken, String tokenType, long expiresIn) {
|
||||
return new TokenDto(accessToken, refreshToken, tokenType, expiresIn);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ticketing.server.user.application.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class TokenResponse {
|
||||
|
||||
private final String accessToken;
|
||||
private final String refreshToken;
|
||||
private final String tokenType;
|
||||
private final long expiresIn;
|
||||
|
||||
}
|
||||
@@ -1,20 +1,15 @@
|
||||
package com.ticketing.server.user.application.response;
|
||||
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import lombok.AccessLevel;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@AllArgsConstructor
|
||||
public class UserChangePasswordResponse {
|
||||
|
||||
private String name;
|
||||
|
||||
private String email;
|
||||
|
||||
public static UserChangePasswordResponse from(User user) {
|
||||
return new UserChangePasswordResponse(user.getName(), user.getEmail());
|
||||
}
|
||||
private final String name;
|
||||
private final String email;
|
||||
private final LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
package com.ticketing.server.user.application.response;
|
||||
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import lombok.AccessLevel;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@AllArgsConstructor
|
||||
public class UserDeleteResponse {
|
||||
|
||||
private String name;
|
||||
|
||||
private String email;
|
||||
|
||||
public static UserDeleteResponse from(User user) {
|
||||
return new UserDeleteResponse(user.getName(), user.getEmail());
|
||||
}
|
||||
private final String name;
|
||||
private final String email;
|
||||
private final LocalDateTime deletedAt;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.ticketing.server.user.application.response;
|
||||
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import com.ticketing.server.user.service.dto.UserDetailDTO;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -9,13 +10,9 @@ import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
public class UserDetailResponse {
|
||||
|
||||
private String name;
|
||||
private String email;
|
||||
private UserGrade grade;
|
||||
private String phone;
|
||||
|
||||
public static UserDetailResponse from(User user) {
|
||||
return new UserDetailResponse(user.getName(), user.getEmail(), user.getGrade(), user.getPhone());
|
||||
}
|
||||
private final String name;
|
||||
private final String email;
|
||||
private final UserGrade grade;
|
||||
private final String phone;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ticketing.server.user.domain;
|
||||
|
||||
import com.ticketing.server.user.application.UserChangeGradeResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class ChangeGradeDTO {
|
||||
|
||||
private final String email;
|
||||
private final UserGrade beforeGrade;
|
||||
private final UserGrade afterGrade;
|
||||
|
||||
public UserChangeGradeResponse toResponse() {
|
||||
return new UserChangeGradeResponse(email, beforeGrade, afterGrade);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.ticketing.server.user.domain;
|
||||
|
||||
public interface SequenceGenerator {
|
||||
|
||||
Long generateId();
|
||||
|
||||
long[] parse(long id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.ticketing.server.user.domain;
|
||||
|
||||
import java.net.NetworkInterface;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.Instant;
|
||||
import java.util.Enumeration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Twitter Snowflake Custom.
|
||||
* https://github.com/callicoder/java-snowflake
|
||||
*/
|
||||
@Component
|
||||
public class Snowflake implements SequenceGenerator {
|
||||
|
||||
private static final int EPOCH_BITS = 41;
|
||||
private static final int NODE_ID_BITS = 10;
|
||||
private static final int SEQUENCE_BITS = 12;
|
||||
|
||||
private static final long MAX_NODE_ID = (1L << NODE_ID_BITS) - 1;
|
||||
private static final long MAX_SEQUENCE = (1L << SEQUENCE_BITS) - 1;
|
||||
|
||||
// Custom Epoch (January 1, 2015 Midnight UTC = 2015-01-01T00:00:00Z)
|
||||
private static final long DEFAULT_CUSTOM_EPOCH = 1420070400000L;
|
||||
|
||||
private final long nodeId;
|
||||
private final long customEpoch;
|
||||
|
||||
private volatile long lastTimestamp = -1L;
|
||||
private volatile long sequence = 0L;
|
||||
|
||||
// Let Snowflake generate a nodeId
|
||||
public Snowflake() {
|
||||
this.nodeId = createNodeId();
|
||||
this.customEpoch = DEFAULT_CUSTOM_EPOCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long generateId() {
|
||||
return nextId();
|
||||
}
|
||||
|
||||
private synchronized long nextId() {
|
||||
long currentTimestamp = timestamp();
|
||||
|
||||
if(currentTimestamp < lastTimestamp) {
|
||||
throw new IllegalStateException("Invalid System Clock!");
|
||||
}
|
||||
|
||||
if (currentTimestamp == lastTimestamp) {
|
||||
sequence = (sequence + 1) & MAX_SEQUENCE;
|
||||
if(sequence == 0) {
|
||||
// 동일 밀리초 시퀀스가 소진됐을 경우 대기.
|
||||
currentTimestamp = waitNextMillis(currentTimestamp);
|
||||
}
|
||||
} else {
|
||||
// 다음 밀리초 시퀀스 초기화.
|
||||
sequence = 0;
|
||||
}
|
||||
|
||||
lastTimestamp = currentTimestamp;
|
||||
return currentTimestamp << (NODE_ID_BITS + SEQUENCE_BITS)
|
||||
| (nodeId << SEQUENCE_BITS)
|
||||
| sequence;
|
||||
}
|
||||
|
||||
public long[] parse(long id) {
|
||||
long maskNodeId = ((1L << NODE_ID_BITS) - 1) << SEQUENCE_BITS;
|
||||
long maskSequence = (1L << SEQUENCE_BITS) - 1;
|
||||
|
||||
long timestamp = (id >> (NODE_ID_BITS + SEQUENCE_BITS)) + customEpoch;
|
||||
long nodeId = (id & maskNodeId) >> SEQUENCE_BITS;
|
||||
long sequence = id & maskSequence;
|
||||
|
||||
return new long[]{timestamp, nodeId, sequence};
|
||||
}
|
||||
|
||||
private long timestamp() {
|
||||
return Instant.now().toEpochMilli() - customEpoch;
|
||||
}
|
||||
|
||||
private long waitNextMillis(long currentTimestamp) {
|
||||
while (currentTimestamp == lastTimestamp) {
|
||||
currentTimestamp = timestamp();
|
||||
}
|
||||
return currentTimestamp;
|
||||
}
|
||||
|
||||
private long createNodeId() {
|
||||
long nodeId;
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
while (networkInterfaces.hasMoreElements()) {
|
||||
NetworkInterface networkInterface = networkInterfaces.nextElement();
|
||||
byte[] mac = networkInterface.getHardwareAddress();
|
||||
if (mac != null) {
|
||||
for(byte macPort: mac) {
|
||||
sb.append(String.format("%02X", macPort));
|
||||
}
|
||||
}
|
||||
}
|
||||
nodeId = sb.toString().hashCode();
|
||||
} catch (Exception ex) {
|
||||
nodeId = (new SecureRandom().nextInt());
|
||||
}
|
||||
nodeId = nodeId & MAX_NODE_ID;
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Snowflake Settings [EPOCH_BITS=" + EPOCH_BITS + ", NODE_ID_BITS=" + NODE_ID_BITS
|
||||
+ ", SEQUENCE_BITS=" + SEQUENCE_BITS + ", CUSTOM_EPOCH=" + customEpoch
|
||||
+ ", NodeId=" + nodeId + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,42 +14,54 @@ import javax.persistence.Enumerated;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class User extends AbstractEntity {
|
||||
|
||||
@Column(name = "name")
|
||||
@Column(name = "alternate_key", unique = true, nullable = false)
|
||||
@NotNull(message = "{validation.not.null.alternate.key}")
|
||||
private Long alternateId;
|
||||
|
||||
@Column(name = "name", nullable = false)
|
||||
@NotEmpty(message = "{validation.not.empty.name}")
|
||||
private String name;
|
||||
|
||||
@Column(name = "email")
|
||||
@Column(name = "email", unique = true, nullable = false)
|
||||
@NotEmpty(message = "{validation.not.empty.email}")
|
||||
@Email(message = "{validation.email}")
|
||||
private String email;
|
||||
|
||||
@Column(name = "password")
|
||||
@Column(name = "password", nullable = false)
|
||||
@NotEmpty(message = "{validation.not.empty.password}")
|
||||
private String password;
|
||||
|
||||
@Column(name = "grade")
|
||||
@NotNull(message = "{validation.not.empty.grade}")
|
||||
@Column(name = "grade", nullable = false)
|
||||
@NotNull(message = "{validation.not.null.grade}")
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
private UserGrade grade = UserGrade.GUEST;
|
||||
private UserGrade grade = UserGrade.USER;
|
||||
|
||||
@Column(name = "phone")
|
||||
@Column(name = "phone", nullable = false)
|
||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
||||
@Phone
|
||||
private String phone;
|
||||
|
||||
private boolean isDeleted = false;
|
||||
public User(Long alternateId, String name, String email, String password, UserGrade grade, String phone) {
|
||||
this.alternateId = alternateId;
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.grade = grade;
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
private LocalDateTime deletedAt;
|
||||
|
||||
public User(String name, String email, String password, UserGrade grade, String phone) {
|
||||
User(Long id, Long alternateId, String name, String email, String password, UserGrade grade, String phone) {
|
||||
this.id = id;
|
||||
this.alternateId = alternateId;
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
@@ -58,13 +70,12 @@ public class User extends AbstractEntity {
|
||||
}
|
||||
|
||||
public User delete(DeleteUserDTO deleteUser) {
|
||||
if (isDeleted) {
|
||||
if (deletedAt != null) {
|
||||
throw ErrorCode.throwDeletedEmail();
|
||||
}
|
||||
|
||||
checkPassword(deleteUser);
|
||||
|
||||
isDeleted = true;
|
||||
deletedAt = LocalDateTime.now();
|
||||
return this;
|
||||
}
|
||||
@@ -82,4 +93,14 @@ public class User extends AbstractEntity {
|
||||
}
|
||||
}
|
||||
|
||||
public ChangeGradeDTO changeGrade(UserGrade afterGrade) {
|
||||
if (grade.equals(afterGrade)) {
|
||||
throw ErrorCode.throwUnableChangeGrade();
|
||||
}
|
||||
final UserGrade beforeGrade = this.grade;
|
||||
|
||||
this.grade = afterGrade;
|
||||
return new ChangeGradeDTO(email, beforeGrade, afterGrade);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor;
|
||||
public enum UserGrade {
|
||||
ADMIN(ROLES.ADMIN, null),
|
||||
STAFF(ROLES.STAFF, ROLES.ADMIN),
|
||||
GUEST(ROLES.GUEST, ROLES.STAFF);
|
||||
USER(ROLES.USER, ROLES.STAFF);
|
||||
|
||||
private final String roleName;
|
||||
private final String parentName;
|
||||
@@ -15,7 +15,7 @@ public enum UserGrade {
|
||||
|
||||
public static final String ADMIN = "ROLE_ADMIN";
|
||||
public static final String STAFF = "ROLE_STAFF";
|
||||
public static final String GUEST = "ROLE_GUEST";
|
||||
public static final String USER = "ROLE_USER";
|
||||
|
||||
private ROLES() {
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
|
||||
|
||||
Optional<User> findByEmail(String email);
|
||||
|
||||
Optional<User> findByEmailAndIsDeletedFalse(String email);
|
||||
Optional<User> findByEmailAndDeletedAtNull(String email);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import com.ticketing.server.global.redis.RefreshRedisRepository;
|
||||
import com.ticketing.server.global.redis.RefreshToken;
|
||||
import com.ticketing.server.global.security.jwt.JwtProperties;
|
||||
import com.ticketing.server.global.security.jwt.JwtProvider;
|
||||
import com.ticketing.server.user.application.response.LogoutResponse;
|
||||
import com.ticketing.server.user.application.response.TokenDto;
|
||||
import com.ticketing.server.user.service.dto.TokenDTO;
|
||||
import com.ticketing.server.user.service.dto.DeleteRefreshTokenDTO;
|
||||
import com.ticketing.server.user.service.interfaces.AuthenticationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
@@ -28,14 +28,14 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public TokenDto generateTokenDto(UsernamePasswordAuthenticationToken authenticationToken) {
|
||||
public TokenDTO generateTokenDto(UsernamePasswordAuthenticationToken authenticationToken) {
|
||||
// 회원인증
|
||||
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
|
||||
|
||||
String email = authenticationToken.getName();
|
||||
|
||||
// 토큰 발급
|
||||
TokenDto tokenDto = jwtProvider.generateTokenDto(authentication);
|
||||
TokenDTO tokenDto = jwtProvider.generateTokenDto(authentication);
|
||||
|
||||
// refresh 토큰이 있으면 수정, 없으면 생성
|
||||
refreshRedisRepository.findByEmail(email)
|
||||
@@ -49,7 +49,7 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public TokenDto reissueTokenDto(String bearerRefreshToken) {
|
||||
public TokenDTO reissueTokenDto(String bearerRefreshToken) {
|
||||
String refreshToken = resolveToken(bearerRefreshToken);
|
||||
|
||||
// 토큰 검증
|
||||
@@ -67,7 +67,7 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
}
|
||||
|
||||
// 토큰 발급
|
||||
TokenDto tokenDto = jwtProvider.generateTokenDto(authentication);
|
||||
TokenDTO tokenDto = jwtProvider.generateTokenDto(authentication);
|
||||
|
||||
// 토큰 최신화
|
||||
findTokenEntity.changeToken(tokenDto.getRefreshToken());
|
||||
@@ -78,12 +78,14 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public LogoutResponse deleteRefreshToken(String email) {
|
||||
public DeleteRefreshTokenDTO deleteRefreshToken(String email) {
|
||||
return refreshRedisRepository.findByEmail(email)
|
||||
.map(tokenDto -> {
|
||||
refreshRedisRepository.delete(tokenDto);
|
||||
return LogoutResponse.from(tokenDto);
|
||||
}).orElseGet(() -> LogoutResponse.from(email));
|
||||
return new DeleteRefreshTokenDTO(tokenDto);
|
||||
}).orElseGet(
|
||||
() -> new DeleteRefreshTokenDTO(email)
|
||||
);
|
||||
}
|
||||
|
||||
private String resolveToken(String bearerToken) {
|
||||
|
||||
@@ -19,7 +19,7 @@ public class CustomUserDetailsService implements UserDetailsService {
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
|
||||
return userRepository.findByEmailAndIsDeletedFalse(email)
|
||||
return userRepository.findByEmailAndDeletedAtNull(email)
|
||||
.map(this::createUserDetails)
|
||||
.orElseThrow(ErrorCode::throwEmailNotFound);
|
||||
}
|
||||
@@ -33,4 +33,5 @@ public class CustomUserDetailsService implements UserDetailsService {
|
||||
, Collections.singleton(grantedAuthority)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ticketing.server.user.service;
|
||||
|
||||
import com.ticketing.server.payment.application.response.SimplePaymentsResponse;
|
||||
import com.ticketing.server.user.api.PaymentClient;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.service.dto.PaymentsDTO;
|
||||
import com.ticketing.server.user.service.interfaces.UserApisService;
|
||||
import com.ticketing.server.user.service.interfaces.UserService;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class UserApisServiceImpl implements UserApisService {
|
||||
|
||||
private final PaymentClient paymentClient;
|
||||
private final UserService userService;
|
||||
|
||||
@Override
|
||||
public PaymentsDTO findPaymentsByEmail(@NotNull String email) {
|
||||
User user = userService.findNotDeletedUserByEmail(email);
|
||||
SimplePaymentsResponse simplePayments = paymentClient.getPayments(user.getAlternateId());
|
||||
|
||||
return new PaymentsDTO(user, simplePayments);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +1,22 @@
|
||||
package com.ticketing.server.user.service;
|
||||
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.user.api.PaymentClient;
|
||||
import com.ticketing.server.user.api.dto.request.SimplePaymentsRequest;
|
||||
import com.ticketing.server.user.api.dto.response.SimplePaymentsResponse;
|
||||
import com.ticketing.server.user.application.response.SimplePaymentDetailsResponse;
|
||||
import com.ticketing.server.user.domain.ChangeGradeDTO;
|
||||
import com.ticketing.server.user.domain.SequenceGenerator;
|
||||
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.ChangePasswordDTO;
|
||||
import com.ticketing.server.user.service.dto.ChangedPasswordUserDTO;
|
||||
import com.ticketing.server.user.service.dto.CreatedUserDTO;
|
||||
import com.ticketing.server.user.service.dto.DeleteUserDTO;
|
||||
import com.ticketing.server.user.service.dto.DeletedUserDTO;
|
||||
import com.ticketing.server.user.service.dto.SignUpDTO;
|
||||
import com.ticketing.server.user.service.dto.UserDetailDTO;
|
||||
import com.ticketing.server.user.service.interfaces.UserService;
|
||||
import java.util.Optional;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -27,14 +31,15 @@ import org.springframework.validation.annotation.Validated;
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final PaymentClient paymentClient;
|
||||
private final SequenceGenerator sequenceGenerator;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public User register(@Valid SignUpDTO signUpDto) {
|
||||
Optional<User> user = userRepository.findByEmail(signUpDto.getEmail());
|
||||
if (user.isEmpty()) {
|
||||
return userRepository.save(signUpDto.toUser());
|
||||
public CreatedUserDTO register(@Valid SignUpDTO signUpDto) {
|
||||
Optional<User> optionalUser = userRepository.findByEmail(signUpDto.getEmail());
|
||||
if (optionalUser.isEmpty()) {
|
||||
User user = userRepository.save(signUpDto.toUser(sequenceGenerator.generateId()));
|
||||
return new CreatedUserDTO(user);
|
||||
}
|
||||
|
||||
throw ErrorCode.throwDuplicateEmail();
|
||||
@@ -42,34 +47,40 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public User delete(@Valid DeleteUserDTO deleteUserDto) {
|
||||
User user = findNotDeletedUserByEmail(deleteUserDto.getEmail());
|
||||
return user.delete(deleteUserDto);
|
||||
public DeletedUserDTO delete(@Valid DeleteUserDTO deleteUserDto) {
|
||||
User user = findNotDeletedUserByEmail(deleteUserDto.getEmail())
|
||||
.delete(deleteUserDto);
|
||||
|
||||
return new DeletedUserDTO(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public User changePassword(@Valid ChangePasswordDTO changePasswordDto) {
|
||||
User user = findNotDeletedUserByEmail(changePasswordDto.getEmail());
|
||||
return user.changePassword(changePasswordDto);
|
||||
public ChangedPasswordUserDTO changePassword(@Valid ChangePasswordDTO changePasswordDto) {
|
||||
User user = findNotDeletedUserByEmail(changePasswordDto.getEmail())
|
||||
.changePassword(changePasswordDto);
|
||||
|
||||
return new ChangedPasswordUserDTO(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findByEmail(String email) {
|
||||
return userRepository.findByEmail(email)
|
||||
.orElseThrow(ErrorCode::throwEmailNotFound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimplePaymentDetailsResponse findSimplePaymentDetails(String email) {
|
||||
@Transactional
|
||||
public ChangeGradeDTO changeGrade(@NotNull String email, @NotNull UserGrade grade) {
|
||||
User user = findNotDeletedUserByEmail(email);
|
||||
SimplePaymentsResponse simplePayments = paymentClient.getSimplePayments(SimplePaymentsRequest.from(user));
|
||||
|
||||
return SimplePaymentDetailsResponse.of(email, simplePayments);
|
||||
return user.changeGrade(grade);
|
||||
}
|
||||
|
||||
private User findNotDeletedUserByEmail(String email) {
|
||||
return userRepository.findByEmailAndIsDeletedFalse(email)
|
||||
@Override
|
||||
public UserDetailDTO findDetailByEmail(@NotNull String email) {
|
||||
User user = userRepository.findByEmail(email)
|
||||
.orElseThrow(ErrorCode::throwEmailNotFound);
|
||||
|
||||
return new UserDetailDTO(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findNotDeletedUserByEmail(@NotNull String email) {
|
||||
return userRepository.findByEmailAndDeletedAtNull(email)
|
||||
.orElseThrow(ErrorCode::throwEmailNotFound);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,28 +2,23 @@ package com.ticketing.server.user.service.dto;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class ChangePasswordDTO implements PasswordMatches {
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.email}")
|
||||
@Email(message = "{validation.email}")
|
||||
private String email;
|
||||
private final String email;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.oldpassword}")
|
||||
private String oldPassword;
|
||||
private final String oldPassword;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.newpassword}")
|
||||
private String newPassword;
|
||||
private final String newPassword;
|
||||
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
public ChangePasswordDTO(String email, String oldPassword, String newPassword, PasswordEncoder passwordEncoder) {
|
||||
this.email = email;
|
||||
this.oldPassword = oldPassword;
|
||||
this.newPassword = newPassword;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.ticketing.server.user.service.dto;
|
||||
|
||||
import com.ticketing.server.user.application.response.UserChangePasswordResponse;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class ChangedPasswordUserDTO {
|
||||
|
||||
private final String name;
|
||||
private final String email;
|
||||
private final LocalDateTime updatedAt;
|
||||
|
||||
public ChangedPasswordUserDTO(User user) {
|
||||
this(user.getName(), user.getEmail(), user.getUpdatedAt());
|
||||
}
|
||||
|
||||
public UserChangePasswordResponse toResponse() {
|
||||
return new UserChangePasswordResponse(name, email, updatedAt);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ticketing.server.user.service.dto;
|
||||
|
||||
import com.ticketing.server.user.application.response.SignUpResponse;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class CreatedUserDTO {
|
||||
|
||||
private final String name;
|
||||
private final String email;
|
||||
|
||||
public CreatedUserDTO(User user) {
|
||||
this(
|
||||
user.getName(),
|
||||
user.getEmail()
|
||||
);
|
||||
}
|
||||
|
||||
public SignUpResponse toResponse() {
|
||||
return new SignUpResponse(name, email);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.ticketing.server.user.service.dto;
|
||||
|
||||
import com.ticketing.server.global.redis.RefreshToken;
|
||||
import com.ticketing.server.user.application.response.LogoutResponse;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class DeleteRefreshTokenDTO {
|
||||
|
||||
private final Long refreshTokenId;
|
||||
private final String email;
|
||||
private final String refreshToken;
|
||||
|
||||
public DeleteRefreshTokenDTO(String email) {
|
||||
this(null, email, null);
|
||||
}
|
||||
|
||||
public DeleteRefreshTokenDTO(RefreshToken refreshToken) {
|
||||
this(refreshToken.getId(), refreshToken.getEmail(), refreshToken.getToken());
|
||||
}
|
||||
|
||||
public LogoutResponse toResponse() {
|
||||
return new LogoutResponse(refreshTokenId, email, refreshToken);
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,20 @@ package com.ticketing.server.user.service.dto;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class DeleteUserDTO implements PasswordMatches {
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.email}")
|
||||
@Email(message = "{validation.email}")
|
||||
private String email;
|
||||
private final String email;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.password}")
|
||||
private String inputPassword;
|
||||
private final String inputPassword;
|
||||
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
public DeleteUserDTO(String email, String inputPassword, PasswordEncoder passwordEncoder) {
|
||||
this.email = email;
|
||||
this.inputPassword = inputPassword;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@Override
|
||||
public boolean passwordMatches(String password) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.ticketing.server.user.service.dto;
|
||||
|
||||
import com.ticketing.server.user.application.response.UserDeleteResponse;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class DeletedUserDTO {
|
||||
|
||||
private final String name;
|
||||
private final String email;
|
||||
private final LocalDateTime deletedAt;
|
||||
|
||||
public DeletedUserDTO(User user) {
|
||||
this(user.getName(), user.getEmail(), user.getDeletedAt());
|
||||
}
|
||||
|
||||
public UserDeleteResponse toResponse() {
|
||||
return new UserDeleteResponse(name, email, deletedAt);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ticketing.server.user.service.dto;
|
||||
|
||||
import com.ticketing.server.payment.application.response.SimplePaymentsResponse;
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentDTO;
|
||||
import com.ticketing.server.user.application.response.PaymentsResponse;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import java.util.List;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class PaymentsDTO {
|
||||
|
||||
private final String email;
|
||||
private final List<SimplePaymentDTO> payments;
|
||||
|
||||
public PaymentsDTO(User user, SimplePaymentsResponse simplePayments) {
|
||||
this(user.getEmail(), simplePayments.getPayments());
|
||||
}
|
||||
|
||||
public PaymentsResponse toResponse() {
|
||||
return new PaymentsResponse(email, payments);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,34 +5,29 @@ 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.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class SignUpDTO {
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.name}")
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.email}")
|
||||
@Email(message = "{validation.email}")
|
||||
private String email;
|
||||
private final String email;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.password}")
|
||||
private String password;
|
||||
private final String password;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
||||
@Phone
|
||||
private String phone;
|
||||
private final String phone;
|
||||
|
||||
public SignUpDTO(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);
|
||||
public User toUser(long alternateId) {
|
||||
return new User(alternateId, this.name, this.email, password, UserGrade.USER, this.phone);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.ticketing.server.user.service.dto;
|
||||
|
||||
import com.ticketing.server.user.application.response.TokenResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class TokenDTO {
|
||||
|
||||
private final String accessToken;
|
||||
private final String refreshToken;
|
||||
private final String tokenType;
|
||||
private final long expiresIn;
|
||||
|
||||
public TokenResponse toResponse() {
|
||||
return new TokenResponse(accessToken, refreshToken, tokenType, expiresIn);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ticketing.server.user.service.dto;
|
||||
|
||||
import com.ticketing.server.user.application.response.UserDetailResponse;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class UserDetailDTO {
|
||||
|
||||
private final Long alternateId;
|
||||
private final String name;
|
||||
private final String email;
|
||||
private final UserGrade grade;
|
||||
private final String phone;
|
||||
|
||||
public UserDetailDTO(User user) {
|
||||
this(
|
||||
user.getAlternateId(),
|
||||
user.getName(),
|
||||
user.getEmail(),
|
||||
user.getGrade(),
|
||||
user.getPhone()
|
||||
);
|
||||
}
|
||||
|
||||
public UserDetailResponse toResponse() {
|
||||
return new UserDetailResponse(name, email, grade, phone);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.ticketing.server.user.service.interfaces;
|
||||
|
||||
import com.ticketing.server.user.application.response.LogoutResponse;
|
||||
import com.ticketing.server.user.application.response.TokenDto;
|
||||
import com.ticketing.server.user.service.dto.TokenDTO;
|
||||
import com.ticketing.server.user.service.dto.DeleteRefreshTokenDTO;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
|
||||
public interface AuthenticationService {
|
||||
|
||||
TokenDto generateTokenDto(UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken);
|
||||
TokenDTO generateTokenDto(UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken);
|
||||
|
||||
TokenDto reissueTokenDto(String bearerRefreshToken);
|
||||
TokenDTO reissueTokenDto(String bearerRefreshToken);
|
||||
|
||||
LogoutResponse deleteRefreshToken(String email);
|
||||
DeleteRefreshTokenDTO deleteRefreshToken(String email);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ticketing.server.user.service.interfaces;
|
||||
|
||||
import com.ticketing.server.user.service.dto.PaymentsDTO;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public interface UserApisService {
|
||||
|
||||
PaymentsDTO findPaymentsByEmail(@NotNull String email);
|
||||
|
||||
}
|
||||
@@ -1,22 +1,30 @@
|
||||
package com.ticketing.server.user.service.interfaces;
|
||||
|
||||
import com.ticketing.server.user.application.response.SimplePaymentDetailsResponse;
|
||||
import com.ticketing.server.user.domain.ChangeGradeDTO;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import com.ticketing.server.user.service.dto.ChangePasswordDTO;
|
||||
import com.ticketing.server.user.service.dto.ChangedPasswordUserDTO;
|
||||
import com.ticketing.server.user.service.dto.CreatedUserDTO;
|
||||
import com.ticketing.server.user.service.dto.DeleteUserDTO;
|
||||
import com.ticketing.server.user.service.dto.DeletedUserDTO;
|
||||
import com.ticketing.server.user.service.dto.SignUpDTO;
|
||||
import com.ticketing.server.user.service.dto.UserDetailDTO;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
User register(@Valid SignUpDTO signUpDto);
|
||||
CreatedUserDTO register(@Valid SignUpDTO signUpDto);
|
||||
|
||||
User delete(@Valid DeleteUserDTO deleteUserDto);
|
||||
DeletedUserDTO delete(@Valid DeleteUserDTO deleteUserDto);
|
||||
|
||||
User changePassword(@Valid ChangePasswordDTO changePasswordDto);
|
||||
ChangedPasswordUserDTO changePassword(@Valid ChangePasswordDTO changePasswordDto);
|
||||
|
||||
User findByEmail(String email);
|
||||
ChangeGradeDTO changeGrade(@NotNull String email, @NotNull UserGrade grade);
|
||||
|
||||
SimplePaymentDetailsResponse findSimplePaymentDetails(String email);
|
||||
UserDetailDTO findDetailByEmail(@NotNull String email);
|
||||
|
||||
User findNotDeletedUserByEmail(@NotNull String email);
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ jwt:
|
||||
refresh-header: REFRESH_TOKEN
|
||||
prefix: Bearer
|
||||
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK
|
||||
access-token-validity-in-seconds: 60 # 1분
|
||||
access-token-validity-in-seconds: 1800 # 30분
|
||||
refresh-token-validity-in-seconds: 259200 # 3일
|
||||
|
||||
springfox:
|
||||
|
||||
@@ -3,8 +3,11 @@ validation.not.empty.email=\uC774\uBA54\uC77C\uC740 \uD544\uC218 \uC785\uB2C8\uB
|
||||
validation.not.empty.password=\uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4.
|
||||
validation.not.empty.oldpassword=\uD604\uC7AC \uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4.
|
||||
validation.not.empty.newpassword=\uBCC0\uACBD\uD560 \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.not.null.grade=\uC0AC\uC6A9\uC790 \uB4F1\uAE09\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4.
|
||||
validation.not.null.payment.id=\uACB0\uC81C ID\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4.
|
||||
validation.not.null.alternate.key=\uB300\uCCB4\uD0A4\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.
|
||||
validation.password.not.change=\uB3D9\uC77C\uD55C \uD328\uC2A4\uC6CC\uB4DC\uB85C \uBCC0\uACBD\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@ validation.not.empty.email=email is required.
|
||||
validation.not.empty.password=password is required.
|
||||
validation.not.empty.oldpassword=Old Password is required.
|
||||
validation.not.empty.newpassword=New Password is required.
|
||||
validation.not.empty.grade=user grade is required.
|
||||
validation.not.empty.phone=phone is required.
|
||||
validation.not.null.grade=user grade is required.
|
||||
validation.not.null.payment.id=payment id is required.
|
||||
validation.not.null.alternate.key=alternate Key is required.
|
||||
validation.email=email is not valid.
|
||||
validation.phone=phone is not valid.
|
||||
validation.password.not.change=password not change.
|
||||
|
||||
@@ -3,8 +3,11 @@ validation.not.empty.email=\uC774\uBA54\uC77C\uC740 \uD544\uC218 \uC785\uB2C8\uB
|
||||
validation.not.empty.password=\uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4.
|
||||
validation.not.empty.oldpassword=\uD604\uC7AC \uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4.
|
||||
validation.not.empty.newpassword=\uBCC0\uACBD\uD560 \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.not.null.grade=\uC0AC\uC6A9\uC790 \uB4F1\uAE09\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4.
|
||||
validation.not.null.payment.id=\uACB0\uC81C ID\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4.
|
||||
validation.not.null.alternate.key=\uB300\uCCB4\uD0A4\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.
|
||||
validation.password.not.change=\uB3D9\uC77C\uD55C \uD328\uC2A4\uC6CC\uB4DC\uB85C \uBCC0\uACBD\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.ticketing.server.global.security.jwt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.ticketing.server.global.factory.YamlPropertySourceFactory;
|
||||
import com.ticketing.server.user.application.response.TokenDto;
|
||||
import com.ticketing.server.user.service.dto.TokenDTO;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -38,27 +38,27 @@ class TokenProviderTest {
|
||||
@DisplayName("토큰 생성 성공")
|
||||
void createTokenSuccess() {
|
||||
// given
|
||||
SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(UserGrade.GUEST.name());
|
||||
SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(UserGrade.USER.name());
|
||||
UsernamePasswordAuthenticationToken authenticationToken =
|
||||
new UsernamePasswordAuthenticationToken("ticketing@gmail.com", "123456", Collections.singleton(grantedAuthority));
|
||||
|
||||
// when
|
||||
TokenDto tokenDto = jwtProvider.generateTokenDto(authenticationToken);
|
||||
TokenDTO tokenDto = jwtProvider.generateTokenDto(authenticationToken);
|
||||
|
||||
// then
|
||||
assertThat(tokenDto).isInstanceOf(TokenDto.class);
|
||||
assertThat(tokenDto).isInstanceOf(TokenDTO.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("토큰 복호화 성공")
|
||||
void getAuthentication() {
|
||||
// given
|
||||
SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(UserGrade.GUEST.name());
|
||||
SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(UserGrade.USER.name());
|
||||
UsernamePasswordAuthenticationToken authenticationToken =
|
||||
new UsernamePasswordAuthenticationToken("ticketing@gmail.com", "123456", Collections.singleton(grantedAuthority));
|
||||
|
||||
// when
|
||||
TokenDto tokenDto = jwtProvider.generateTokenDto(authenticationToken);
|
||||
TokenDTO tokenDto = jwtProvider.generateTokenDto(authenticationToken);
|
||||
Authentication authentication = jwtProvider.getAuthentication(tokenDto.getAccessToken());
|
||||
|
||||
// then
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.ticketing.server.movie.domain;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class MovieTest {
|
||||
|
||||
public static final List<Movie> MOVIES;
|
||||
|
||||
static {
|
||||
MOVIES = Arrays.asList(
|
||||
new Movie(1L, "탑건: 매버릭", 130L),
|
||||
new Movie(2L, "헤어질 결심", 138L),
|
||||
new Movie(3L, "마녀2", 137L),
|
||||
new Movie(4L, "범죄도시2", 106L),
|
||||
new Movie(5L, "버즈 라이트이어", 105L)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,49 @@
|
||||
package com.ticketing.server.movie.domain;
|
||||
|
||||
import static com.ticketing.server.movie.domain.MovieTest.MOVIES;
|
||||
import static com.ticketing.server.movie.domain.TheaterTest.THEATERS;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
class MovieTimeTest {
|
||||
|
||||
public static final List<MovieTime> MOVIE_TIMES;
|
||||
|
||||
static {
|
||||
MOVIE_TIMES = new ArrayList<>();
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<LocalDateTime> startAts = Arrays.asList(
|
||||
LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 8, 0),
|
||||
LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 10, 0),
|
||||
LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 12, 0),
|
||||
LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 14, 0),
|
||||
LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 16, 0),
|
||||
LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 18, 0),
|
||||
LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 21, 0),
|
||||
LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 23, 0)
|
||||
);
|
||||
|
||||
Long idx = 1L;
|
||||
for (Theater theater : THEATERS) {
|
||||
MOVIE_TIMES.add(new MovieTime(idx++, MOVIES.get(0), theater, 1, startAts.get(0)));
|
||||
MOVIE_TIMES.add(new MovieTime(idx++, MOVIES.get(0), theater, 3, startAts.get(1)));
|
||||
MOVIE_TIMES.add(new MovieTime(idx++, MOVIES.get(1), theater, 2, startAts.get(2)));
|
||||
MOVIE_TIMES.add(new MovieTime(idx++, MOVIES.get(2), theater, 4, startAts.get(3)));
|
||||
MOVIE_TIMES.add(new MovieTime(idx++, MOVIES.get(0), theater, 5, startAts.get(4)));
|
||||
MOVIE_TIMES.add(new MovieTime(idx++, MOVIES.get(3), theater, 6, startAts.get(5)));
|
||||
MOVIE_TIMES.add(new MovieTime(idx++, MOVIES.get(0), theater, 7, startAts.get(6)));
|
||||
MOVIE_TIMES.add(new MovieTime(idx++, MOVIES.get(4), theater, 8, startAts.get(7)));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@DisplayName("영화상영시간 생성")
|
||||
@ValueSource(longs = {130L, 140L, 30L})
|
||||
@@ -19,7 +54,7 @@ class MovieTimeTest {
|
||||
LocalDateTime startAt = LocalDateTime.of(2022, 7, 4, 8, 10);
|
||||
|
||||
// when
|
||||
MovieTime movieTime = MovieTime.of(movie, theater, 1, startAt);
|
||||
MovieTime movieTime = new MovieTime(movie, theater, 1, startAt);
|
||||
|
||||
// then
|
||||
assertThat(movieTime.getEndAt()).isEqualTo(startAt.plusMinutes(runningTime));
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ticketing.server.movie.domain;
|
||||
|
||||
import static com.ticketing.server.movie.domain.TheaterTest.THEATERS;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class SeatTest {
|
||||
|
||||
public static final Map<Theater, List<Seat>> SEATS_BY_THEATER = new HashMap<>();
|
||||
|
||||
static {
|
||||
Long idx = 1L;
|
||||
for (Theater theater : THEATERS) {
|
||||
List<Seat> seats = new ArrayList<>();
|
||||
for (int col = 1; col <= 2; col++) {
|
||||
for (int row = 1; row <= 10; row++) {
|
||||
seats.add(new Seat(idx++, col, row, theater));
|
||||
}
|
||||
}
|
||||
SEATS_BY_THEATER.put(theater, seats);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ticketing.server.movie.domain;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class TheaterTest {
|
||||
|
||||
public static final List<Theater> THEATERS;
|
||||
|
||||
static {
|
||||
THEATERS = Arrays.asList(
|
||||
new Theater(1L, 1),
|
||||
new Theater(2L, 2),
|
||||
new Theater(3L, 3),
|
||||
new Theater(4L, 4)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.ticketing.server.movie.domain;
|
||||
|
||||
import static com.ticketing.server.movie.domain.MovieTimeTest.MOVIE_TIMES;
|
||||
import static com.ticketing.server.movie.domain.SeatTest.SEATS_BY_THEATER;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.global.exception.TicketingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TicketTest {
|
||||
|
||||
List<Ticket> tickets;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
tickets = setupTickets();
|
||||
}
|
||||
|
||||
public static List<Ticket> setupTickets() {
|
||||
List<Ticket> tickets = new ArrayList<>();
|
||||
Integer ticketPrice = 15_000;
|
||||
|
||||
Long id = 1L;
|
||||
for (MovieTime movieTime : MOVIE_TIMES) {
|
||||
List<Seat> seats = SEATS_BY_THEATER.get(movieTime.getTheater());
|
||||
for (Seat seat : seats) {
|
||||
tickets.add(new Ticket(id++, seat, movieTime, ticketPrice));
|
||||
}
|
||||
}
|
||||
return tickets;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("티켓에 결제 ID 등록 성공")
|
||||
void registerPaymentSuccess() {
|
||||
// given
|
||||
Ticket ticket = tickets.get(0);
|
||||
|
||||
// when
|
||||
ticket.registerPayment(1L);
|
||||
|
||||
// then
|
||||
assertThat(ticket.getPaymentId()).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("티켓에 결제 ID 등록 실패 - 이미 등록된 경우")
|
||||
void registerPaymentFail_Duplicate() {
|
||||
// given
|
||||
Ticket ticket = tickets.get(0);
|
||||
|
||||
// when
|
||||
ticket.registerPayment(1L);
|
||||
|
||||
// then
|
||||
assertThatThrownBy(() -> ticket.registerPayment(1L))
|
||||
.isInstanceOf(TicketingException.class)
|
||||
.extracting("errorCode")
|
||||
.isEqualTo(ErrorCode.DUPLICATE_PAYMENT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class MovieTimeServiceImplTest {
|
||||
// given
|
||||
Movie movie = new Movie(title, 106L);
|
||||
Theater theater = new Theater(1);
|
||||
MovieTime movieTime = MovieTime.of(movie, theater, 1,
|
||||
MovieTime movieTime = new MovieTime(movie, theater, 1,
|
||||
LocalDateTime.of(2022, 7, 1, 17, 0, 0)
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
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.junit.jupiter.api.Assertions.assertAll;
|
||||
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.TicketDetailsDTO;
|
||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
||||
import java.util.Collections;
|
||||
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 TicketServiceImplTest {
|
||||
|
||||
@Mock
|
||||
TicketRepository ticketRepository;
|
||||
|
||||
@InjectMocks
|
||||
TicketServiceImpl ticketService;
|
||||
|
||||
@Test
|
||||
@DisplayName("paymentId 로 Ticket 목록 조회 실패 - paymentId 가 없는 경우")
|
||||
void findTicketsByPaymentIdFail() {
|
||||
// given
|
||||
when(ticketRepository.findTicketFetchJoinByPaymentId(1L)).thenReturn(Collections.emptyList());
|
||||
|
||||
// when
|
||||
// then
|
||||
assertThatThrownBy(() -> ticketService.findTicketsByPaymentId(1L))
|
||||
.isInstanceOf(TicketingException.class)
|
||||
.extracting("errorCode")
|
||||
.isEqualTo(ErrorCode.PAYMENT_ID_NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("paymentId 로 Ticket 목록 조회 성공")
|
||||
void findTicketsByPaymentIdSuccess() {
|
||||
// given
|
||||
List<Ticket> tickets = setupTickets();
|
||||
when(ticketRepository.findTicketFetchJoinByPaymentId(1L)).thenReturn(List.of(tickets.get(0)));
|
||||
|
||||
// when
|
||||
TicketDetailsDTO ticketDetailDto = ticketService.findTicketsByPaymentId(1L);
|
||||
List<TicketDetailDTO> ticketDetails = ticketDetailDto.getTicketDetails();
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
() -> assertThat(ticketDetails).hasSize(1),
|
||||
() -> assertThat(ticketDetails.get(0).getPrice()).isEqualTo(15_000)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.ticketing.server.payment.domain;
|
||||
|
||||
public class PaymentTest {
|
||||
|
||||
public static final Payment PAYMENT_USER_1
|
||||
= new Payment(1L, 111L, "탑건: 매버릭", PaymentType.KAKAO_PAY, PaymentStatus.COMPLETED, "2022-0710-4142", 30_000);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.ticketing.server.payment.service;
|
||||
|
||||
import static com.ticketing.server.movie.domain.TicketTest.setupTickets;
|
||||
import static com.ticketing.server.payment.domain.PaymentTest.PAYMENT_USER_1;
|
||||
import static com.ticketing.server.user.domain.UserTest.provideCorrectUsers;
|
||||
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.when;
|
||||
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.global.exception.TicketingException;
|
||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||
import com.ticketing.server.movie.domain.Ticket;
|
||||
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.application.response.PaymentDetailResponse;
|
||||
import com.ticketing.server.payment.service.dto.PaymentDetailDTO;
|
||||
import com.ticketing.server.payment.service.dto.TicketDetailDTO;
|
||||
import com.ticketing.server.payment.domain.repository.PaymentRepository;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.service.dto.UserDetailDTO;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
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 PaymentApisServiceImplTest {
|
||||
|
||||
private Map<String, User> users;
|
||||
private List<Ticket> tickets;
|
||||
|
||||
@Mock
|
||||
UserClient userClient;
|
||||
|
||||
@Mock
|
||||
MovieClient movieClient;
|
||||
|
||||
@Mock
|
||||
PaymentRepository paymentRepository;
|
||||
|
||||
|
||||
@InjectMocks
|
||||
PaymentApisServiceImpl paymentApisService;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
users = provideCorrectUsers().collect(Collectors.toMap(User::getEmail, user -> user));
|
||||
tickets = setupTickets();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("상세 결제정보 조회 실패 - paymentId 가 존재하지 않을 경우")
|
||||
void findPaymentDetailNotPaymentIdFail() {
|
||||
// given
|
||||
when(paymentRepository.findById(1L)).thenReturn(Optional.empty());
|
||||
|
||||
// when
|
||||
// then
|
||||
assertThatThrownBy(() -> paymentApisService.findPaymentDetail(1L))
|
||||
.isInstanceOf(TicketingException.class)
|
||||
.extracting("errorCode")
|
||||
.isEqualTo(ErrorCode.PAYMENT_ID_NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("상세 결제정보 조회 실패 - 결제UserId와 JWT 로그인 userId 불일치")
|
||||
void findPaymentDetailUserIdFail() {
|
||||
// given
|
||||
when(paymentRepository.findById(1L)).thenReturn(Optional.of(PAYMENT_USER_1));
|
||||
|
||||
UserDetailDTO userDetail = new UserDetailDTO(users.get("ticketing2@gmail.com"));
|
||||
when(userClient.detail()).thenReturn(new UserDetailResponse(userDetail));
|
||||
|
||||
// when
|
||||
// then
|
||||
assertThatThrownBy(() -> paymentApisService.findPaymentDetail(1L))
|
||||
.isInstanceOf(TicketingException.class)
|
||||
.extracting("errorCode")
|
||||
.isEqualTo(ErrorCode.VALID_USER_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("상세 결제정보 조회 성공")
|
||||
void findPaymentDetailSuccess() {
|
||||
// given
|
||||
UserDetailDTO userDetail = new UserDetailDTO(users.get("ticketing1@gmail.com"));
|
||||
TicketDetailsResponse response = new TicketDetailsResponse(Arrays.asList(
|
||||
new TicketDetailDTO(tickets.get(0)),
|
||||
new TicketDetailDTO(tickets.get(1))
|
||||
));
|
||||
|
||||
when(paymentRepository.findById(1L)).thenReturn(Optional.of(PAYMENT_USER_1));
|
||||
when(userClient.detail()).thenReturn(new UserDetailResponse(userDetail));
|
||||
when(movieClient.getTicketsByPaymentId(1L)).thenReturn(response);
|
||||
|
||||
// when
|
||||
PaymentDetailDTO paymentDetail = paymentApisService.findPaymentDetail(1L);
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
() -> assertThat(paymentDetail.getPaymentId()).isEqualTo(1L),
|
||||
() -> assertThat(paymentDetail.getMovieTitle()).isEqualTo("탑건: 매버릭"),
|
||||
() -> assertThat(paymentDetail.getPaymentNumber()).isEqualTo("2022-0710-4142"),
|
||||
() -> assertThat(paymentDetail.getTotalPrice()).isEqualTo(30_000),
|
||||
() -> assertThat(paymentDetail.getTickets()).hasSize(2)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,13 +3,12 @@ package com.ticketing.server.payment.service;
|
||||
import static com.ticketing.server.payment.domain.PaymentStatus.COMPLETED;
|
||||
import static com.ticketing.server.payment.domain.PaymentType.KAKAO_PAY;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.ticketing.server.payment.domain.Payment;
|
||||
import com.ticketing.server.payment.domain.repository.PaymentRepository;
|
||||
import com.ticketing.server.payment.service.dto.CreatePaymentDto;
|
||||
import com.ticketing.server.user.api.dto.response.SimplePaymentsResponse;
|
||||
import com.ticketing.server.payment.service.dto.CreatePaymentDTO;
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentsDTO;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -28,44 +27,39 @@ class PaymentServiceImplTest {
|
||||
@Mock
|
||||
PaymentRepository paymentRepository;
|
||||
|
||||
|
||||
@InjectMocks
|
||||
PaymentServiceImpl paymentService;
|
||||
|
||||
@Test
|
||||
@DisplayName("유저 ID로 결제내역이 없을 경우")
|
||||
@DisplayName("유저 대체키로 결제내역이 없을 경우")
|
||||
void findSimplePaymentsZero() {
|
||||
// given
|
||||
when(paymentRepository.findByUserId(2L)).thenReturn(Collections.emptyList());
|
||||
when(paymentRepository.findByUserAlternateId(2L)).thenReturn(Collections.emptyList());
|
||||
|
||||
// when
|
||||
SimplePaymentsResponse simplePayments = paymentService.findSimplePayments(2L);
|
||||
SimplePaymentsDTO simplePayments = paymentService.findSimplePayments(2L);
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
() -> assertThat(simplePayments.getUserId()).isEqualTo(2L)
|
||||
, () -> assertThat(simplePayments.getPayments()).isEmpty()
|
||||
);
|
||||
assertThat(simplePayments.getPayments()).isEmpty();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@DisplayName("유저 ID로 간소 결제내역 조회 성공")
|
||||
@DisplayName("유저 대체키로 간소 결제내역 조회 성공")
|
||||
@ValueSource(longs = {1L, 2L, 100L, 154L})
|
||||
void findSimplePaymentsSuccess(Long userId) {
|
||||
void findSimplePaymentsSuccess(Long userAlternateId) {
|
||||
// given
|
||||
List<Payment> payments = Arrays.asList(
|
||||
Payment.from(CreatePaymentDto.of(userId, "범죄도시2", KAKAO_PAY, COMPLETED, "004-323-77542", 15_000)),
|
||||
Payment.from(CreatePaymentDto.of(userId, "토르", KAKAO_PAY, COMPLETED, "004-323-77544", 30_000))
|
||||
new CreatePaymentDTO(userAlternateId, "범죄도시2", KAKAO_PAY, COMPLETED, "004-323-77542", 15_000).toEntity(),
|
||||
new CreatePaymentDTO(userAlternateId, "토르", KAKAO_PAY, COMPLETED, "004-323-77544", 30_000).toEntity()
|
||||
);
|
||||
when(paymentRepository.findByUserId(userId)).thenReturn(payments);
|
||||
when(paymentRepository.findByUserAlternateId(userAlternateId)).thenReturn(payments);
|
||||
|
||||
// when
|
||||
SimplePaymentsResponse simplePayments = paymentService.findSimplePayments(userId);
|
||||
SimplePaymentsDTO simplePayments = paymentService.findSimplePayments(userAlternateId);
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
() -> assertThat(simplePayments.getUserId()).isEqualTo(userId)
|
||||
, () -> assertThat(simplePayments.getPayments()).hasSize(2)
|
||||
);
|
||||
assertThat(simplePayments.getPayments()).hasSize(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.ticketing.server.user.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SnowflakeTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("비트 계산이 정상적으로 처리되었는지 확인")
|
||||
void nextId_shouldGenerateIdWithCorrectBitsFilled() {
|
||||
// given
|
||||
int nodeId = 784;
|
||||
int sequence = 0;
|
||||
Snowflake snowflake = new Snowflake();
|
||||
long beforeTimestamp = Instant.now().toEpochMilli();
|
||||
|
||||
// when
|
||||
long id = snowflake.generateId();
|
||||
|
||||
// then
|
||||
long[] attrs = snowflake.parse(id);
|
||||
assertAll(
|
||||
() -> assertThat(attrs[0] >= beforeTimestamp).isTrue(),
|
||||
() -> assertThat(sequence).isEqualTo(attrs[2])
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("50_000 번 돌렸을 시 유니크 ID 인지 확인")
|
||||
void nextId_shouldGenerateUniqueId() {
|
||||
// given
|
||||
Set<Long> ids = new HashSet<>();
|
||||
Snowflake snowflake = new Snowflake();
|
||||
int iterations = 50_000;
|
||||
|
||||
// when
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
ids.add(snowflake.generateId());
|
||||
}
|
||||
|
||||
// then
|
||||
assertThat(ids).hasSize(iterations);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("멀티스레드 환경 유니크 ID 테스트")
|
||||
void nextId_shouldGenerateUniqueIdIfCalledFromMultipleThreads() throws InterruptedException, ExecutionException {
|
||||
// given
|
||||
int numThreads = 50;
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
|
||||
CountDownLatch latch = new CountDownLatch(numThreads);
|
||||
|
||||
Snowflake snowflake = new Snowflake();
|
||||
int iterations = 10_000;
|
||||
|
||||
// when
|
||||
Future<Long>[] futures = new Future[iterations];
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
futures[i] = executorService.submit(() -> {
|
||||
long id = snowflake.generateId();
|
||||
latch.countDown();
|
||||
return id;
|
||||
});
|
||||
}
|
||||
|
||||
// then
|
||||
latch.await();
|
||||
|
||||
Set<Future<Long>> set = Arrays.stream(futures)
|
||||
.collect(Collectors.toSet());
|
||||
assertThat(set).hasSize(iterations);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,10 +4,11 @@ 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 com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.global.exception.TicketingException;
|
||||
import com.ticketing.server.user.service.dto.ChangePasswordDTO;
|
||||
import com.ticketing.server.user.service.dto.DeleteUserDTO;
|
||||
import com.ticketing.server.user.service.dto.DeleteUserDtoTest;
|
||||
import com.ticketing.server.user.service.dto.DeleteUserDTOTest;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -22,7 +23,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
class UserTest {
|
||||
public class UserTest {
|
||||
|
||||
private Validator validator;
|
||||
private Map<String, User> users;
|
||||
@@ -34,6 +35,37 @@ class UserTest {
|
||||
users = provideCorrectUsers().collect(Collectors.toMap(User::getEmail, user -> user));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("동일한 권한으로 변경 시 예외처리")
|
||||
void changeGradeFail() {
|
||||
// given
|
||||
User user = users.get("ticketing1@gmail.com");
|
||||
|
||||
// when
|
||||
// then
|
||||
assertThatThrownBy(() -> user.changeGrade(UserGrade.USER))
|
||||
.isInstanceOf(TicketingException.class)
|
||||
.extracting("errorCode")
|
||||
.isEqualTo(ErrorCode.UNABLE_CHANGE_GRADE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("권한 변경 성공")
|
||||
void changeGradeSuccess() {
|
||||
// given
|
||||
User user = users.get("ticketing1@gmail.com");
|
||||
|
||||
// when
|
||||
ChangeGradeDTO changeGradeDto = user.changeGrade(UserGrade.ADMIN);
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
() -> assertThat(changeGradeDto.getEmail()).isEqualTo("ticketing1@gmail.com"),
|
||||
() -> assertThat(changeGradeDto.getBeforeGrade()).isEqualTo(UserGrade.USER),
|
||||
() -> assertThat(changeGradeDto.getAfterGrade()).isEqualTo(UserGrade.ADMIN)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideDifferentPasswordDeleteUsers")
|
||||
@DisplayName("입력된 패스워드가 다를 경우")
|
||||
@@ -74,17 +106,14 @@ class UserTest {
|
||||
User deletedUser = user.delete(deleteUserDto);
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
() -> assertThat(deletedUser.getDeletedAt()).isNotNull()
|
||||
, () -> assertThat(deletedUser.isDeleted()).isTrue()
|
||||
);
|
||||
assertThat(deletedUser.getDeletedAt()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("입력받은 패스워드와 불일치로 변경 실패")
|
||||
void changePasswordFail() {
|
||||
// given
|
||||
ChangePasswordDTO changePasswordDto = new ChangePasswordDTO("ticketing1@gmail.com", "1234567", "ticketing1234", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER);
|
||||
ChangePasswordDTO changePasswordDto = new ChangePasswordDTO("ticketing1@gmail.com", "1234567", "ticketing1234", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER);
|
||||
User user = users.get(changePasswordDto.getEmail());
|
||||
|
||||
// when
|
||||
@@ -97,7 +126,7 @@ class UserTest {
|
||||
@DisplayName("패스워드 변경 성공")
|
||||
void changePasswordSuccess() {
|
||||
// given
|
||||
ChangePasswordDTO changePasswordDto = new ChangePasswordDTO("ticketing1@gmail.com", "123456", "ticketing1234", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER);
|
||||
ChangePasswordDTO changePasswordDto = new ChangePasswordDTO("ticketing1@gmail.com", "123456", "ticketing1234", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER);
|
||||
User user = users.get(changePasswordDto.getEmail());
|
||||
String oldPassword = user.getPassword();
|
||||
|
||||
@@ -172,7 +201,20 @@ class UserTest {
|
||||
@DisplayName("grade null 검증")
|
||||
void gradeNull() {
|
||||
// given
|
||||
User user = new User("유저1", "email@gmail.com", "testPassword01", null, "010-1234-5678");
|
||||
User user = new User(111L, "유저1", "email@gmail.com", "testPassword01", null, "010-1234-5678");
|
||||
|
||||
// when
|
||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||
|
||||
// then
|
||||
assertThat(constraintViolations).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("alternateId null 검증")
|
||||
void alternateIdNull() {
|
||||
// given
|
||||
User user = new User(null, "유저1", "email@gmail.com", "testPassword01", UserGrade.USER, "010-1234-5678");
|
||||
|
||||
// when
|
||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||
@@ -207,73 +249,73 @@ class UserTest {
|
||||
|
||||
public static Stream<User> provideCorrectUsers() {
|
||||
return Stream.of(
|
||||
new User("유저1", "ticketing1@gmail.com", "123456", UserGrade.GUEST, "010-1234-5678")
|
||||
, new User("유저2", "ticketing2@gmail.com", "qwe123", UserGrade.GUEST, "010-2234-5678")
|
||||
, new User("유저3", "ticketing3@gmail.com", "ticketing", UserGrade.STAFF, "010-3234-5678")
|
||||
, new User("유저4", "ticketing4@gmail.com", "ticketing123456", UserGrade.STAFF, "010-4234-5678")
|
||||
new User(1L, 111L, "유저1", "ticketing1@gmail.com", "123456", UserGrade.USER, "010-1234-5678")
|
||||
, new User(2L, 222L, "유저2", "ticketing2@gmail.com", "qwe123", UserGrade.USER, "010-2234-5678")
|
||||
, new User(3L, 333L, "유저3", "ticketing3@gmail.com", "ticketing", UserGrade.STAFF, "010-3234-5678")
|
||||
, new User(4L, 444L, "유저4", "ticketing4@gmail.com", "ticketing123456", UserGrade.STAFF, "010-4234-5678")
|
||||
);
|
||||
}
|
||||
|
||||
public static Stream<User> provideNullOrEmptyOfName() {
|
||||
return Stream.of(
|
||||
new User(null, "ticketing1@gmail.com", "123456", UserGrade.GUEST, "010-1234-5678")
|
||||
, new User("", "ticketing2@gmail.com", "qwe123", UserGrade.GUEST, "010-2234-5678")
|
||||
new User(111L, null, "ticketing1@gmail.com", "123456", UserGrade.USER, "010-1234-5678")
|
||||
, new User(111L, "", "ticketing2@gmail.com", "qwe123", UserGrade.USER, "010-2234-5678")
|
||||
);
|
||||
}
|
||||
|
||||
public static Stream<User> provideNullOrEmptyOfEmail() {
|
||||
return Stream.of(
|
||||
new User("유저1", null, "123456", UserGrade.GUEST, "010-1234-5678")
|
||||
, new User("유저2", "", "qwe123", UserGrade.GUEST, "010-2234-5678")
|
||||
new User(111L, "유저1", null, "123456", UserGrade.USER, "010-1234-5678")
|
||||
, new User(111L, "유저2", "", "qwe123", UserGrade.USER, "010-2234-5678")
|
||||
);
|
||||
}
|
||||
|
||||
public static Stream<User> provideValidationFailedOfEmail() {
|
||||
return Stream.of(
|
||||
new User("유저1", "email", "123456", UserGrade.GUEST, "010-1234-5678")
|
||||
, new User("유저2", "@gmail.com", "qwe123", UserGrade.GUEST, "010-2234-5678")
|
||||
, new User("유저3", "12Bye#domain.com", "ticketing", UserGrade.STAFF, "010-3234-5678")
|
||||
new User(111L, "유저1", "email", "123456", UserGrade.USER, "010-1234-5678")
|
||||
, new User(111L, "유저2", "@gmail.com", "qwe123", UserGrade.USER, "010-2234-5678")
|
||||
, new User(111L, "유저3", "12Bye#domain.com", "ticketing", UserGrade.STAFF, "010-3234-5678")
|
||||
);
|
||||
}
|
||||
|
||||
public static Stream<User> provideNullOrEmptyOfPassword() {
|
||||
return Stream.of(
|
||||
new User("유저1", "ticketing1@gmail.com", null, UserGrade.GUEST, "010-1234-5678")
|
||||
, new User("유저2", "ticketing2@gmail.com", "", UserGrade.GUEST, "010-2234-5678")
|
||||
new User(111L, "유저1", "ticketing1@gmail.com", null, UserGrade.USER, "010-1234-5678")
|
||||
, new User(111L, "유저2", "ticketing2@gmail.com", "", UserGrade.USER, "010-2234-5678")
|
||||
);
|
||||
}
|
||||
|
||||
public static Stream<User> provideNullOrEmptyOfPhone() {
|
||||
return Stream.of(
|
||||
new User("유저1", "ticketing1@gmail.com", "123456", UserGrade.GUEST, null)
|
||||
, new User("유저2", "ticketing2@gmail.com", "qwe123", UserGrade.GUEST, "")
|
||||
new User(111L, "유저1", "ticketing1@gmail.com", "123456", UserGrade.USER, null)
|
||||
, new User(111L, "유저2", "ticketing2@gmail.com", "qwe123", UserGrade.USER, "")
|
||||
);
|
||||
}
|
||||
|
||||
public static Stream<User> provideValidationFailedOfPhone() {
|
||||
return Stream.of(
|
||||
new User("유저1", "ticketing1@gmail.com", "123456", UserGrade.GUEST, "010-123-1234")
|
||||
, new User("유저2", "ticketing2@gmail.com", "qwe123", UserGrade.GUEST, "02-0444-4044")
|
||||
, new User("유저3", "ticketing3@gmail.com", "ticketing", UserGrade.STAFF, "033-7953")
|
||||
, new User("유저4", "ticketing4@gmail.com", "ticketing123456", UserGrade.STAFF, "033-0455-504")
|
||||
new User(111L, "유저1", "ticketing1@gmail.com", "123456", UserGrade.USER, "010-123-1234")
|
||||
, new User(111L, "유저2", "ticketing2@gmail.com", "qwe123", UserGrade.USER, "02-0444-4044")
|
||||
, new User(111L, "유저3", "ticketing3@gmail.com", "ticketing", UserGrade.STAFF, "033-7953")
|
||||
, new User(111L, "유저4", "ticketing4@gmail.com", "ticketing123456", UserGrade.STAFF, "033-0455-504")
|
||||
);
|
||||
}
|
||||
|
||||
public static Stream<DeleteUserDTO> provideDifferentPasswordDeleteUsers() {
|
||||
return Stream.of(
|
||||
new DeleteUserDTO("ticketing1@gmail.com", "1234561", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing2@gmail.com", "qwe1231", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing3@gmail.com", "ticketing1", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing4@gmail.com", "ticketing1234561", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER)
|
||||
new DeleteUserDTO("ticketing1@gmail.com", "1234561", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing2@gmail.com", "qwe1231", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing3@gmail.com", "ticketing1", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing4@gmail.com", "ticketing1234561", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER)
|
||||
);
|
||||
}
|
||||
|
||||
public static Stream<DeleteUserDTO> provideDeleteUsers() {
|
||||
return Stream.of(
|
||||
new DeleteUserDTO("ticketing1@gmail.com", "123456", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing2@gmail.com", "qwe123", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing3@gmail.com", "ticketing", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing4@gmail.com", "ticketing123456", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER)
|
||||
new DeleteUserDTO("ticketing1@gmail.com", "123456", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing2@gmail.com", "qwe123", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing3@gmail.com", "ticketing", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER)
|
||||
, new DeleteUserDTO("ticketing4@gmail.com", "ticketing123456", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.ticketing.server.global.redis.RefreshRedisRepository;
|
||||
import com.ticketing.server.global.redis.RefreshToken;
|
||||
import com.ticketing.server.global.security.jwt.JwtProperties;
|
||||
import com.ticketing.server.global.security.jwt.JwtProvider;
|
||||
import com.ticketing.server.user.application.response.TokenDto;
|
||||
import com.ticketing.server.user.service.dto.TokenDTO;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
@@ -53,7 +53,7 @@ class AuthenticationServiceImplTest {
|
||||
@BeforeEach
|
||||
void init() {
|
||||
useJwtProvider = new JwtProvider(useJwtProperties);
|
||||
SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(UserGrade.GUEST.name());
|
||||
SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(UserGrade.USER.name());
|
||||
authenticationToken =
|
||||
new UsernamePasswordAuthenticationToken("ticketing@gmail.com", "123456", Collections.singleton(grantedAuthority));
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class AuthenticationServiceImplTest {
|
||||
when(jwtProperties.hasTokenStartsWith(refreshToken)).thenReturn(true);
|
||||
|
||||
// when
|
||||
TokenDto tokenDto = authenticationService.reissueTokenDto(refreshToken);
|
||||
TokenDTO tokenDto = authenticationService.reissueTokenDto(refreshToken);
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.ticketing.server.user.service;
|
||||
|
||||
import static com.ticketing.server.payment.domain.PaymentStatus.COMPLETED;
|
||||
import static com.ticketing.server.payment.domain.PaymentType.KAKAO_PAY;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.ticketing.server.payment.application.response.SimplePaymentsResponse;
|
||||
import com.ticketing.server.payment.service.dto.CreatePaymentDTO;
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentDTO;
|
||||
import com.ticketing.server.user.api.PaymentClient;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import com.ticketing.server.user.service.dto.PaymentsDTO;
|
||||
import com.ticketing.server.user.service.interfaces.UserService;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
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 UserApisServiceImplTest {
|
||||
|
||||
User user;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
user = new User(111L, "유저", "ticketing@gmail.com", "123456", UserGrade.USER, "010-1234-5678");
|
||||
}
|
||||
|
||||
@Mock
|
||||
UserService userService;
|
||||
|
||||
@Mock
|
||||
PaymentClient paymentClient;
|
||||
|
||||
@InjectMocks
|
||||
UserApisServiceImpl userApisService;
|
||||
|
||||
@Test
|
||||
@DisplayName("회원 결제 목록 조회 시 결제목록이 없을 경우")
|
||||
void findPaymentsByEmailSuccess_paymentEmpty() {
|
||||
// given
|
||||
when(userService.findNotDeletedUserByEmail("ticketing@gmail.com")).thenReturn(user);
|
||||
when(paymentClient.getPayments(any())).thenReturn(new SimplePaymentsResponse(1L, Collections.emptyList()));
|
||||
|
||||
// when
|
||||
PaymentsDTO paymentsDto = userApisService.findPaymentsByEmail("ticketing@gmail.com");
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
() -> assertThat(paymentsDto.getEmail()).isEqualTo("ticketing@gmail.com")
|
||||
, () -> assertThat(paymentsDto.getPayments()).isEmpty()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("회원 결제목록 조회")
|
||||
void findPaymentsByEmailSuccess() {
|
||||
// given
|
||||
List<SimplePaymentDTO> payments = Arrays.asList(
|
||||
new SimplePaymentDTO(
|
||||
new CreatePaymentDTO(1L, "범죄도시2", KAKAO_PAY, COMPLETED, "004-323-77542", 15_000).toEntity()),
|
||||
new SimplePaymentDTO(
|
||||
new CreatePaymentDTO(1L, "토르", KAKAO_PAY, COMPLETED, "004-323-77544", 30_000).toEntity())
|
||||
);
|
||||
|
||||
when(userService.findNotDeletedUserByEmail("ticketing@gmail.com")).thenReturn(user);
|
||||
when(paymentClient.getPayments(any())).thenReturn(new SimplePaymentsResponse(1L, payments));
|
||||
|
||||
// when
|
||||
PaymentsDTO patmentsDto = userApisService.findPaymentsByEmail("ticketing@gmail.com");
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
() -> assertThat(patmentsDto.getEmail()).isEqualTo("ticketing@gmail.com")
|
||||
, () -> assertThat(patmentsDto.getPayments()).hasSize(2)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +1,25 @@
|
||||
package com.ticketing.server.user.service;
|
||||
|
||||
import static com.ticketing.server.payment.domain.PaymentStatus.COMPLETED;
|
||||
import static com.ticketing.server.payment.domain.PaymentType.KAKAO_PAY;
|
||||
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.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.global.exception.TicketingException;
|
||||
import com.ticketing.server.payment.domain.Payment;
|
||||
import com.ticketing.server.payment.service.dto.CreatePaymentDto;
|
||||
import com.ticketing.server.payment.service.dto.SimplePaymentDto;
|
||||
import com.ticketing.server.user.api.PaymentClient;
|
||||
import com.ticketing.server.user.api.dto.request.SimplePaymentsRequest;
|
||||
import com.ticketing.server.user.api.dto.response.SimplePaymentsResponse;
|
||||
import com.ticketing.server.user.application.response.SimplePaymentDetailsResponse;
|
||||
import com.ticketing.server.user.domain.SequenceGenerator;
|
||||
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.ChangePasswordDTO;
|
||||
import com.ticketing.server.user.service.dto.ChangedPasswordUserDTO;
|
||||
import com.ticketing.server.user.service.dto.CreatedUserDTO;
|
||||
import com.ticketing.server.user.service.dto.DeleteUserDTO;
|
||||
import com.ticketing.server.user.service.dto.DeleteUserDtoTest;
|
||||
import com.ticketing.server.user.service.dto.DeleteUserDTOTest;
|
||||
import com.ticketing.server.user.service.dto.DeletedUserDTO;
|
||||
import com.ticketing.server.user.service.dto.SignUpDTO;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import com.ticketing.server.user.service.dto.UserDetailDTO;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
@@ -46,7 +41,7 @@ class UserServiceImplTest {
|
||||
UserRepository userRepository;
|
||||
|
||||
@Mock
|
||||
PaymentClient paymentClient;
|
||||
SequenceGenerator sequenceGenerator;
|
||||
|
||||
@InjectMocks
|
||||
UserServiceImpl userService;
|
||||
@@ -54,9 +49,9 @@ class UserServiceImplTest {
|
||||
@BeforeEach
|
||||
void init() {
|
||||
signUpDto = new SignUpDTO("유저", "ticketing@gmail.com", "123456", "010-1234-5678");
|
||||
user = new User("유저", "ticketing@gmail.com", "123456", UserGrade.GUEST, "010-1234-5678");
|
||||
deleteUserDto = new DeleteUserDTO("ticketing@gmail.com", "123456", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER);
|
||||
changePasswordDto = new ChangePasswordDTO("ticketing@gmail.com", "123456", "ticketing1234", DeleteUserDtoTest.CUSTOM_PASSWORD_ENCODER);
|
||||
user = new User(111L, "유저", "ticketing@gmail.com", "123456", UserGrade.USER, "010-1234-5678");
|
||||
deleteUserDto = new DeleteUserDTO("ticketing@gmail.com", "123456", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER);
|
||||
changePasswordDto = new ChangePasswordDTO("ticketing@gmail.com", "123456", "ticketing1234", DeleteUserDTOTest.CUSTOM_PASSWORD_ENCODER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,19 +72,20 @@ class UserServiceImplTest {
|
||||
// given
|
||||
when(userRepository.findByEmail("ticketing@gmail.com")).thenReturn(Optional.empty());
|
||||
when(userRepository.save(any())).thenReturn(user);
|
||||
when(sequenceGenerator.generateId()).thenReturn(123L);
|
||||
|
||||
// when
|
||||
User user = userService.register(signUpDto);
|
||||
CreatedUserDTO createdUserDto = userService.register(signUpDto);
|
||||
|
||||
// then
|
||||
assertThat(user).isNotNull();
|
||||
assertThat(createdUserDto).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("회원탈퇴 시 이메일이 존재하지 않을 경우")
|
||||
void deleteFail() {
|
||||
// given
|
||||
when(userRepository.findByEmailAndIsDeletedFalse("ticketing@gmail.com")).thenReturn(Optional.empty());
|
||||
when(userRepository.findByEmailAndDeletedAtNull("ticketing@gmail.com")).thenReturn(Optional.empty());
|
||||
|
||||
// when
|
||||
// then
|
||||
@@ -101,23 +97,20 @@ class UserServiceImplTest {
|
||||
@DisplayName("회원탈퇴 성공했을 경우")
|
||||
void deleteSuccess() {
|
||||
// given
|
||||
when(userRepository.findByEmailAndIsDeletedFalse("ticketing@gmail.com")).thenReturn(Optional.of(user));
|
||||
when(userRepository.findByEmailAndDeletedAtNull("ticketing@gmail.com")).thenReturn(Optional.of(user));
|
||||
|
||||
// when
|
||||
User user = userService.delete(deleteUserDto);
|
||||
DeletedUserDTO deletedUserDto = userService.delete(deleteUserDto);
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
() -> assertThat(user.isDeleted()).isTrue(),
|
||||
() -> assertThat(user.getDeletedAt()).isNotNull()
|
||||
);
|
||||
assertThat(deletedUserDto.getDeletedAt()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("패스워드 변경 시 이메일이 존재하지 않을 경우")
|
||||
void changePasswordFail() {
|
||||
// given
|
||||
when(userRepository.findByEmailAndIsDeletedFalse("ticketing@gmail.com")).thenReturn(Optional.empty());
|
||||
when(userRepository.findByEmailAndDeletedAtNull("ticketing@gmail.com")).thenReturn(Optional.empty());
|
||||
|
||||
// when
|
||||
// then
|
||||
@@ -129,39 +122,45 @@ class UserServiceImplTest {
|
||||
@DisplayName("패스워드 변경 성공했을 경우")
|
||||
void changePasswordSuccess() {
|
||||
// given
|
||||
when(userRepository.findByEmailAndIsDeletedFalse("ticketing@gmail.com")).thenReturn(Optional.of(user));
|
||||
when(userRepository.findByEmailAndDeletedAtNull("ticketing@gmail.com")).thenReturn(Optional.of(user));
|
||||
|
||||
// when
|
||||
User user = userService.changePassword(changePasswordDto);
|
||||
ChangedPasswordUserDTO changedUserDto = userService.changePassword(changePasswordDto);
|
||||
|
||||
// then
|
||||
assertThat(user).isNotNull();
|
||||
assertThat(changedUserDto).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("회원 결제목록 조회")
|
||||
void findSimplePaymentDetailsSuccess() {
|
||||
// given
|
||||
List<SimplePaymentDto> paymentDtos = Arrays.asList(
|
||||
SimplePaymentDto.from(
|
||||
Payment.from(
|
||||
CreatePaymentDto.of(1L, "범죄도시2", KAKAO_PAY, COMPLETED, "004-323-77542", 15_000))),
|
||||
SimplePaymentDto.from(
|
||||
Payment.from(
|
||||
CreatePaymentDto.of(1L, "토르", KAKAO_PAY, COMPLETED, "004-323-77544", 30_000)))
|
||||
);
|
||||
@DisplayName("email 로 유저 디테일 정보 가져오기 성공했을 경우")
|
||||
void findDetailByEmailSuccess() {
|
||||
// given
|
||||
when(userRepository.findByEmail("ticketing@gmail.com")).thenReturn(Optional.of(user));
|
||||
|
||||
when(userRepository.findByEmailAndIsDeletedFalse("ticketing@gmail.com")).thenReturn(Optional.of(user));
|
||||
when(paymentClient.getSimplePayments(any())).thenReturn(SimplePaymentsResponse.from(1L, paymentDtos));
|
||||
|
||||
// when
|
||||
SimplePaymentDetailsResponse paymentDetails = userService.findSimplePaymentDetails("ticketing@gmail.com");
|
||||
// when
|
||||
UserDetailDTO userDetail = userService.findDetailByEmail("ticketing@gmail.com");
|
||||
|
||||
// then
|
||||
assertAll(
|
||||
() -> assertThat(paymentDetails.getEmail()).isEqualTo("ticketing@gmail.com")
|
||||
, () -> assertThat(paymentDetails.getPayments()).hasSize(2)
|
||||
() -> assertThat(userDetail.getEmail()).isEqualTo("ticketing@gmail.com"),
|
||||
() -> assertThat(userDetail.getName()).isEqualTo("유저"),
|
||||
() -> assertThat(userDetail.getPhone()).isEqualTo("010-1234-5678"),
|
||||
() -> assertThat(userDetail.getGrade()).isEqualTo(UserGrade.USER)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("email 로 유저 디테일 정보 가져오기 실패했을 경우")
|
||||
void findDetailByEmailFail() {
|
||||
// given
|
||||
when(userRepository.findByEmail("ticketing@gmail.com")).thenReturn(Optional.empty());
|
||||
|
||||
// when
|
||||
// then
|
||||
assertThatThrownBy(() -> userService.findDetailByEmail("ticketing@gmail.com"))
|
||||
.isInstanceOf(TicketingException.class)
|
||||
.extracting("errorCode")
|
||||
.isEqualTo(ErrorCode.EMAIL_NOT_FOUND);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
public class DeleteUserDtoTest {
|
||||
public class DeleteUserDTOTest {
|
||||
|
||||
public static PasswordEncoder CUSTOM_PASSWORD_ENCODER = new CustomPasswordEncoder();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user