-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 팔로잉 조회 여부 api 개발 #106
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
399b64c
[feat] 팔로잉 테이블 소프트 삭제 전략 해제(#100)
buzz0331 73d8989
[fix] 팔로잉 테이블 소프트 삭제 전략 해제에 따른 팔로잉 상태 변경 api 수정(#100)
buzz0331 66613c7
[feat] 팔로잉 여부 조회 api 구현 (#100)
buzz0331 8fb4c36
[feat] 에러코드 수정 (#100)
buzz0331 b5683a0
[fix] 오타 수정 (#100)
buzz0331 561d7fc
[fix] 오타 수정 (#100)
buzz0331 bf0a26c
[fix] NPE 검증 (#100)
buzz0331 4e1d9e3
[fix] 클린 아키텍처 기반 의존성 수정 (#100)
buzz0331 49b10f2
[refactor] usecase에서 primitive 타입 반환 (#100)
buzz0331 410be15
[rename] FollowDtoMapper -> FollowQueryMapper 네이밍 수정 (#100)
buzz0331 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
9 changes: 9 additions & 0 deletions
9
src/main/java/konkuk/thip/user/adapter/in/web/response/UserIsFollowingResponse.java
This file contains hidden or 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,9 @@ | ||
| package konkuk.thip.user.adapter.in.web.response; | ||
|
|
||
| public record UserIsFollowingResponse( | ||
| boolean isFollowing | ||
| ) { | ||
| public static UserIsFollowingResponse of(boolean isFollowing) { | ||
| return new UserIsFollowingResponse(isFollowing); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
5 changes: 5 additions & 0 deletions
5
src/main/java/konkuk/thip/user/application/port/in/UserIsFollowingUsecase.java
This file contains hidden or 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 konkuk.thip.user.application.port.in; | ||
|
|
||
| public interface UserIsFollowingUsecase { | ||
| boolean isFollowing(Long userId, Long targetUserId); | ||
| } |
This file contains hidden or 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,5 +1,7 @@ | ||
| package konkuk.thip.user.application.port.out; | ||
|
|
||
| import konkuk.thip.common.exception.EntityNotFoundException; | ||
| import konkuk.thip.common.exception.code.ErrorCode; | ||
| import konkuk.thip.user.domain.Following; | ||
| import konkuk.thip.user.domain.User; | ||
|
|
||
|
|
@@ -9,7 +11,12 @@ public interface FollowingCommandPort { | |
|
|
||
| Optional<Following> findByUserIdAndTargetUserId(Long userId, Long targetUserId); | ||
|
|
||
| default Following getByUserIdAndTargetUserIdOrThrow(Long userId, Long targetUserId) { | ||
| return findByUserIdAndTargetUserId(userId, targetUserId) | ||
| .orElseThrow(() -> new EntityNotFoundException(ErrorCode.FOLLOW_NOT_FOUND)); | ||
| } | ||
|
Comment on lines
12
to
+17
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
|
|
||
| void save(Following following, User targetUser); | ||
|
|
||
| void updateStatus(Following following, User targetUser); | ||
| void deleteFollowing(Following following, User targetUser); | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
src/main/java/konkuk/thip/user/application/service/UserIsFollowingService.java
This file contains hidden or 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,19 @@ | ||
| package konkuk.thip.user.application.service; | ||
|
|
||
| import konkuk.thip.user.application.port.in.UserIsFollowingUsecase; | ||
| import konkuk.thip.user.application.port.out.FollowingCommandPort; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class UserIsFollowingService implements UserIsFollowingUsecase { | ||
|
|
||
| private final FollowingCommandPort followingCommandPort; | ||
|
|
||
| @Override | ||
| public boolean isFollowing(Long userId, Long targetUserId) { | ||
| return followingCommandPort.findByUserIdAndTargetUserId(userId, targetUserId) | ||
| .isPresent(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
90 changes: 90 additions & 0 deletions
90
src/test/java/konkuk/thip/user/adapter/in/web/UserIsFollowingApiTest.java
This file contains hidden or 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 konkuk.thip.user.adapter.in.web; | ||
|
|
||
| import konkuk.thip.common.util.TestEntityFactory; | ||
| import konkuk.thip.user.adapter.out.jpa.AliasJpaEntity; | ||
| import konkuk.thip.user.adapter.out.jpa.FollowingJpaEntity; | ||
| import konkuk.thip.user.adapter.out.jpa.UserJpaEntity; | ||
| import konkuk.thip.user.adapter.out.persistence.repository.UserJpaRepository; | ||
| import konkuk.thip.user.adapter.out.persistence.repository.alias.AliasJpaRepository; | ||
| import konkuk.thip.user.adapter.out.persistence.repository.following.FollowingJpaRepository; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
|
|
||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| @SpringBootTest | ||
| @ActiveProfiles("test") | ||
| @AutoConfigureMockMvc(addFilters = false) | ||
| @DisplayName("[통합] 팔로잉 여부 조회 API 통합 테스트") | ||
| class UserIsFollowingApiTest { | ||
|
|
||
| @Autowired | ||
| private MockMvc mockMvc; | ||
|
|
||
| @Autowired | ||
| private UserJpaRepository userJpaRepository; | ||
|
|
||
| @Autowired | ||
| private AliasJpaRepository aliasJpaRepository; | ||
|
|
||
| @Autowired | ||
| private FollowingJpaRepository followingJpaRepository; | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| followingJpaRepository.deleteAllInBatch(); | ||
| userJpaRepository.deleteAll(); | ||
| aliasJpaRepository.deleteAll(); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("팔로우 관계가 존재하면 true를 반환한다.") | ||
| void isFollowing_true() throws Exception { | ||
| // given | ||
| AliasJpaEntity alias = aliasJpaRepository.save(TestEntityFactory.createScienceAlias()); | ||
|
|
||
| UserJpaEntity user = userJpaRepository.save(TestEntityFactory.createUser(alias)); | ||
|
|
||
| UserJpaEntity target = userJpaRepository.save(TestEntityFactory.createUser(alias)); | ||
|
|
||
| // 팔로잉 관계 저장 | ||
| followingJpaRepository.save(FollowingJpaEntity.builder() | ||
| .userJpaEntity(user) | ||
| .followingUserJpaEntity(target) | ||
| .build()); | ||
|
|
||
| // when & then | ||
| mockMvc.perform(get("/users/{targetUserId}/is-following", target.getUserId()) | ||
| .requestAttr("userId", user.getUserId()) | ||
| .contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.data.isFollowing").value(true)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("팔로우 관계가 없으면 false를 반환한다.") | ||
| void isFollowing_false() throws Exception { | ||
| // given | ||
| AliasJpaEntity alias = aliasJpaRepository.save(TestEntityFactory.createScienceAlias()); | ||
|
|
||
| UserJpaEntity user = userJpaRepository.save(TestEntityFactory.createUser(alias)); | ||
|
|
||
| UserJpaEntity target = userJpaRepository.save(TestEntityFactory.createUser(alias)); | ||
|
|
||
| // when & then | ||
| mockMvc.perform(get("/users/{targetUserId}/is-following", target.getUserId()) | ||
| .requestAttr("userId", user.getUserId()) | ||
| .contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.data.isFollowing").value(false)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.