Skip to content
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

fix: 카카오토큰 영속화 #19

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .gradle/8.10/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/8.10/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified .gradle/8.10/checksums/sha1-checksums.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file modified out/production/classes/com/knu/daeguhackathon/member/Member.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.knu.daeguhackathon.kakaotoken.repository;

import com.knu.daeguhackathon.kakaotoken.KakaoToken;
import com.knu.daeguhackathon.member.Member;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -11,4 +12,6 @@ public interface KakaoTokenRepository extends JpaRepository<KakaoToken, Long> {
Optional<KakaoToken> findByAccessToken(String accessToken);

Optional<KakaoToken> findByMemberId(Long memberId);

KakaoToken findByMember(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ public class KakaoTokenService {
private final MemberRepository memberRepository;

@Transactional
public KakaoToken saveKakaoToken(String email, KakaoTokenResponse tokenInfo) {
public void saveKakaoToken(String email, KakaoTokenResponse tokenInfo) {

Member member = memberRepository.findByEmail(email).orElseThrow(
() -> new RuntimeException("이메일에 해당하는 Member가 없습니다")
);

KakaoToken kakaoToken = KakaoToken.builder()
.member(member)
.accessToken(tokenInfo.accessToken())
.refreshToken(tokenInfo.refreshToken())
.expires_in(tokenInfo.expiresIn())
.issuedAt(LocalDateTime.now())
.updated_at(LocalDateTime.now())
.build();

return kakaoTokenRepository.save(kakaoToken);
KakaoToken savedToken = kakaoTokenRepository.save(kakaoToken);

member.setKakaoToken(savedToken);
}

@Transactional
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/knu/daeguhackathon/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Member extends BaseTimeEntity {
private LocalDateTime createdTime;
private int speed;
private String nickName;
@OneToOne
@OneToOne(cascade = CascadeType.PERSIST)
private KakaoToken kakaoToken;
@OneToMany(mappedBy = "member", cascade = CascadeType.REMOVE)
private List<Subject> subjects = new ArrayList<>();
Expand Down