-
Notifications
You must be signed in to change notification settings - Fork 0
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
사용자 로그아웃, 탈퇴 기능 구현 #48
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7328601
feat: 사용자의 특정 디바이스 토큰 비활성화 기능 추가
JJ503 8672b0c
feat: 블랙 리스트 토큰 및 조회 기능 추가
JJ503 1867122
feat: 블랙 리스트 토큰을 저장하는 기능 추가
JJ503 48dba0b
feat: 로그아웃 기능 서비스 추가
JJ503 9b55084
feat: 로그아웃 기능 컨트로러 추가
JJ503 a1926ac
feat: 탈퇴 기능 서비스 구현
JJ503 0b506e6
feat: 탈퇴 기능 컨트롤러 구현
JJ503 388e94c
feat: 이미 블랙 리스트에 등록된 토큰에 대한 예외 처리 추가
JJ503 9da2cb6
test: import 문의 와일드 카드 제거
JJ503 0c6d595
ci: 브랜치 최신화
JJ503 dda637b
style: 개행 추가
JJ503 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/backend/blooming/authentication/application/BlackListTokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.backend.blooming.authentication.application; | ||
|
||
import com.backend.blooming.authentication.application.exception.AlreadyRegisterBlackListTokenException; | ||
import com.backend.blooming.authentication.domain.BlackListToken; | ||
import com.backend.blooming.authentication.infrastructure.blacklist.BlackListTokenRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class BlackListTokenService { | ||
|
||
private final BlackListTokenRepository blackListTokenRepository; | ||
|
||
public Long register(final String token) { | ||
validateToken(token); | ||
final BlackListToken blackListToken = new BlackListToken(token); | ||
|
||
return blackListTokenRepository.save(blackListToken) | ||
.getId(); | ||
} | ||
|
||
private void validateToken(String token) { | ||
if (blackListTokenRepository.existsByToken(token)) { | ||
throw new AlreadyRegisterBlackListTokenException(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/backend/blooming/authentication/application/dto/LogoutDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.backend.blooming.authentication.application.dto; | ||
|
||
import com.backend.blooming.authentication.presentation.dto.LogoutRequest; | ||
|
||
public record LogoutDto(String refreshToken, String deviceToken) { | ||
|
||
public static LogoutDto from(final LogoutRequest logoutRequest) { | ||
return new LogoutDto(logoutRequest.refreshToken(), logoutRequest.deviceToken()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...blooming/authentication/application/exception/AlreadyRegisterBlackListTokenException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.backend.blooming.authentication.application.exception; | ||
|
||
import com.backend.blooming.exception.BloomingException; | ||
import com.backend.blooming.exception.ExceptionMessage; | ||
|
||
public class AlreadyRegisterBlackListTokenException extends BloomingException { | ||
|
||
public AlreadyRegisterBlackListTokenException() { | ||
super(ExceptionMessage.ALREADY_REGISTER_BLACK_LIST_TOKEN); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/com/backend/blooming/authentication/domain/BlackListToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.backend.blooming.authentication.domain; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@EqualsAndHashCode(of = "id", callSuper = false) | ||
@ToString | ||
@Table | ||
public class BlackListToken { | ||
|
||
@Id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개행이 필요할 것 같네요! |
||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String token; | ||
|
||
public BlackListToken(final String token) { | ||
this.token = token; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...om/backend/blooming/authentication/infrastructure/blacklist/BlackListTokenRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.backend.blooming.authentication.infrastructure.blacklist; | ||
|
||
import com.backend.blooming.authentication.domain.BlackListToken; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface BlackListTokenRepository extends JpaRepository<BlackListToken, Long> { | ||
|
||
Optional<BlackListToken> findByToken(final String token); | ||
|
||
boolean existsByToken(final String token); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/backend/blooming/authentication/presentation/dto/LogoutRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.backend.blooming.authentication.presentation.dto; | ||
|
||
public record LogoutRequest(String refreshToken, String deviceToken) { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/backend/blooming/authentication/presentation/dto/WithdrawRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.backend.blooming.authentication.presentation.dto; | ||
|
||
public record WithdrawRequest(String refreshToken) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
별건 아닌데 저희 메서드 정렬 기준이 필요할까요?
지금까지는 구현 순서대로 정렬하기로 해서 그렇게 진행하고 있는데 코드가 점점 길어지다보니 메서드 정렬도 뭔가 기준이 필요한가? 하는 생각이 들더라구요. 그래서 클래스 내 메서드 정렬 기준을 만드는 건 어떻게 생각하시는지 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 보통 public 메서드는 C -> R -> U -> D의 순서로 작성하고, 그 외에는 호출 순서로 작성하고 있습니다.
저도 제안드릴까 고민을 하다, 오히려 익숙해진 메서드 작성 방식이 있으시다면 불편함을 드릴까 해서 제안드리지 못했습니다.
그래서 메서드 정렬 기준을 만드는 것에 대해선 찬성합니다!
혹시 생각해 보시거나 적용하신 메서드 정렬 기준이 있으실까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 이번에 서비스 클래스에서 CRUD 순서대로 메서드 정렬 후에 검증 메서드들을 아예 crud 메서드 아래로 다 빼서 정리를 해봤습니다. 순서는 자주 호출되는 순서대로 정렬했습니다. 그런데 구글링 해보니 읽는 사람이 편하게 메서드끼리 논리적 응집도를 높이는 방법도 있더라구요!
어떤 방법이 더 좋을 것 같으신가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 굳이 검증 메서드를 하위로 빼는 것을 선호하지 않긴 합니다.
왜냐하면, 보통 코드리뷰를 할 때 위에서부터 코드를 읽게 되는데, 말씀해 주신 방식대로 한다면 계속 스크롤을 왔다 갔다 해야 하는 번거로움이 있으며 기존 있던 메서들를 새로운 메서드에서 사용하게 된다면 이에 대한 순서를 계속해 고려해야 하기 때문입니다.
그래서 저는 보통 호출되는 순서대로 작성했었습니다. 하단에서 상단의 메서드를 사용하더라도 이미 본 코드기에 이해하기 편하기도 하고요!
그런데, 메서드 정렬을 논리적 응집도를 사용하게 된다면 어떤 형식으로 되는 것인지 잘 모르겠는데 설명을 좀 더 해주실 수 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
논리적 응집도를 높이는 방식이 호출 순서대로 작성하는 방식입니다. 예를 들어 update 메서드에서 차례대로 getUser, getGoal, validateTeamsToUpdate 함수를 호출한다면 update 메서드에서 아래에 세가지 함수를 순서대로 정렬하는 것입니다. 가독성을 위해 하나의 큰 메서드를 기준으로 해서 호출되는 메서드를 주위에 정렬하는 방식으로 이해했습니다.
정리를 깔끔하게 하고자 하는 마음에 검증 메서드를 아예 하위로 빼봤는데 가독성이 더 중요하니 하던대로 호출 순서대로 정렬을 할까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저희가 슬랙에서 이야기한 결과 메서드 작성 순서는 큰 형식은 CRUD 순으로 작성하는 것으로 결정되었습니다.
또한, private과 같이 public 메서드들에서 사용되는 메서드들은 모두 호출 순서로 public 메서드 사이에 위치하도록 결정되었습니다.