Skip to content

Commit

Permalink
feat: 회원 조회 시 그룹 정보 함께 조회 구현 (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywonchae1 committed Nov 23, 2024
1 parent 4d0c6d7 commit 22b294a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ioteatime.meonghanyangserver.auth.mapper;

import org.ioteatime.meonghanyangserver.auth.dto.db.LoginWithMemberInfo;
import org.ioteatime.meonghanyangserver.auth.dto.reponse.LoginResponse;
import org.ioteatime.meonghanyangserver.auth.dto.reponse.RefreshResponse;
import org.ioteatime.meonghanyangserver.member.dto.response.MemberSimpleResponse;
Expand All @@ -9,11 +10,14 @@ public static MemberSimpleResponse from(Long id, String email) {
return new MemberSimpleResponse(id, email);
}

public static LoginResponse from(Long id, String accessToken, String refreshToken) {
public static LoginResponse from(
LoginWithMemberInfo memberInfo, String accessToken, String refreshToken) {
return LoginResponse.builder()
.memberId(id)
.memberId(memberInfo.memberId())
.accessToken(accessToken)
.refreshToken(refreshToken)
.isGroupMember(memberInfo.isGroupMember())
.role(memberInfo.role())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ThreadLocalRandom;
import lombok.RequiredArgsConstructor;
import org.ioteatime.meonghanyangserver.auth.dto.db.LoginWithMemberInfo;
import org.ioteatime.meonghanyangserver.auth.dto.reponse.LoginResponse;
import org.ioteatime.meonghanyangserver.auth.dto.request.LoginRequest;
import org.ioteatime.meonghanyangserver.auth.mapper.AuthEntityMapper;
Expand Down Expand Up @@ -39,34 +40,36 @@ public class AuthService {
private final RefreshTokenRepository refreshTokenRepository;

public LoginResponse login(LoginRequest loginRequest) {
MemberEntity memberEntity =
LoginWithMemberInfo memberInfo =
memberRepository
.findByEmail(loginRequest.email())
.findGroupMemberInfoByEmail(loginRequest.email())
.orElseThrow(() -> new NotFoundException(AuthErrorType.NOT_FOUND));

boolean passwordMatch =
bCryptPasswordEncoder.matches(loginRequest.password(), memberEntity.getPassword());
bCryptPasswordEncoder.matches(loginRequest.password(), memberInfo.password());
if (!passwordMatch) {
throw new BadRequestException(AuthErrorType.PASSWORD_NOT_MATCH);
}

String accessToken = jwtUtils.generateAccessToken(memberEntity);
String refreshToken = jwtUtils.generateRefreshToken(memberEntity);
String accessToken =
jwtUtils.generateAccessToken(memberInfo.nickname(), memberInfo.memberId());
String refreshToken =
jwtUtils.generateRefreshToken(memberInfo.nickname(), memberInfo.memberId());

if (accessToken.isEmpty() || refreshToken.isEmpty()) {
throw new NotFoundException(AuthErrorType.TOKEN_NOT_FOUND);
}
RefreshToken refreshTokenEntity =
RefreshToken.builder()
.memberId(memberEntity.getId())
.memberId(memberInfo.memberId())
.refreshToken(refreshToken)
.build();

refreshTokenRepository.save(refreshTokenEntity);
accessToken = jwtUtils.includeBearer(accessToken);
refreshToken = jwtUtils.includeBearer(refreshToken);

return AuthResponseMapper.from(memberEntity.getId(), accessToken, refreshToken);
return AuthResponseMapper.from(memberInfo, accessToken, refreshToken);
}

public MemberSimpleResponse joinProcess(JoinRequest userDto) {
Expand Down

0 comments on commit 22b294a

Please sign in to comment.