Skip to content

Commit

Permalink
Merge pull request #74 from KOA-TF/feat/auth
Browse files Browse the repository at this point in the history
refactor : API request 형식 수정, HTTP 메서드 수정, 로그아웃 로직 수정
  • Loading branch information
isprogrammingfun authored Feb 6, 2024
2 parents 18d596f + 76054db commit d5cc00c
Show file tree
Hide file tree
Showing 37 changed files with 262 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import com.koa.commonmodule.common.ApplicationResponse;
import com.koa.coremodule.auth.application.common.consts.AuthConsts;
import com.koa.coremodule.auth.application.dto.AuthResponse;
import com.koa.coremodule.auth.application.dto.LoginRequest;
import com.koa.coremodule.auth.application.service.AuthUseCase;
import com.koa.coremodule.auth.application.service.LogoutUseCase;
import com.koa.coremodule.member.domain.entity.Authority;
import com.koa.coremodule.fcm.application.service.AlarmUseCase;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;

@Slf4j
@RestController
Expand All @@ -20,11 +21,10 @@ public class AuthController {

private final AuthUseCase authUseCase;
private final LogoutUseCase logoutUseCase;
private final AlarmUseCase alarmUseCase;

@GetMapping("/login/{authority}")
public ApplicationResponse<AuthResponse> authLogin(@PathVariable Authority authority, @RequestParam String email, @RequestParam String password){
AuthResponse response = authUseCase.authLogin(authority, email, password);
public ApplicationResponse<AuthResponse> authLogin(@PathVariable Authority authority, @RequestBody LoginRequest loginRequest){
AuthResponse response = authUseCase.authLogin(authority, loginRequest);
return ApplicationResponse.ok(response);
}

Expand All @@ -37,10 +37,6 @@ public ApplicationResponse<AuthResponse> authReissue(@RequestHeader(AuthConsts.R
@DeleteMapping("/logout")
public ApplicationResponse<Void> logout(@RequestHeader(AuthConsts.REFRESH_TOKEN_HEADER) String refreshToken){
logoutUseCase.logoutAccessUser(refreshToken);

// 로그아웃 시 토큰 제거
alarmUseCase.deleteFcmToken();

return ApplicationResponse.ok(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.koa.apimodule.command.api;

import com.koa.commonmodule.common.ApplicationResponse;
import com.koa.coremodule.member.application.dto.response.VerifyCodeResponse;
import com.koa.coremodule.member.application.service.EmailVerificationUseCase;
import com.koa.coremodule.email.application.dto.request.VerifyCodeRequest;
import com.koa.coremodule.email.application.dto.request.VerifyEmailRequest;
import com.koa.coremodule.email.application.dto.response.VerifyCodeResponse;
import com.koa.coremodule.email.application.service.EmailVerificationUseCase;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
Expand All @@ -18,14 +21,14 @@ public class EmailController {
private final EmailVerificationUseCase emailVerificationUseCase;

@PostMapping("/verify")
public ApplicationResponse<Void> postVerifyEmail(@RequestParam String email) {
emailVerificationUseCase.sendVerificationEmail(email);
public ApplicationResponse<Void> postVerifyEmail(@RequestBody VerifyEmailRequest verifyEmailRequest) {
emailVerificationUseCase.sendVerificationEmail(verifyEmailRequest);
return ApplicationResponse.ok(null);
}

@PostMapping("/verify/code")
public ApplicationResponse<VerifyCodeResponse> verifyCode(@RequestParam String email, @RequestParam String code) {
VerifyCodeResponse response = emailVerificationUseCase.verifyCode(email, code);
@GetMapping("/verify/code")
public ApplicationResponse<VerifyCodeResponse> verifyCode(@RequestBody VerifyCodeRequest verifyCodeRequest) {
VerifyCodeResponse response = emailVerificationUseCase.verifyCode(verifyCodeRequest);
return ApplicationResponse.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.koa.apimodule.command.api;

import com.koa.commonmodule.common.ApplicationResponse;
import com.koa.coremodule.member.application.dto.request.CheckEmailRequest;
import com.koa.coremodule.member.application.dto.request.CheckPasswordRequest;
import com.koa.coremodule.member.application.dto.request.MemberPasswordChangeRequest;
import com.koa.coremodule.member.application.dto.request.MemberRegisterRequest;
import com.koa.coremodule.member.application.dto.response.CheckEmailResponse;
import com.koa.coremodule.member.application.dto.response.CheckPasswordResponse;
import com.koa.coremodule.member.application.dto.response.CheckRegisterResponse;
Expand All @@ -16,11 +19,9 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
Expand All @@ -41,21 +42,21 @@ public ApplicationResponse<MemberInfoResponse> getMemberInfo(){
return ApplicationResponse.ok(response);
}

@PostMapping("/check/register")
public ApplicationResponse<CheckRegisterResponse> checkMemberRegistered(@RequestParam String email, @RequestParam String password) {
CheckRegisterResponse response = memberCheckUseCase.checkMemberRegistered(email, password);
@GetMapping("/check/register")
public ApplicationResponse<CheckRegisterResponse> checkMemberRegistered(@RequestBody MemberRegisterRequest memberRegisterRequest) {
CheckRegisterResponse response = memberCheckUseCase.checkMemberRegistered(memberRegisterRequest);
return ApplicationResponse.ok(response);
}

@PostMapping("/register")
public ApplicationResponse<Void> postMemberDetail(@RequestParam String email, @RequestParam String password){
memberRegisterUseCase.registerMember(email, password);
@GetMapping("/register")
public ApplicationResponse<Void> getMemberRegister(@RequestBody MemberRegisterRequest memberRegisterRequest){
memberRegisterUseCase.registerMember(memberRegisterRequest);
return ApplicationResponse.ok(null);
}

@PostMapping("/email")
public ApplicationResponse<CheckEmailResponse> checkEmail(@RequestParam String email) {
CheckEmailResponse response = memberCheckUseCase.checkEmail(email);
@GetMapping("/email")
public ApplicationResponse<CheckEmailResponse> checkEmail(@RequestBody CheckEmailRequest checkEmailRequest) {
CheckEmailResponse response = memberCheckUseCase.checkEmail(checkEmailRequest);
return ApplicationResponse.ok(response);
}

Expand All @@ -65,9 +66,9 @@ public ApplicationResponse<Void> deleteMember(){
return ApplicationResponse.ok(null);
}

@PostMapping("/password")
public ApplicationResponse<CheckPasswordResponse> checkPassword(@RequestParam String password) {
CheckPasswordResponse response = memberCheckUseCase.checkPassword(password);
@GetMapping("/password")
public ApplicationResponse<CheckPasswordResponse> checkPassword(@RequestBody CheckPasswordRequest checkPasswordRequest) {
CheckPasswordResponse response = memberCheckUseCase.checkPassword(checkPasswordRequest);
return ApplicationResponse.ok(response);
}

Expand All @@ -78,8 +79,8 @@ public ApplicationResponse<Void> putPassword(@RequestBody MemberPasswordChangeRe
}

@PutMapping("/password/unauthenticated")
public ApplicationResponse<Void> putPasswordUnauthenticated(@RequestParam String email, @RequestBody MemberPasswordChangeRequest memberPasswordChangeRequest) {
memberPasswordChangeUseCase.changePasswordUnauthenticated(email, memberPasswordChangeRequest);
public ApplicationResponse<Void> putPasswordUnauthenticated(@RequestBody MemberPasswordChangeRequest memberPasswordChangeRequest) {
memberPasswordChangeUseCase.changePasswordUnauthenticated(memberPasswordChangeRequest);
return ApplicationResponse.ok(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ private static Map<String, Set<HttpMethod>> createIgnoredPathMap() {
Map<String, Set<HttpMethod>> map = new LinkedHashMap<>();

map.put("/v1/auth/reissue", Set.of(HttpMethod.GET));
map.put("/v1/member/register", Set.of(HttpMethod.POST));
map.put("/v1/member/check/register", Set.of(HttpMethod.POST));
map.put("/v1/member/register", Set.of(HttpMethod.GET));
map.put("/v1/member/check/register", Set.of(HttpMethod.GET));
map.put("/h2-console/**", Set.of(HttpMethod.GET, HttpMethod.POST));
map.put("/v1/auth/login/**", Set.of(HttpMethod.GET, HttpMethod.POST));
map.put("/v1/member/email", Set.of(HttpMethod.POST));
map.put("/v1/member/email", Set.of(HttpMethod.GET));
map.put("/v1/member/verify", Set.of(HttpMethod.POST));
map.put("/v1/member/verify/code", Set.of(HttpMethod.POST));
map.put("/v1/member/verify/code", Set.of(HttpMethod.GET));
map.put("/v1/member/password/unauthenticated", Set.of(HttpMethod.PUT));
map.put("/api-docs/**", Set.of(HttpMethod.GET, HttpMethod.POST));
map.put("/error", Set.of(HttpMethod.GET, HttpMethod.POST));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.koa.coremodule.auth.application.dto;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class LoginRequest {
private String email;
private String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.koa.coremodule.auth.application.handler;

import com.koa.coremodule.auth.application.handler.event.AlarmTokenDeleteEvent;
import com.koa.coremodule.fcm.domain.service.AlarmDeleteService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@RequiredArgsConstructor
@Transactional
public class AlarmTokenDeleteEventHandler {

private final AlarmDeleteService alarmDeleteService;

@EventListener
public void handle(AlarmTokenDeleteEvent event){
alarmDeleteService.deleteFcmToken(event.getMemberId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.koa.coremodule.auth.application.handler.event;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class AlarmTokenDeleteEvent {
private final Long memberId;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.koa.coremodule.auth.application.service;

import com.google.rpc.context.AttributeContext.Auth;
import com.koa.commonmodule.annotation.ApplicationService;
import com.koa.coremodule.auth.application.common.consts.AuthConsts;
import com.koa.coremodule.auth.application.dto.AuthRequest;
import com.koa.coremodule.auth.application.dto.AuthResponse;
import com.koa.coremodule.auth.application.dto.LoginRequest;
import com.koa.coremodule.auth.application.service.command.AuthInvoker;
import com.koa.coremodule.auth.application.utils.TokenExtractUtils;
import com.koa.coremodule.auth.domain.jwt.JWTProvider;
Expand All @@ -21,8 +23,8 @@ public class AuthUseCase {
private final AuthInvoker authInvoker;


public AuthResponse authLogin(Authority authority, String email, String password){
return authInvoker.execute(new AuthRequest(authority, email, password));
public AuthResponse authLogin(Authority authority, LoginRequest loginRequest){
return authInvoker.execute(new AuthRequest(authority, loginRequest.getEmail(), loginRequest.getPassword()));
}

public AuthResponse reissue(String refreshToken){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
package com.koa.coremodule.auth.application.service;

import com.koa.commonmodule.annotation.ApplicationService;
import com.koa.coremodule.auth.application.handler.event.AlarmTokenDeleteEvent;
import com.koa.coremodule.auth.application.utils.TokenExtractUtils;
import com.koa.coremodule.auth.domain.entity.Token;
import com.koa.coremodule.auth.domain.entity.TokenType;
import com.koa.coremodule.auth.domain.service.TokenDeleteService;
import com.koa.coremodule.auth.domain.service.TokenQueryService;
import com.koa.coremodule.member.domain.entity.Member;
import com.koa.coremodule.member.domain.utils.MemberUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.transaction.annotation.Transactional;

@ApplicationService
@RequiredArgsConstructor
@Transactional
public class LogoutUseCase {
private final TokenDeleteService tokenDeleteService;
private final TokenQueryService tokenQueryService;
private final ApplicationEventPublisher applicationEventPublisher;
private final MemberUtils memberUtils;

public void logoutAccessUser(String refreshTokenHeader) {
final Member member = memberUtils.getAccessMember();
final String refreshToken = TokenExtractUtils.extractToken(refreshTokenHeader);
final Token refreshTokenEntity = tokenQueryService.findTokenByTokenValue(refreshToken, TokenType.REFRESH_TOKEN);
tokenDeleteService.deleteToken(refreshTokenEntity);
applicationEventPublisher.publishEvent(new AlarmTokenDeleteEvent(member.getId()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import com.koa.coremodule.auth.domain.repository.TokenRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@DomainService
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class TokenQueryService {

private final TokenRepository tokenRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.koa.coremodule.auth.domain.entity.TokenType;
import com.koa.coremodule.auth.domain.repository.TokenRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@DomainService
@RequiredArgsConstructor
@Transactional
public class TokenSaveService {
private final TokenRepository tokenRepository;
public void saveToken( final String token, final String email, final TokenType tokenType){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

@ApplicationService
@RequiredArgsConstructor
@Transactional
public class CommentCreateUseCase {
private final MemberUtils memberUtils;
private final NoticeQueryService noticeQueryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import com.koa.coremodule.member.domain.utils.MemberUtils;
import lombok.RequiredArgsConstructor;
import com.koa.commonmodule.exception.Error;
import org.springframework.transaction.annotation.Transactional;

@ApplicationService
@RequiredArgsConstructor
@Transactional
public class CommentDeleteUseCase {

private final MemberUtils memberUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.koa.coremodule.comment.domain.entity.Comment;
import com.koa.coremodule.comment.domain.repository.CommentRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@DomainService
@RequiredArgsConstructor
@Transactional
public class CommentDeleteService {

private final CommentRepository commentRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.koa.coremodule.comment.domain.entity.Comment;
import com.koa.coremodule.comment.domain.repository.CommentRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@DomainService
@RequiredArgsConstructor
@Transactional
public class CommentSaveService {

private final CommentRepository commentRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.koa.coremodule.email.application.dto.request;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class VerifyCodeRequest {
private String email;
private String code;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.koa.coremodule.email.application.dto.request;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class VerifyEmailRequest {
private String email;

public VerifyEmailRequest(String email) {
this.email = email;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.koa.coremodule.member.application.dto.response;
package com.koa.coremodule.email.application.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Loading

0 comments on commit d5cc00c

Please sign in to comment.