-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/depromeet/15th-team2-BE …
…into feature/94-member-update
- Loading branch information
Showing
158 changed files
with
1,811 additions
and
1,514 deletions.
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
11 changes: 11 additions & 0 deletions
11
module-domain/src/main/java/com/depromeet/auth/port/in/usecase/CreateTokenUseCase.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.depromeet.auth.port.in.usecase; | ||
|
||
import com.depromeet.auth.vo.AccessTokenInfo; | ||
import com.depromeet.auth.vo.JwtToken; | ||
import com.depromeet.member.domain.MemberRole; | ||
|
||
public interface CreateTokenUseCase { | ||
JwtToken generateToken(Long memberId, MemberRole memberRole); | ||
|
||
AccessTokenInfo generateAccessToken(String refreshToken); | ||
} |
10 changes: 10 additions & 0 deletions
10
module-domain/src/main/java/com/depromeet/auth/port/in/usecase/SocialUseCase.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.depromeet.auth.port.in.usecase; | ||
|
||
import com.depromeet.auth.vo.kakao.KakaoAccountProfile; | ||
import com.depromeet.dto.auth.AccountProfileResponse; | ||
|
||
public interface SocialUseCase { | ||
AccountProfileResponse getGoogleAccountProfile(String code); | ||
|
||
KakaoAccountProfile getKakaoAccountProfile(String code); | ||
} |
7 changes: 7 additions & 0 deletions
7
module-domain/src/main/java/com/depromeet/auth/port/out/GooglePort.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,7 @@ | ||
package com.depromeet.auth.port.out; | ||
|
||
import com.depromeet.dto.auth.AccountProfileResponse; | ||
|
||
public interface GooglePort { | ||
AccountProfileResponse getGoogleAccountProfile(String code); | ||
} |
7 changes: 7 additions & 0 deletions
7
module-domain/src/main/java/com/depromeet/auth/port/out/KakaoPort.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,7 @@ | ||
package com.depromeet.auth.port.out; | ||
|
||
import com.depromeet.auth.vo.kakao.KakaoAccountProfile; | ||
|
||
public interface KakaoPort { | ||
KakaoAccountProfile getKakaoAccountProfile(final String code); | ||
} |
18 changes: 18 additions & 0 deletions
18
module-domain/src/main/java/com/depromeet/auth/port/out/SecurityPort.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,18 @@ | ||
package com.depromeet.auth.port.out; | ||
|
||
import com.depromeet.auth.vo.AccessTokenInfo; | ||
import com.depromeet.auth.vo.RefreshTokenInfo; | ||
import com.depromeet.member.domain.MemberRole; | ||
import java.util.Optional; | ||
|
||
public interface SecurityPort { | ||
AccessTokenInfo generateAccessToken(Long memberId, MemberRole memberRole); | ||
|
||
RefreshTokenInfo generateRefreshToken(Long memberId, MemberRole memberRole); | ||
|
||
String findTokenType(String token); | ||
|
||
Optional<AccessTokenInfo> parseAccessToken(String token); | ||
|
||
Optional<RefreshTokenInfo> parseRefreshToken(String token); | ||
} |
90 changes: 90 additions & 0 deletions
90
module-domain/src/main/java/com/depromeet/auth/service/JwtTokenService.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,90 @@ | ||
package com.depromeet.auth.service; | ||
|
||
import com.depromeet.auth.port.in.usecase.CreateTokenUseCase; | ||
import com.depromeet.auth.port.out.SecurityPort; | ||
import com.depromeet.auth.vo.AccessTokenInfo; | ||
import com.depromeet.auth.vo.JwtToken; | ||
import com.depromeet.auth.vo.RefreshTokenInfo; | ||
import com.depromeet.constant.SecurityConstant; | ||
import com.depromeet.exception.ForbiddenException; | ||
import com.depromeet.exception.NotFoundException; | ||
import com.depromeet.exception.UnauthorizedException; | ||
import com.depromeet.member.domain.Member; | ||
import com.depromeet.member.domain.MemberRole; | ||
import com.depromeet.member.port.out.persistence.MemberPersistencePort; | ||
import com.depromeet.type.auth.AuthErrorType; | ||
import com.depromeet.type.member.MemberErrorType; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class JwtTokenService implements CreateTokenUseCase { | ||
private final SecurityPort securityPort; | ||
private final MemberPersistencePort memberPersistencePort; | ||
|
||
public JwtToken generateToken(Long memberId, MemberRole memberRole) { | ||
AccessTokenInfo accessTokenInfo = securityPort.generateAccessToken(memberId, memberRole); | ||
RefreshTokenInfo refreshTokenInfo = securityPort.generateRefreshToken(memberId, memberRole); | ||
|
||
memberPersistencePort.updateRefresh(memberId, refreshTokenInfo.refreshToken()); | ||
|
||
return new JwtToken( | ||
memberId, | ||
SecurityConstant.BEARER_PREFIX.getValue() + accessTokenInfo.accessToken(), | ||
SecurityConstant.BEARER_PREFIX.getValue() + refreshTokenInfo.refreshToken()); | ||
} | ||
|
||
public String findTokenType(String token) { | ||
return securityPort.findTokenType(token); | ||
} | ||
|
||
public Optional<AccessTokenInfo> parseAccessToken(String token) { | ||
return securityPort.parseAccessToken(token); | ||
} | ||
|
||
public Optional<RefreshTokenInfo> parseRefreshToken(String token) { | ||
return securityPort.parseRefreshToken(token); | ||
} | ||
|
||
public AccessTokenInfo generateAccessToken(String refreshToken) { | ||
return reissueAccessToken(refreshToken); | ||
} | ||
|
||
public AccessTokenInfo reissueAccessToken(String refreshToken) { | ||
RefreshTokenInfo refreshTokenInfo = | ||
parseRefreshToken(refreshToken) | ||
.orElseThrow( | ||
() -> | ||
new UnauthorizedException( | ||
AuthErrorType.INVALID_JWT_REFRESH_TOKEN)); | ||
|
||
Long memberId = refreshTokenInfo.memberId(); | ||
Member member = | ||
memberPersistencePort | ||
.findById(memberId) | ||
.orElseThrow(() -> new NotFoundException(MemberErrorType.NOT_FOUND)); | ||
|
||
if (member.getRefreshToken() != null && member.getRefreshToken().equals(refreshToken)) { | ||
MemberRole memberRole = member.getRole(); | ||
return securityPort.generateAccessToken(memberId, memberRole); | ||
} else { | ||
throw new ForbiddenException(AuthErrorType.REFRESH_TOKEN_NOT_MATCH); | ||
} | ||
} | ||
|
||
public RefreshTokenInfo retrieveRefreshToken( | ||
RefreshTokenInfo refreshTokenInfoDto, String refreshToken) { | ||
Member member = | ||
memberPersistencePort | ||
.findById(refreshTokenInfoDto.memberId()) | ||
.orElseThrow(() -> new NotFoundException(MemberErrorType.NOT_FOUND)); | ||
if (member.getRefreshToken() != null && member.getRefreshToken().equals(refreshToken)) { | ||
return refreshTokenInfoDto; | ||
} | ||
throw new ForbiddenException(AuthErrorType.REFRESH_TOKEN_NOT_MATCH); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
module-domain/src/main/java/com/depromeet/auth/service/SocialService.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,26 @@ | ||
package com.depromeet.auth.service; | ||
|
||
import com.depromeet.auth.port.in.usecase.SocialUseCase; | ||
import com.depromeet.auth.port.out.GooglePort; | ||
import com.depromeet.auth.port.out.KakaoPort; | ||
import com.depromeet.auth.vo.kakao.KakaoAccountProfile; | ||
import com.depromeet.dto.auth.AccountProfileResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SocialService implements SocialUseCase { | ||
private final KakaoPort kakaoPort; | ||
private final GooglePort googlePort; | ||
|
||
@Override | ||
public AccountProfileResponse getGoogleAccountProfile(String code) { | ||
return googlePort.getGoogleAccountProfile(code); | ||
} | ||
|
||
@Override | ||
public KakaoAccountProfile getKakaoAccountProfile(String code) { | ||
return kakaoPort.getKakaoAccountProfile(code); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
module-domain/src/main/java/com/depromeet/auth/vo/AccessTokenInfo.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,5 @@ | ||
package com.depromeet.auth.vo; | ||
|
||
import com.depromeet.member.domain.MemberRole; | ||
|
||
public record AccessTokenInfo(Long memberId, MemberRole memberRole, String accessToken) {} |
11 changes: 11 additions & 0 deletions
11
module-domain/src/main/java/com/depromeet/auth/vo/JwtToken.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.depromeet.auth.vo; | ||
|
||
import java.util.Objects; | ||
|
||
public record JwtToken(Long userId, String accessToken, String refreshToken) { | ||
public JwtToken { | ||
Objects.requireNonNull(userId); | ||
Objects.requireNonNull(accessToken); | ||
Objects.requireNonNull(refreshToken); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
module-domain/src/main/java/com/depromeet/auth/vo/RefreshTokenInfo.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,5 @@ | ||
package com.depromeet.auth.vo; | ||
|
||
import com.depromeet.member.domain.MemberRole; | ||
|
||
public record RefreshTokenInfo(Long memberId, MemberRole memberRole, String refreshToken) {} |
7 changes: 7 additions & 0 deletions
7
module-domain/src/main/java/com/depromeet/auth/vo/kakao/KakaoAccountInfo.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,7 @@ | ||
package com.depromeet.auth.vo.kakao; | ||
|
||
public record KakaoAccountInfo(String email, KakaoProfileInfo profileInfo) { | ||
public static KakaoAccountInfo of(String email, String nickname) { | ||
return new KakaoAccountInfo(email, KakaoProfileInfo.of(nickname)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
module-domain/src/main/java/com/depromeet/auth/vo/kakao/KakaoAccountProfile.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,7 @@ | ||
package com.depromeet.auth.vo.kakao; | ||
|
||
public record KakaoAccountProfile(String id, KakaoAccountInfo accountInfo) { | ||
public static KakaoAccountProfile of(String id, String email, String nickname) { | ||
return new KakaoAccountProfile(id, KakaoAccountInfo.of(email, nickname)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
module-domain/src/main/java/com/depromeet/auth/vo/kakao/KakaoProfileInfo.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,7 @@ | ||
package com.depromeet.auth.vo.kakao; | ||
|
||
public record KakaoProfileInfo(String nickname) { | ||
public static KakaoProfileInfo of(String nickname) { | ||
return new KakaoProfileInfo(nickname); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
module-domain/src/main/java/com/depromeet/image/domain/Image.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
module-domain/src/main/java/com/depromeet/image/port/in/ImageUpdateUseCase.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
module-domain/src/main/java/com/depromeet/image/port/in/ImageUploadUseCase.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
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
...ain/java/com/depromeet/member/Member.java → ...a/com/depromeet/member/domain/Member.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,4 +1,4 @@ | ||
package com.depromeet.member; | ||
package com.depromeet.member.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
2 changes: 1 addition & 1 deletion
2
...java/com/depromeet/member/MemberRole.java → ...m/depromeet/member/domain/MemberRole.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
3 changes: 3 additions & 0 deletions
3
module-domain/src/main/java/com/depromeet/member/port/in/command/CreateMemberCommand.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,3 @@ | ||
package com.depromeet.member.port.in.command; | ||
|
||
public record CreateMemberCommand(String name, String email) {} |
3 changes: 3 additions & 0 deletions
3
module-domain/src/main/java/com/depromeet/member/port/in/command/SocialMemberCommand.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,3 @@ | ||
package com.depromeet.member.port.in.command; | ||
|
||
public record SocialMemberCommand(String id, String name, String email) {} |
Empty file.
7 changes: 7 additions & 0 deletions
7
module-domain/src/main/java/com/depromeet/member/port/in/usecase/GoalUpdateUseCase.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,7 @@ | ||
package com.depromeet.member.port.in.usecase; | ||
|
||
import com.depromeet.member.domain.Member; | ||
|
||
public interface GoalUpdateUseCase { | ||
Member updateGoal(Long memberId, Integer goal); | ||
} |
10 changes: 10 additions & 0 deletions
10
module-domain/src/main/java/com/depromeet/member/port/in/usecase/MemberUseCase.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.depromeet.member.port.in.usecase; | ||
|
||
import com.depromeet.member.domain.Member; | ||
import com.depromeet.member.port.in.command.SocialMemberCommand; | ||
|
||
public interface MemberUseCase { | ||
Member findById(Long id); | ||
|
||
Member findOrCreateMemberBy(SocialMemberCommand command); | ||
} |
16 changes: 16 additions & 0 deletions
16
...domain/src/main/java/com/depromeet/member/port/out/persistence/MemberPersistencePort.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,16 @@ | ||
package com.depromeet.member.port.out.persistence; | ||
|
||
import com.depromeet.member.domain.Member; | ||
import java.util.Optional; | ||
|
||
public interface MemberPersistencePort { | ||
Optional<Member> findByEmail(String email); | ||
|
||
Optional<Member> findById(Long id); | ||
|
||
Member save(Member member); | ||
|
||
void updateRefresh(Long memberId, String refreshToken); | ||
|
||
Optional<Member> updateGoal(Long memberId, Integer goal); | ||
} |
52 changes: 52 additions & 0 deletions
52
module-domain/src/main/java/com/depromeet/member/service/MemberService.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,52 @@ | ||
package com.depromeet.member.service; | ||
|
||
import com.depromeet.exception.InternalServerException; | ||
import com.depromeet.exception.NotFoundException; | ||
import com.depromeet.member.domain.Member; | ||
import com.depromeet.member.domain.MemberRole; | ||
import com.depromeet.member.port.in.command.SocialMemberCommand; | ||
import com.depromeet.member.port.in.usecase.GoalUpdateUseCase; | ||
import com.depromeet.member.port.in.usecase.MemberUseCase; | ||
import com.depromeet.member.port.out.persistence.MemberPersistencePort; | ||
import com.depromeet.type.member.MemberErrorType; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class MemberService implements MemberUseCase, GoalUpdateUseCase { | ||
private final MemberPersistencePort memberPersistencePort; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public Member findById(Long id) { | ||
return memberPersistencePort | ||
.findById(id) | ||
.orElseThrow(() -> new NotFoundException(MemberErrorType.NOT_FOUND)); | ||
} | ||
|
||
@Override | ||
public Member findOrCreateMemberBy(SocialMemberCommand command) { | ||
return memberPersistencePort | ||
.findByEmail(command.email()) | ||
.orElseGet( | ||
() -> { | ||
Member member = | ||
Member.builder() | ||
.name(command.name()) | ||
.email(command.email()) | ||
.role(MemberRole.USER) | ||
.build(); | ||
return memberPersistencePort.save(member); | ||
}); | ||
} | ||
|
||
@Override | ||
public Member updateGoal(Long memberId, Integer goal) { | ||
return memberPersistencePort | ||
.updateGoal(memberId, goal) | ||
.orElseThrow(() -> new InternalServerException(MemberErrorType.UPDATE_GOAL_FAILED)); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ain/java/com/depromeet/memory/Memory.java → ...a/com/depromeet/memory/domain/Memory.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
Oops, something went wrong.