diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/AuthController.java b/api-module/src/main/java/com/koa/apimodule/command/api/AuthController.java index f56510da..191337e3 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/AuthController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/AuthController.java @@ -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 @@ -20,11 +21,10 @@ public class AuthController { private final AuthUseCase authUseCase; private final LogoutUseCase logoutUseCase; - private final AlarmUseCase alarmUseCase; @GetMapping("/login/{authority}") - public ApplicationResponse authLogin(@PathVariable Authority authority, @RequestParam String email, @RequestParam String password){ - AuthResponse response = authUseCase.authLogin(authority, email, password); + public ApplicationResponse authLogin(@PathVariable Authority authority, @RequestBody LoginRequest loginRequest){ + AuthResponse response = authUseCase.authLogin(authority, loginRequest); return ApplicationResponse.ok(response); } @@ -37,10 +37,6 @@ public ApplicationResponse authReissue(@RequestHeader(AuthConsts.R @DeleteMapping("/logout") public ApplicationResponse logout(@RequestHeader(AuthConsts.REFRESH_TOKEN_HEADER) String refreshToken){ logoutUseCase.logoutAccessUser(refreshToken); - - // 로그아웃 시 토큰 제거 - alarmUseCase.deleteFcmToken(); - return ApplicationResponse.ok(null); } } diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/EmailController.java b/api-module/src/main/java/com/koa/apimodule/command/api/EmailController.java index c5c1fec4..ace3df5a 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/EmailController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/EmailController.java @@ -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 @@ -18,14 +21,14 @@ public class EmailController { private final EmailVerificationUseCase emailVerificationUseCase; @PostMapping("/verify") - public ApplicationResponse postVerifyEmail(@RequestParam String email) { - emailVerificationUseCase.sendVerificationEmail(email); + public ApplicationResponse postVerifyEmail(@RequestBody VerifyEmailRequest verifyEmailRequest) { + emailVerificationUseCase.sendVerificationEmail(verifyEmailRequest); return ApplicationResponse.ok(null); } - @PostMapping("/verify/code") - public ApplicationResponse verifyCode(@RequestParam String email, @RequestParam String code) { - VerifyCodeResponse response = emailVerificationUseCase.verifyCode(email, code); + @GetMapping("/verify/code") + public ApplicationResponse verifyCode(@RequestBody VerifyCodeRequest verifyCodeRequest) { + VerifyCodeResponse response = emailVerificationUseCase.verifyCode(verifyCodeRequest); return ApplicationResponse.ok(response); } } diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java b/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java index d303082b..421eb234 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java @@ -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; @@ -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 @@ -41,21 +42,21 @@ public ApplicationResponse getMemberInfo(){ return ApplicationResponse.ok(response); } - @PostMapping("/check/register") - public ApplicationResponse checkMemberRegistered(@RequestParam String email, @RequestParam String password) { - CheckRegisterResponse response = memberCheckUseCase.checkMemberRegistered(email, password); + @GetMapping("/check/register") + public ApplicationResponse checkMemberRegistered(@RequestBody MemberRegisterRequest memberRegisterRequest) { + CheckRegisterResponse response = memberCheckUseCase.checkMemberRegistered(memberRegisterRequest); return ApplicationResponse.ok(response); } - @PostMapping("/register") - public ApplicationResponse postMemberDetail(@RequestParam String email, @RequestParam String password){ - memberRegisterUseCase.registerMember(email, password); + @GetMapping("/register") + public ApplicationResponse getMemberRegister(@RequestBody MemberRegisterRequest memberRegisterRequest){ + memberRegisterUseCase.registerMember(memberRegisterRequest); return ApplicationResponse.ok(null); } - @PostMapping("/email") - public ApplicationResponse checkEmail(@RequestParam String email) { - CheckEmailResponse response = memberCheckUseCase.checkEmail(email); + @GetMapping("/email") + public ApplicationResponse checkEmail(@RequestBody CheckEmailRequest checkEmailRequest) { + CheckEmailResponse response = memberCheckUseCase.checkEmail(checkEmailRequest); return ApplicationResponse.ok(response); } @@ -65,9 +66,9 @@ public ApplicationResponse deleteMember(){ return ApplicationResponse.ok(null); } - @PostMapping("/password") - public ApplicationResponse checkPassword(@RequestParam String password) { - CheckPasswordResponse response = memberCheckUseCase.checkPassword(password); + @GetMapping("/password") + public ApplicationResponse checkPassword(@RequestBody CheckPasswordRequest checkPasswordRequest) { + CheckPasswordResponse response = memberCheckUseCase.checkPassword(checkPasswordRequest); return ApplicationResponse.ok(response); } @@ -78,8 +79,8 @@ public ApplicationResponse putPassword(@RequestBody MemberPasswordChangeRe } @PutMapping("/password/unauthenticated") - public ApplicationResponse putPasswordUnauthenticated(@RequestParam String email, @RequestBody MemberPasswordChangeRequest memberPasswordChangeRequest) { - memberPasswordChangeUseCase.changePasswordUnauthenticated(email, memberPasswordChangeRequest); + public ApplicationResponse putPasswordUnauthenticated(@RequestBody MemberPasswordChangeRequest memberPasswordChangeRequest) { + memberPasswordChangeUseCase.changePasswordUnauthenticated(memberPasswordChangeRequest); return ApplicationResponse.ok(null); } diff --git a/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java b/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java index 52f1beb3..ef55763b 100644 --- a/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java +++ b/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java @@ -19,13 +19,13 @@ private static Map> createIgnoredPathMap() { Map> 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)); diff --git a/core-module/src/main/java/com/koa/coremodule/auth/application/dto/LoginRequest.java b/core-module/src/main/java/com/koa/coremodule/auth/application/dto/LoginRequest.java new file mode 100644 index 00000000..4e9a73fa --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/auth/application/dto/LoginRequest.java @@ -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; +} diff --git a/core-module/src/main/java/com/koa/coremodule/auth/application/handler/AlarmTokenDeleteEventHandler.java b/core-module/src/main/java/com/koa/coremodule/auth/application/handler/AlarmTokenDeleteEventHandler.java new file mode 100644 index 00000000..ab397c46 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/auth/application/handler/AlarmTokenDeleteEventHandler.java @@ -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()); + } +} diff --git a/core-module/src/main/java/com/koa/coremodule/auth/application/handler/event/AlarmTokenDeleteEvent.java b/core-module/src/main/java/com/koa/coremodule/auth/application/handler/event/AlarmTokenDeleteEvent.java new file mode 100644 index 00000000..0506d3c3 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/auth/application/handler/event/AlarmTokenDeleteEvent.java @@ -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; +} diff --git a/core-module/src/main/java/com/koa/coremodule/auth/application/service/AuthUseCase.java b/core-module/src/main/java/com/koa/coremodule/auth/application/service/AuthUseCase.java index 6c97a079..1251c162 100644 --- a/core-module/src/main/java/com/koa/coremodule/auth/application/service/AuthUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/auth/application/service/AuthUseCase.java @@ -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; @@ -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){ diff --git a/core-module/src/main/java/com/koa/coremodule/auth/application/service/LogoutUseCase.java b/core-module/src/main/java/com/koa/coremodule/auth/application/service/LogoutUseCase.java index 2f2ae6ff..3a6680e5 100644 --- a/core-module/src/main/java/com/koa/coremodule/auth/application/service/LogoutUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/auth/application/service/LogoutUseCase.java @@ -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())); } } diff --git a/core-module/src/main/java/com/koa/coremodule/auth/domain/service/TokenQueryService.java b/core-module/src/main/java/com/koa/coremodule/auth/domain/service/TokenQueryService.java index 91f44b44..a3a734a9 100644 --- a/core-module/src/main/java/com/koa/coremodule/auth/domain/service/TokenQueryService.java +++ b/core-module/src/main/java/com/koa/coremodule/auth/domain/service/TokenQueryService.java @@ -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; diff --git a/core-module/src/main/java/com/koa/coremodule/auth/domain/service/TokenSaveService.java b/core-module/src/main/java/com/koa/coremodule/auth/domain/service/TokenSaveService.java index 18dd7f52..79c70e5c 100644 --- a/core-module/src/main/java/com/koa/coremodule/auth/domain/service/TokenSaveService.java +++ b/core-module/src/main/java/com/koa/coremodule/auth/domain/service/TokenSaveService.java @@ -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){ diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java index 8c5e4cb1..61d1bb7e 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java @@ -18,6 +18,7 @@ @ApplicationService @RequiredArgsConstructor +@Transactional public class CommentCreateUseCase { private final MemberUtils memberUtils; private final NoticeQueryService noticeQueryService; diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentDeleteUseCase.java b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentDeleteUseCase.java index 7641e9af..21df8bd8 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentDeleteUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentDeleteUseCase.java @@ -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; diff --git a/core-module/src/main/java/com/koa/coremodule/comment/domain/service/CommentDeleteService.java b/core-module/src/main/java/com/koa/coremodule/comment/domain/service/CommentDeleteService.java index 8fb3200f..5c7b3b14 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/domain/service/CommentDeleteService.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/domain/service/CommentDeleteService.java @@ -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; diff --git a/core-module/src/main/java/com/koa/coremodule/comment/domain/service/CommentSaveService.java b/core-module/src/main/java/com/koa/coremodule/comment/domain/service/CommentSaveService.java index 8b220072..d368f4af 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/domain/service/CommentSaveService.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/domain/service/CommentSaveService.java @@ -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; diff --git a/core-module/src/main/java/com/koa/coremodule/email/application/dto/request/VerifyCodeRequest.java b/core-module/src/main/java/com/koa/coremodule/email/application/dto/request/VerifyCodeRequest.java new file mode 100644 index 00000000..c550de4f --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/email/application/dto/request/VerifyCodeRequest.java @@ -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; +} diff --git a/core-module/src/main/java/com/koa/coremodule/email/application/dto/request/VerifyEmailRequest.java b/core-module/src/main/java/com/koa/coremodule/email/application/dto/request/VerifyEmailRequest.java new file mode 100644 index 00000000..7027feb3 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/email/application/dto/request/VerifyEmailRequest.java @@ -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; + } +} diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/dto/response/VerifyCodeResponse.java b/core-module/src/main/java/com/koa/coremodule/email/application/dto/response/VerifyCodeResponse.java similarity index 76% rename from core-module/src/main/java/com/koa/coremodule/member/application/dto/response/VerifyCodeResponse.java rename to core-module/src/main/java/com/koa/coremodule/email/application/dto/response/VerifyCodeResponse.java index 063330d2..fadf03bd 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/application/dto/response/VerifyCodeResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/email/application/dto/response/VerifyCodeResponse.java @@ -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; diff --git a/core-module/src/main/java/com/koa/coremodule/email/application/service/EmailVerificationUseCase.java b/core-module/src/main/java/com/koa/coremodule/email/application/service/EmailVerificationUseCase.java new file mode 100644 index 00000000..aed26505 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/email/application/service/EmailVerificationUseCase.java @@ -0,0 +1,25 @@ +package com.koa.coremodule.email.application.service; + +import com.koa.commonmodule.annotation.ApplicationService; +import com.koa.coremodule.email.application.dto.request.VerifyCodeRequest; +import com.koa.coremodule.email.application.dto.request.VerifyEmailRequest; +import com.koa.coremodule.email.service.EmailSendService; +import com.koa.coremodule.email.service.EmailVerifyService; +import com.koa.coremodule.email.application.dto.response.VerifyCodeResponse; +import lombok.RequiredArgsConstructor; + +@ApplicationService +@RequiredArgsConstructor +public class EmailVerificationUseCase { + + private final EmailSendService emailSendService; + private final EmailVerifyService emailVerifyService; + public void sendVerificationEmail(VerifyEmailRequest verifyEmailRequest) { + emailSendService.sendEmail(verifyEmailRequest.getEmail()); + } + + public VerifyCodeResponse verifyCode(VerifyCodeRequest verifyCodeRequest) { + final boolean isVerified = emailVerifyService.verifyCode(verifyCodeRequest.getEmail(), verifyCodeRequest.getCode()); + return new VerifyCodeResponse(isVerified); + } +} diff --git a/core-module/src/main/java/com/koa/coremodule/email/exception/CreateCodeException.java b/core-module/src/main/java/com/koa/coremodule/email/exception/CreateCodeException.java deleted file mode 100644 index 17719f00..00000000 --- a/core-module/src/main/java/com/koa/coremodule/email/exception/CreateCodeException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.koa.coremodule.email.exception; -import com.koa.commonmodule.exception.Error; - -public class CreateCodeException extends EmailException{ - public CreateCodeException(Error error) { - super(error); - } -} diff --git a/core-module/src/main/java/com/koa/coremodule/email/exception/EmailException.java b/core-module/src/main/java/com/koa/coremodule/email/exception/EmailException.java deleted file mode 100644 index e9484102..00000000 --- a/core-module/src/main/java/com/koa/coremodule/email/exception/EmailException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.koa.coremodule.email.exception; - -import com.koa.commonmodule.exception.BusinessException; -import com.koa.commonmodule.exception.Error; - -public class EmailException extends BusinessException { - public EmailException(Error error) { - super(error); - } -} diff --git a/core-module/src/main/java/com/koa/coremodule/email/exception/WrongCodeException.java b/core-module/src/main/java/com/koa/coremodule/email/exception/WrongCodeException.java deleted file mode 100644 index 47693399..00000000 --- a/core-module/src/main/java/com/koa/coremodule/email/exception/WrongCodeException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.koa.coremodule.email.exception; -import com.koa.commonmodule.exception.Error; - -public class WrongCodeException extends EmailException{ - public WrongCodeException(Error error) { - super(error); - } -} diff --git a/core-module/src/main/java/com/koa/coremodule/email/service/EmailSendService.java b/core-module/src/main/java/com/koa/coremodule/email/service/EmailSendService.java index 6943a5f6..803a900b 100644 --- a/core-module/src/main/java/com/koa/coremodule/email/service/EmailSendService.java +++ b/core-module/src/main/java/com/koa/coremodule/email/service/EmailSendService.java @@ -1,10 +1,6 @@ package com.koa.coremodule.email.service; -import com.koa.commonmodule.exception.Error; import com.koa.commonmodule.utils.RedisUtils; -import com.koa.coremodule.email.exception.CreateCodeException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; import java.util.Random; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; diff --git a/core-module/src/main/java/com/koa/coremodule/email/service/EmailVerifyService.java b/core-module/src/main/java/com/koa/coremodule/email/service/EmailVerifyService.java index d5c11cdc..9c56fe2a 100644 --- a/core-module/src/main/java/com/koa/coremodule/email/service/EmailVerifyService.java +++ b/core-module/src/main/java/com/koa/coremodule/email/service/EmailVerifyService.java @@ -1,8 +1,6 @@ package com.koa.coremodule.email.service; -import com.koa.commonmodule.exception.Error; import com.koa.commonmodule.utils.RedisUtils; -import com.koa.coremodule.email.exception.WrongCodeException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/core-module/src/main/java/com/koa/coremodule/fcm/application/service/AlarmUseCase.java b/core-module/src/main/java/com/koa/coremodule/fcm/application/service/AlarmUseCase.java index 732bb727..49555f48 100644 --- a/core-module/src/main/java/com/koa/coremodule/fcm/application/service/AlarmUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/fcm/application/service/AlarmUseCase.java @@ -12,6 +12,7 @@ import com.koa.coremodule.fcm.domain.entity.Alarm; import com.koa.coremodule.fcm.domain.entity.AlarmType; import com.koa.coremodule.fcm.domain.entity.AlarmView; +import com.koa.coremodule.fcm.domain.service.AlarmDeleteService; import com.koa.coremodule.fcm.domain.service.AlarmQueryService; import com.koa.coremodule.fcm.domain.service.AlarmSaveService; import com.koa.coremodule.member.domain.entity.Member; @@ -42,6 +43,7 @@ public class AlarmUseCase { private final MemberUtils memberUtils; private final AlarmSaveService alarmSaveService; private final AlarmQueryService alarmQueryService; + private final AlarmDeleteService alarmDeleteService; private final NoticeQueryService noticeQueryService; private final CommentQueryService commentQueryService; @@ -251,14 +253,8 @@ public void saveAlarmView(Long alarmId) { alarmSaveService.saveAlarmView(alarmView); } - public void deleteFcmToken() { - - Member memberRequest = memberUtils.getAccessMember(); - alarmSaveService.deleteFcmToken(memberRequest.getId()); - } - public void deleteAlarm(Long alarmId) { - alarmSaveService.deleteAlarm(alarmId); + alarmDeleteService.deleteAlarm(alarmId); } private Member findMember(Long memberId) { diff --git a/core-module/src/main/java/com/koa/coremodule/fcm/domain/service/AlarmDeleteService.java b/core-module/src/main/java/com/koa/coremodule/fcm/domain/service/AlarmDeleteService.java new file mode 100644 index 00000000..239af338 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/fcm/domain/service/AlarmDeleteService.java @@ -0,0 +1,29 @@ +package com.koa.coremodule.fcm.domain.service; + +import com.koa.coremodule.fcm.domain.repository.AlarmRepository; +import com.koa.coremodule.fcm.domain.repository.AlarmViewRepository; +import com.koa.coremodule.member.domain.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class AlarmDeleteService { + + private final AlarmRepository alarmRepository; + private final AlarmViewRepository alarmViewRepository; + private final MemberRepository memberRepository; + + public void deleteFcmToken(Long id) { + memberRepository.deleteAlarmToken(id); + } + + public void deleteAlarm(Long alarmId) { + + alarmViewRepository.deleteAlarmViewByAlarmId(alarmId); + alarmRepository.deleteAlarmById(alarmId); + } + +} diff --git a/core-module/src/main/java/com/koa/coremodule/fcm/domain/service/AlarmSaveService.java b/core-module/src/main/java/com/koa/coremodule/fcm/domain/service/AlarmSaveService.java index 3055cf11..a110915a 100644 --- a/core-module/src/main/java/com/koa/coremodule/fcm/domain/service/AlarmSaveService.java +++ b/core-module/src/main/java/com/koa/coremodule/fcm/domain/service/AlarmSaveService.java @@ -26,14 +26,4 @@ public void saveAlarmView(AlarmView alarmView) { alarmViewRepository.save(alarmView); } - public void deleteFcmToken(Long id) { - noticeRepository.deleteToken(id); - } - - public void deleteAlarm(Long alarmId) { - - alarmViewRepository.deleteAlarmViewByAlarmId(alarmId); - alarmRepository.deleteAlarmById(alarmId); - } - } diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/CheckEmailRequest.java b/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/CheckEmailRequest.java new file mode 100644 index 00000000..2e49d033 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/CheckEmailRequest.java @@ -0,0 +1,13 @@ +package com.koa.coremodule.member.application.dto.request; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CheckEmailRequest { + private String email; +} diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/CheckPasswordRequest.java b/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/CheckPasswordRequest.java new file mode 100644 index 00000000..caa66e81 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/CheckPasswordRequest.java @@ -0,0 +1,13 @@ +package com.koa.coremodule.member.application.dto.request; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CheckPasswordRequest { + private String password; +} diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/MemberPasswordChangeRequest.java b/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/MemberPasswordChangeRequest.java index f67242d7..9ea3bc27 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/MemberPasswordChangeRequest.java +++ b/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/MemberPasswordChangeRequest.java @@ -1,15 +1,14 @@ package com.koa.coremodule.member.application.dto.request; import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @Getter +@AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) public class MemberPasswordChangeRequest { + private String email; private String password; - - public MemberPasswordChangeRequest(String password) { - this.password = password; - } } diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/MemberRegisterRequest.java b/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/MemberRegisterRequest.java new file mode 100644 index 00000000..0a3fbb8a --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/member/application/dto/request/MemberRegisterRequest.java @@ -0,0 +1,14 @@ +package com.koa.coremodule.member.application.dto.request; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class MemberRegisterRequest { + private String email; + private String password; +} diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/service/EmailVerificationUseCase.java b/core-module/src/main/java/com/koa/coremodule/member/application/service/EmailVerificationUseCase.java deleted file mode 100644 index deab08a4..00000000 --- a/core-module/src/main/java/com/koa/coremodule/member/application/service/EmailVerificationUseCase.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.koa.coremodule.member.application.service; - -import com.koa.commonmodule.annotation.ApplicationService; -import com.koa.coremodule.email.service.EmailSendService; -import com.koa.coremodule.email.service.EmailVerifyService; -import com.koa.coremodule.member.application.dto.response.VerifyCodeResponse; -import com.koa.coremodule.member.domain.service.MemberQueryService; -import lombok.RequiredArgsConstructor; - -@ApplicationService -@RequiredArgsConstructor -public class EmailVerificationUseCase { - - private final EmailSendService emailSendService; - private final EmailVerifyService emailVerifyService; - private final MemberQueryService memberQueryService; - - public void sendVerificationEmail(String email) { - emailSendService.sendEmail(email); - } - - public VerifyCodeResponse verifyCode(String email, String code) { - final boolean isVerified = emailVerifyService.verifyCode(email, code); - return new VerifyCodeResponse(isVerified); - } -} diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberCheckUseCase.java b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberCheckUseCase.java index b74420d8..3b938234 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberCheckUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberCheckUseCase.java @@ -1,6 +1,9 @@ package com.koa.coremodule.member.application.service; import com.koa.commonmodule.annotation.ApplicationService; +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.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; @@ -18,19 +21,19 @@ public class MemberCheckUseCase { private final MemberUtils memberUtils; private final MemberQueryService memberQueryService; - public CheckRegisterResponse checkMemberRegistered(String email, String password) { - boolean isMember = memberQueryService.checkMemberExist(email, password); - Member member = isMember ? memberQueryService.findByEmail(email) : null; + public CheckRegisterResponse checkMemberRegistered(MemberRegisterRequest memberRegisterRequest) { + boolean isMember = memberQueryService.checkMemberExist(memberRegisterRequest.getEmail(), memberRegisterRequest.getPassword()); + Member member = isMember ? memberQueryService.findByEmail(memberRegisterRequest.getEmail()) : null; return new CheckRegisterResponse(isMember, member != null && member.isRegistered()); } - public CheckPasswordResponse checkPassword(String password) { + public CheckPasswordResponse checkPassword(CheckPasswordRequest checkPasswordRequest) { Member member = memberUtils.getAccessMember(); - return new CheckPasswordResponse(member.checkPassword(password)); + return new CheckPasswordResponse(member.checkPassword(checkPasswordRequest.getPassword())); } - public CheckEmailResponse checkEmail(String email) { - final boolean isEmailExist = memberQueryService.checkEmailExist(email); + public CheckEmailResponse checkEmail(CheckEmailRequest checkEmailRequest) { + final boolean isEmailExist = memberQueryService.checkEmailExist(checkEmailRequest.getEmail()); return new CheckEmailResponse(isEmailExist); } } diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberPasswordChangeUseCase.java b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberPasswordChangeUseCase.java index 11108805..55f6a454 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberPasswordChangeUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberPasswordChangeUseCase.java @@ -16,13 +16,13 @@ public class MemberPasswordChangeUseCase { private final MemberUtils memberUtils; private final MemberQueryService memberQueryService; - public void changePassword(MemberPasswordChangeRequest request) { + public void changePassword(MemberPasswordChangeRequest memberPasswordChangeRequest) { Member member = memberUtils.getAccessMember(); - member.updatePassword(request.getPassword()); + member.updatePassword(memberPasswordChangeRequest.getPassword()); } - public void changePasswordUnauthenticated(String email, MemberPasswordChangeRequest request) { - Member member = memberQueryService.findByEmail(email); - member.updatePassword(request.getPassword()); + public void changePasswordUnauthenticated(MemberPasswordChangeRequest memberPasswordChangeRequest) { + Member member = memberQueryService.findByEmail(memberPasswordChangeRequest.getEmail()); + member.updatePassword(memberPasswordChangeRequest.getPassword()); } } diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberRegisterUseCase.java b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberRegisterUseCase.java index f3496ad6..a5611abc 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberRegisterUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberRegisterUseCase.java @@ -2,6 +2,7 @@ import com.koa.commonmodule.annotation.ApplicationService; import com.koa.commonmodule.exception.Error; +import com.koa.coremodule.member.application.dto.request.MemberRegisterRequest; import com.koa.coremodule.member.application.exception.WrongPasswordException; import com.koa.coremodule.member.domain.entity.Member; import com.koa.coremodule.member.domain.service.MemberQueryService; @@ -15,9 +16,9 @@ public class MemberRegisterUseCase { private final MemberQueryService memberQueryService; - public void registerMember(String email, String password) { - Member member = memberQueryService.findByEmail(email); - final boolean isPasswordMatch = member.checkPassword(password); + public void registerMember(MemberRegisterRequest memberRegisterRequest) { + Member member = memberQueryService.findByEmail(memberRegisterRequest.getEmail()); + final boolean isPasswordMatch = member.checkPassword(memberRegisterRequest.getPassword()); if(!isPasswordMatch) { throw new WrongPasswordException(Error.MEMBER_NOT_FOUND); } diff --git a/core-module/src/main/java/com/koa/coremodule/member/domain/repository/MemberRepository.java b/core-module/src/main/java/com/koa/coremodule/member/domain/repository/MemberRepository.java index a371468b..2bd2e2c3 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/domain/repository/MemberRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/member/domain/repository/MemberRepository.java @@ -4,10 +4,16 @@ import com.koa.coremodule.member.domain.entity.Member; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; public interface MemberRepository extends JpaRepository { boolean existsByAuthorityAndEmailAndPassword(Authority authority, String email, String password); boolean existsByEmailAndPassword(String email, String password); boolean existsByEmail(String email); Optional findByEmail(String email); + + @Modifying + @Query("update Member m set m.fcmToken = null where m.id = :id") + void deleteAlarmToken(Long id); } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java index 79fa5a8e..9dd48e25 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java @@ -45,10 +45,6 @@ public interface NoticeRepository extends JpaRepository, NoticeDyn @Query("update NoticeView v set v.view = :viewType where v.member.id = :memberId and v.id = :noticeViewId") void updateSingleViewYn(Long noticeViewId, Long memberId, ViewType viewType); - @Modifying - @Query("update Member m set m.fcmToken = null where m.id = :id") - void deleteToken(Long id); - @Query("select n.member.id from Notice n where n.id = :noticeId") Long findMemberIdByNoticeId(Long noticeId);