Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
stoneHee99 authored Jan 8, 2024
2 parents 0b5158f + 1f5b5d4 commit caf981a
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import kr.co.yigil.follow.dto.FollowCountDto;
import kr.co.yigil.member.domain.Member;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;


@Getter
@AllArgsConstructor
@RedisHash("followCount")
Expand All @@ -14,7 +15,8 @@ public class FollowCount {
@Id
private Long memberId;

private int followerCount;
private final int followerCount;

private final int followingCount;

private int followingCount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public interface FollowRepository extends JpaRepository<Follow, Long> {

@Query("SELECT new kr.co.yigil.follow.dto.FollowCountDto(" +
" (SELECT COUNT(f1) FROM Follow f1 WHERE f1.following = :member), " +
" (SELECT COUNT(f2) FROM Follow f2 WHERE f2.follower = :member))")
" (SELECT COUNT(f2) FROM Follow f2 WHERE f2.follower = :member)) " +
"FROM Follow f WHERE f.follower = :member OR f.following = :member")
FollowCountDto getFollowCounts(@Param("member") Member member);

public void deleteByFollowerAndFollowing(Member Follower, Member Following);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

import jakarta.servlet.http.HttpSession;
import kr.co.yigil.login.dto.request.LoginRequest;
import kr.co.yigil.login.dto.response.GoogleTokenInfoResponse;
import kr.co.yigil.login.dto.response.LoginResponse;
import kr.co.yigil.member.domain.Member;
import kr.co.yigil.member.domain.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class GoogleLoginStrategy implements LoginStrategy{

private static final String PROVIDER_NAME = "google";

private final MemberRepository memberRepository;


@Override
public LoginResponse login(LoginRequest request, String accessToken, HttpSession session) {
return new LoginResponse();
Expand All @@ -15,4 +29,21 @@ public LoginResponse login(LoginRequest request, String accessToken, HttpSession
public String getProviderName() {
return "google";
}

private boolean isTokenValid(String accessToken, Long expectedUserId) {
GoogleTokenInfoResponse tokenInfo = requestGoogleTokenInfo(accessToken);
return isUserIdValid(tokenInfo, expectedUserId);
}

private GoogleTokenInfoResponse requestGoogleTokenInfo(String accessToken) {
return null;
}

private boolean isUserIdValid(GoogleTokenInfoResponse tokenInfo, Long expectedUserId) {
return false;
}

private Member registerNewMember(LoginRequest request) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@PropertySource("classpath:url.properties")
public class KakaoLoginStrategy implements LoginStrategy {

private final String PROVIDER_NAME = "kakao";
private final static String PROVIDER_NAME = "kakao";

@Value("${kakao.token.info.url}")
private String KAKAO_TOKEN_INFO_URL;
Expand Down Expand Up @@ -82,7 +82,6 @@ private KakaoTokenInfoResponse requestKakaoTokenInfo(String accessToken) {

return response.getBody();
} catch (Exception e) {
log.warn(e.getMessage(), e);
throw new InvalidTokenException(INVALID_ACCESS_TOKEN);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kr.co.yigil.login.dto.response;

import lombok.Data;

@Data
public class GoogleTokenInfoResponse {

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import kr.co.yigil.post.domain.repository.PostRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -34,6 +33,7 @@ public class MemberService {
private final MemberRepository memberRepository;
private final PostRepository postRepository;
private final FollowRepository followRepository;
private final FollowCountRepository followCountRepository;
private final FollowRedisIntegrityService followRedisIntegrityService;
private final ApplicationEventPublisher applicationEventPublisher;

Expand Down
5 changes: 5 additions & 0 deletions backend/src/main/java/kr/co/yigil/test/testController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package kr.co.yigil.test;

import jakarta.servlet.http.HttpSession;
import kr.co.yigil.member.domain.Member;
import kr.co.yigil.member.domain.SocialLoginType;
import kr.co.yigil.member.domain.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -10,6 +13,8 @@
@RequiredArgsConstructor
public class testController {

private final MemberRepository repository;

@PostMapping("/test")
public ResponseEntity<String> loginTest(HttpSession session) {
session.setAttribute("memberId", 1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;


public class FollowRedisIntegrityServiceTest {

@Mock
Expand All @@ -31,6 +32,7 @@ public class FollowRedisIntegrityServiceTest {
@InjectMocks
private FollowRedisIntegrityService followRedisIntegrityService;


@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
Expand Down Expand Up @@ -75,4 +77,6 @@ void testEnsureFollowCountsWhenNotExists() {
verify(followRepository).getFollowCounts(member);
verify(followCountRepository).save((FollowCount) any());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.mock.web.MockMultipartFile;

public class MemberServiceTest {
Expand All @@ -52,10 +50,10 @@ public class MemberServiceTest {
private MemberService memberService;

@Mock
private RedisTemplate<String, Object> redisTemplate;
private FollowRepository followRepository;

@Mock
private FollowRepository followRepository;
private FollowRedisIntegrityService followRedisIntegrityService;

@Mock
private FollowRedisIntegrityService followRedisIntegrityService;
Expand Down

0 comments on commit caf981a

Please sign in to comment.