forked from codesquad-members-2023/FoodyMoody-team-06
-
Notifications
You must be signed in to change notification settings - Fork 3
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
be/feat/#158 be 무드 조회 api 구현 #160
Merged
The head ref may contain hidden characters: "be/feat/#158-be-\uBB34\uB4DC-\uC870\uD68C-api-\uAD6C\uD604"
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1bb748c
feat: Mood 조회, Mood 랜덤 조회 기능 구현
sejeongsong 202cbd9
chore: 성공케이스라는 문구 추가
sejeongsong f1314cd
fix: 에러 코드가 에러 메세지로 출력되는 오류 수정
sejeongsong 1843b4b
feat: 무드 등록, 무드 id로 조회 기능 구현
sejeongsong 51caba8
chore: whitelist 추가
sejeongsong 385b30c
chore: docs -> acceptance로 패키지 이동, 패키지명 인수테스트로 변경
sejeongsong 93d4f2a
fix: 비밀번호 검증이 누락된 오류 해결
sejeongsong 1ef53ef
chore: DB에 존재하지 않는 Member Fixture는 비회원으로 수정
sejeongsong 90be198
refactor: 인증 실패시 응답 상태코드 더 상세하게 분류
sejeongsong a2df764
test: 로그인 기능 인수 테스트 추가
sejeongsong 8fddd0e
refactor: JwtUtil에서 클레임 관련 메서드들을 ClaimUtil로 분리
sejeongsong 6febf06
test: 회원 가입 기능 인수테스트 작성
sejeongsong e9b92e3
refactor: 엔티티 -> dto 변환을 서비스에서 Mapper로 이동
sejeongsong 733f12a
refactor: mood -> name 으로 파라미터명 변경
sejeongsong 63806c6
refactor: Exception 클래스의 상속 깊이가 5를 넘지 않도록 수정
sejeongsong a822e19
test: 회원 프로필 조회 인수 테스트 추가
sejeongsong 5d7077a
feat: 회원가입 시 이메일 형식 검증 추가
sejeongsong f71673e
refactor: 기본생성자 protected로 변경
sejeongsong bea474b
fix: PK의 타입이 String이라 findById가 안되는 오류 수정
sejeongsong 481e83e
refactor: dto로 조회하는 메서드명을 전부 fetch로 변경
sejeongsong 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
48 changes: 48 additions & 0 deletions
48
be/src/main/java/com/foodymoody/be/auth/util/ClaimUtil.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,48 @@ | ||
package com.foodymoody.be.auth.util; | ||
|
||
import com.foodymoody.be.common.exception.ClaimNotFoundException; | ||
import io.jsonwebtoken.Claims; | ||
import io.jsonwebtoken.IncorrectClaimException; | ||
import io.jsonwebtoken.JwtParser; | ||
import io.jsonwebtoken.Jwts; | ||
import io.jsonwebtoken.RequiredTypeException; | ||
import io.jsonwebtoken.security.Keys; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import javax.crypto.SecretKey; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ClaimUtil { | ||
|
||
private String secret; | ||
private SecretKey secretKey; | ||
|
||
public ClaimUtil(@Value("${jwt.token.secret}") String secret){ | ||
this.secret = secret; | ||
this.secretKey = Keys.hmacShaKeyFor(secret.getBytes()); | ||
} | ||
|
||
public Map<String, Object> createClaim(String key, String value) { | ||
return Map.of(key, value); | ||
} | ||
|
||
public <T> T getClaim(Claims claims, String key, Class<T> type) { | ||
try { | ||
T claim = claims.get(key, type); | ||
if (Objects.isNull(claim)) { | ||
throw new ClaimNotFoundException(); | ||
} | ||
return claim; | ||
} catch (RequiredTypeException | ClassCastException e) { | ||
throw new IncorrectClaimException(null, claims, key); | ||
} | ||
} | ||
|
||
public Claims extractClaims(String token) { | ||
JwtParser parser = Jwts.parserBuilder().setSigningKey(secretKey).build(); | ||
return parser.parseClaimsJws(token).getBody(); | ||
} | ||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
be/src/main/java/com/foodymoody/be/common/exception/DuplicateMoodException.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,8 @@ | ||
package com.foodymoody.be.common.exception; | ||
|
||
public class DuplicateMoodException extends BusinessException { | ||
|
||
public DuplicateMoodException() { | ||
super(ErrorMessage.DUPLICATE_MOOD); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
be/src/main/java/com/foodymoody/be/common/exception/IncorrectMemberPasswordException.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
2 changes: 1 addition & 1 deletion
2
be/src/main/java/com/foodymoody/be/common/exception/MemberNotFoundException.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
15 changes: 15 additions & 0 deletions
15
be/src/main/java/com/foodymoody/be/common/exception/ResourceNotFoundException.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,15 @@ | ||
package com.foodymoody.be.common.exception; | ||
|
||
public abstract class ResourceNotFoundException extends RuntimeException{ | ||
|
||
private final ErrorMessage errorMessage; | ||
|
||
protected ResourceNotFoundException(ErrorMessage errorMessage) { | ||
super(errorMessage.getMessage()); | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
public String getCode() { | ||
return errorMessage.getCode(); | ||
} | ||
} |
14 changes: 10 additions & 4 deletions
14
be/src/main/java/com/foodymoody/be/common/exception/UnauthorizedException.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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package com.foodymoody.be.common.exception; | ||
|
||
public class UnauthorizedException extends BusinessException{ | ||
public class UnauthorizedException extends RuntimeException{ | ||
|
||
// TODO 적절한 표준 예외로 리팩토링 | ||
public UnauthorizedException() { | ||
super(ErrorMessage.UNAUTHORIZED); | ||
private final ErrorMessage errorMessage; | ||
|
||
protected UnauthorizedException(ErrorMessage errorMessage) { | ||
super(errorMessage.getMessage()); | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
public String getCode() { | ||
return errorMessage.getCode(); | ||
} | ||
} |
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.
Exception -> RuntimeException -> BusinessException -> UnauthorizedException -> IncorrectMemberPasswordException
deep가 너무 깊어서 추천하지 않아요.~ 원인은 한번 확인 해봐요.
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.
부모 클래스가 많을수록 클래스가 복잡해지고, 불필요하게 결합도가 높아지는 것 같습니다.. BusinessException을 상속받지 않도록 수정하겠습니다!