Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: api module 에서 presentation 관심사 제외 #177

Closed
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions module-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
dependencies {
implementation project(":module-domain")

implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.security:spring-security-crypto'
implementation 'org.springframework:spring-web'

implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'org.springframework.boot:spring-boot-starter-security'

implementation("io.springfox:springfox-swagger-ui:2.9.2")
implementation("io.springfox:springfox-swagger2:2.9.2")

implementation "com.amazonaws:aws-java-sdk-s3:${awsJavaSdkVersion}"

Expand Down
33 changes: 0 additions & 33 deletions module-api/src/main/java/inspiration/ResultResponse.java

This file was deleted.

47 changes: 16 additions & 31 deletions module-api/src/main/java/inspiration/auth/AuthService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package inspiration.auth;

import inspiration.ResultResponse;
import inspiration.auth.jwt.JwtProvider;
import inspiration.auth.request.LoginRequest;
import inspiration.auth.request.LoginRequestVo;
import inspiration.domain.member.Member;
import inspiration.domain.member.MemberRepository;
import inspiration.domain.member.response.MemberInfoResponse;
import inspiration.enumeration.ExceptionType;
import inspiration.enumeration.ExpireTimeConstants;
import inspiration.exception.PostNotFoundException;
Expand Down Expand Up @@ -33,22 +31,18 @@ public class AuthService {

private final String refreshTokenKey = "refreshToken : ";
private final String accessTokenKey = "accessToken : ";
private final String issueToken = "refreshToken : ";

@Transactional
public ResultResponse<TokenResponse> login(LoginRequest request) {

Member member = checkEmail(request.getEmail());
verifyPassword(request.getPassword(), member.getPassword());

TokenResponse tokenResponse = TokenResponse.builder()
.accessToken(resolveAccessToken(member.getId()))
.refreshToken(resolveRefreshToken(member.getId()))
.memberId(member.getId())
.accessTokenExpireDate(ExpireTimeConstants.accessTokenValidMillisecond)
.build();

return ResultResponse.of(issueToken, tokenResponse);
public TokenResponseVo login(LoginRequestVo loginRequestVo) {
Member member = checkEmail(loginRequestVo.getEmail());
verifyPassword(loginRequestVo.getPassword(), member.getPassword());

return TokenResponseVo.builder()
.accessToken(resolveAccessToken(member.getId()))
.refreshToken(resolveRefreshToken(member.getId()))
.accessTokenExpireDate(ExpireTimeConstants.accessTokenValidMillisecond)
.memberId(member.getId())
.build();
}

private Member checkEmail(String email) {
Expand Down Expand Up @@ -93,7 +87,7 @@ private void saveRefreshToken(Long memberId, String refreshToken) {
}

@Transactional
public ResultResponse reissue(String refreshToken) {
public TokenResponseVo reissue(String refreshToken) {
Long memberId = jwtProvider.resolveMemberId(refreshToken)
.orElseThrow(RefreshTokenException::new);
Member member = memberRepository.findById(memberId)
Expand All @@ -109,18 +103,9 @@ public ResultResponse reissue(String refreshToken) {
throw new RefreshTokenException(ExceptionType.VALID_NOT_REFRESH_TOKEN.getMessage());
}

TokenResponse newTokenResponse = jwtProvider.createTokenDto(member.getId());

saveRefreshToken(member.getId(), newTokenResponse.getRefreshToken());
saveAccessToken(member.getId(), newTokenResponse.getAccessToken());

return ResultResponse.of(issueToken, newTokenResponse);
}

@Transactional(readOnly = true)
public MemberInfoResponse getUserInfo(Long memberId) {
return memberRepository.findById(memberId)
.map(MemberInfoResponse::of)
.orElseThrow(() -> new PostNotFoundException(ExceptionType.USER_NOT_EXISTS.getMessage()));
TokenResponseVo newTokenResponseVo = jwtProvider.createTokenVo(member.getId());
saveRefreshToken(member.getId(), newTokenResponseVo.getRefreshToken());
saveAccessToken(member.getId(), newTokenResponseVo.getAccessToken());
return newTokenResponseVo;
}
}
16 changes: 16 additions & 0 deletions module-api/src/main/java/inspiration/auth/TokenResponseVo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package inspiration.auth;

import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@SuppressWarnings("ClassCanBeRecord")
public class TokenResponseVo {
private final String accessToken;
private final String refreshToken;
private final Long accessTokenExpireDate;
private final long memberId;
}
16 changes: 8 additions & 8 deletions module-api/src/main/java/inspiration/auth/jwt/JwtProvider.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package inspiration.auth.jwt;

import inspiration.auth.TokenResponse;
import inspiration.auth.TokenResponseVo;
import inspiration.enumeration.ExpireTimeConstants;
import io.jsonwebtoken.*;
import io.jsonwebtoken.impl.Base64UrlCodec;
Expand Down Expand Up @@ -65,13 +65,13 @@ private String createRefreshTokenInner(Long memberId) {
.compact();
}

public TokenResponse createTokenDto(Long memberId) {
return TokenResponse.builder()
.accessToken(createAccessTokenInner(memberId))
.refreshToken(createRefreshTokenInner(memberId))
.memberId(memberId)
.accessTokenExpireDate(ExpireTimeConstants.accessTokenValidMillisecond)
.build();
public TokenResponseVo createTokenVo(Long memberId) {
return TokenResponseVo.builder()
.accessToken(createAccessTokenInner(memberId))
.refreshToken(createRefreshTokenInner(memberId))
.accessTokenExpireDate(ExpireTimeConstants.accessTokenValidMillisecond)
.memberId(memberId)
.build();
}

public Optional<Long> resolveMemberId(String token) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package inspiration.auth.request;

import lombok.Value;

@Value
@SuppressWarnings("ClassCanBeRecord")
public class LoginRequestVo {
String email;
String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package inspiration.auth.request;

import lombok.Value;

@Value
@SuppressWarnings("ClassCanBeRecord")
public class TokenRequestVo {
String accessToken;
String refreshToken;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package inspiration.domain.emailauth;

import inspiration.ResultResponse;
import inspiration.domain.member.MemberRepository;
import inspiration.domain.passwordauth.PasswordAuth;
import inspiration.domain.passwordauth.PasswordAuthRepository;
import inspiration.enumeration.ExceptionType;
import inspiration.enumeration.ExpireTimeConstants;
import inspiration.enumeration.RedisKey;
import inspiration.exception.EmailAuthenticatedTimeExpiredException;
import inspiration.exception.PostNotFoundException;
import inspiration.domain.member.MemberRepository;
import inspiration.domain.passwordauth.PasswordAuth;
import inspiration.domain.passwordauth.PasswordAuthRepository;
import inspiration.redis.RedisService;
import inspiration.utils.AuthTokenUtil;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,6 +18,7 @@
@Slf4j
@RequiredArgsConstructor
@Service
@SuppressWarnings("ClassCanBeRecord")
public class EmailAuthService {

private final EmailAuthRepository emailAuthRepository;
Expand All @@ -33,7 +33,7 @@ public void signUpEmailSend(String email) {

verifyEmail(email);

if(email.contains("+")) {
if (email.contains("+")) {
throw new PostNotFoundException("잘못된 이메일 형식입니다.");
}

Expand All @@ -58,9 +58,9 @@ public void authenticateEmailOfSignUp(String email) {

emailAuthRepository.save(
EmailAuth.builder()
.email(email)
.isAuth(true)
.build());
.email(email)
.isAuth(true)
.build());
}

@Transactional
Expand All @@ -70,11 +70,11 @@ public void resetPasswordForAuthEmailSend(String email) {
throw new PostNotFoundException(ExceptionType.MEMBER_NOT_FOUND.getMessage());
}

if(passwordAuthRepository.existsByEmail(email)) {
if (passwordAuthRepository.existsByEmail(email)) {
throw new PostNotFoundException(ExceptionType.EMAIL_ALREADY_AUTHENTICATED.getMessage());
}

if(email.contains("+")) {
if (email.contains("+")) {
throw new PostNotFoundException("잘못된 이메일 형식입니다.");
}

Expand All @@ -98,29 +98,19 @@ public void authenticateEmailOfResetPasswordForAuth(String email) {

passwordAuthRepository.save(
PasswordAuth.builder()
.email(email)
.isAuth(true)
.build());
.email(email)
.isAuth(true)
.build());
}

@Transactional(readOnly = true)
public ResultResponse validAuthenticateEmailStatusOfSignup(String email) {

if (emailAuthRepository.existsByEmail(email)) {
return ResultResponse.of(ExceptionType.EMAIL_ALREADY_AUTHENTICATED.getMessage(), true);
}

return ResultResponse.of(ExceptionType.EMAIL_NOT_AUTHENTICATED.getMessage(), false);
public boolean validAuthenticateEmailStatusOfSignup(String email) {
return emailAuthRepository.existsByEmail(email);
}

@Transactional(readOnly = true)
public ResultResponse validAuthenticateEmailStatusOfResetPassword(String email) {

if (passwordAuthRepository.existsByEmail(email)) {
return ResultResponse.of(ExceptionType.EMAIL_ALREADY_AUTHENTICATED.getMessage(), true);
}

return ResultResponse.of(ExceptionType.EMAIL_NOT_AUTHENTICATED.getMessage(), false);
public boolean isValidAuthenticateEmailStatusOfResetPassword(String email) {
return passwordAuthRepository.existsByEmail(email);
}

private void verifyEmail(String email) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
@Service
@RequiredArgsConstructor
@Slf4j
@SuppressWarnings("ClassCanBeRecord")
public class ResetPasswordEmailSendService implements EmailSendService {
private static final String SUBJECT = "비빌번호 초기화";
private static final String CREATED_RESET_PASSWORD = "임시 비밀번호 발급: ";

private final JavaMailSender mailSender;
private final static String SUBJECT = "비빌번호 초기화";
private final static String CREATED_RESET_PASSWORD = "임시 비밀번호 발급: ";

@Override
public void send(String email, String restPassword) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
@Service
@RequiredArgsConstructor
@Slf4j
@SuppressWarnings("ClassCanBeRecord")
public class ResetPasswordForAuthSendService implements EmailSendService {
private static final String SUBJECT = "비밀번호 초기화를 위한 이메일 인증";
private static final String OPEN_HREF = "<a href=";
private static final String CLOSE_HREF = "></a>";

private final JavaMailSender mailSender;
private final MailProperties mailProperties;
private final static String SUBJECT = "비밀번호 초기화를 위한 이메일 인증";
private final static String OPEN_HREF = "<a href=";
private final static String CLOSE_HREF = "></a>";

@Override
public void send(String email, String authToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
@Service
@RequiredArgsConstructor
@Slf4j
@SuppressWarnings("ClassCanBeRecord")
public class SignUpEmailSendService implements EmailSendService {
private static final String SUBJECT = "이메일 인증";

private final JavaMailSender mailSender;
private final MailProperties mailProperties;
private final static String SUBJECT = "이메일 인증";

@Override
public void send(String email, String authToken) {
Expand Down
Loading