Skip to content

Commit

Permalink
fix: 카카오토큰 영속화 (#19)
Browse files Browse the repository at this point in the history
* fix: 카카오토큰 영속화 작업

* fix: 카카오토큰 영속화 작업
  • Loading branch information
GitJIHO authored Sep 21, 2024
1 parent 81c6742 commit 88f4b46
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 5 deletions.
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

0 comments on commit 88f4b46

Please sign in to comment.