diff --git a/src/main/java/com/listywave/list/application/domain/list/ListEntity.java b/src/main/java/com/listywave/list/application/domain/list/ListEntity.java index bca172d6..825a7eb5 100644 --- a/src/main/java/com/listywave/list/application/domain/list/ListEntity.java +++ b/src/main/java/com/listywave/list/application/domain/list/ListEntity.java @@ -229,8 +229,8 @@ public void validateHasItem(Item item) { } } - public void updateVisibility(Boolean isPublic) { - this.isPublic = isPublic; + public void updateVisibility() { + this.isPublic = !this.isPublic; } public String getRepresentImageUrl() { diff --git a/src/main/java/com/listywave/list/application/service/ListService.java b/src/main/java/com/listywave/list/application/service/ListService.java index 05a26fac..3ef99ab6 100644 --- a/src/main/java/com/listywave/list/application/service/ListService.java +++ b/src/main/java/com/listywave/list/application/service/ListService.java @@ -304,4 +304,11 @@ public FindFeedListResponse findFeedList( } return FindFeedListResponse.of(result.hasNext(), cursorUpdatedDate, lists); } + + public void changeVisibility(Long loginUserId, Long listId) { + User user = userRepository.getById(loginUserId); + ListEntity list = listRepository.getById(listId); + list.validateOwner(user); + list.updateVisibility(); + } } diff --git a/src/main/java/com/listywave/list/presentation/controller/ListController.java b/src/main/java/com/listywave/list/presentation/controller/ListController.java index 10bfdd7d..3b79e8c4 100644 --- a/src/main/java/com/listywave/list/presentation/controller/ListController.java +++ b/src/main/java/com/listywave/list/presentation/controller/ListController.java @@ -120,6 +120,15 @@ ResponseEntity deleteLists( @RequestBody ListsDeleteRequest request ) { listService.deleteLists(userId, request.listId()); - return ResponseEntity.ok().build(); + return ResponseEntity.noContent().build(); + } + + @PatchMapping("/lists/{listId}/visibility") + ResponseEntity changeVisibility( + @Auth Long loginUserId, + @PathVariable("listId") Long listId + ) { + listService.changeVisibility(loginUserId, listId); + return ResponseEntity.noContent().build(); } } diff --git a/src/main/java/com/listywave/user/application/service/UserService.java b/src/main/java/com/listywave/user/application/service/UserService.java index dc7b4f69..d4f1afe5 100644 --- a/src/main/java/com/listywave/user/application/service/UserService.java +++ b/src/main/java/com/listywave/user/application/service/UserService.java @@ -36,7 +36,6 @@ @RequiredArgsConstructor public class UserService { - private final ListRepository listRepository; private final UserRepository userRepository; private final FollowRepository followRepository; private final UserElasticRepository userElasticRepository; @@ -175,14 +174,6 @@ public void deleteFollower(Long followerUserId, Long followingUserId) { followingUser.remove(followerUser); } - public void updateListVisibility(Long loginUserId, Long listId, Boolean beforeIsPublic) { - User user = userRepository.getById(loginUserId); - ListEntity list = listRepository.getById(listId); - list.validateOwner(user); - - list.updateVisibility(!beforeIsPublic); - } - @Transactional(readOnly = true) public UserElasticSearchResponse searchUserByElastic(@Nullable Long loginUserId, String keyword, Pageable pageable) { if (loginUserId == null) { diff --git a/src/main/java/com/listywave/user/presentation/UserController.java b/src/main/java/com/listywave/user/presentation/UserController.java index 49abbe21..f7f2e8b2 100644 --- a/src/main/java/com/listywave/user/presentation/UserController.java +++ b/src/main/java/com/listywave/user/presentation/UserController.java @@ -122,15 +122,6 @@ ResponseEntity deleteFollower( return ResponseEntity.noContent().build(); } - @PatchMapping("/users/list-visibility") - ResponseEntity updateListVisibility( - @Auth Long loginUserId, - @RequestBody ListVisibilityUpdateRequest request - ) { - userService.updateListVisibility(loginUserId, request.listId(), request.isPublic()); - return ResponseEntity.ok().build(); - } - @GetMapping("/v2/users") ResponseEntity searchUserByElastic( @OptionalAuth Long loginUserId, diff --git a/src/test/java/com/listywave/acceptance/list/ListAcceptanceTest.java b/src/test/java/com/listywave/acceptance/list/ListAcceptanceTest.java index 6a131607..734fb28e 100644 --- a/src/test/java/com/listywave/acceptance/list/ListAcceptanceTest.java +++ b/src/test/java/com/listywave/acceptance/list/ListAcceptanceTest.java @@ -5,32 +5,7 @@ import static com.listywave.acceptance.comment.CommentAcceptanceTestHelper.댓글_저장_API_호출; import static com.listywave.acceptance.common.CommonAcceptanceHelper.HTTP_상태_코드를_검증한다; import static com.listywave.acceptance.follow.FollowAcceptanceTestHelper.팔로우_요청_API; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.가장_좋아하는_견종_TOP3_생성_요청_데이터; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.검색_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.리스트_삭제_요청_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.리스트_상세_조회를_검증한다; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.리스트_수정_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.리스트_저장_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.리스트의_아이템_순위와_히스토리의_아이템_순위를_검증한다; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원_리스트_상세_조회_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원_최신_리스트_10개_조회_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원_피드_리스트_조회_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원_히스토리_조회_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원이_피드_리스트_조회_카테고리_콜라보레이터_필터링_요청; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원이_피드_리스트_조회_카테고리_필터링_요청; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원이_피드_리스트_조회_콜라보레이터_필터링_요청; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.아이템_순위와_라벨을_바꾼_좋아하는_견종_TOP3_요청_데이터; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.정렬기준을_포함한_검색_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.좋아하는_라면_TOP3_생성_요청_데이터; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.카테고리로_검색_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.카테고리와_키워드로_검색_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.콜렉트_요청_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.키워드로_검색_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.키워드와_정렬기준을_포함한_검색_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.트랜딩_리스트_조회_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.회원_최신_리스트_10개_조회_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.회원_피드_리스트_조회; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.회원용_리스트_상세_조회_API_호출; +import static com.listywave.acceptance.list.ListAcceptanceTestHelper.*; import static com.listywave.acceptance.reply.ReplyAcceptanceTestHelper.답글_등록_API_호출; import static com.listywave.list.fixture.ListFixture.가장_좋아하는_견종_TOP3; import static com.listywave.list.fixture.ListFixture.가장_좋아하는_견종_TOP3_순위_변경; @@ -45,12 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; import static org.junit.jupiter.api.Assertions.assertAll; -import static org.springframework.http.HttpStatus.BAD_REQUEST; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.FORBIDDEN; -import static org.springframework.http.HttpStatus.NOT_FOUND; -import static org.springframework.http.HttpStatus.NO_CONTENT; -import static org.springframework.http.HttpStatus.UNAUTHORIZED; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.HttpStatus.OK; import com.listywave.acceptance.common.AcceptanceTest; import com.listywave.auth.infra.kakao.response.KakaoLogoutResponse; @@ -817,4 +788,63 @@ class 리스트_검색 { ); } } + + @Nested + class 내_리스트_공개_여부_설정 { + + @Test + void 내_공개_리스트_비공개로_설정() { + // given + var 정수 = 회원을_저장한다(정수()); + var 정수_액세스_토큰 = 액세스_토큰을_발급한다(정수); + var 정수_리스트_ID = 리스트_저장_API_호출(가장_좋아하는_견종_TOP3_생성_요청_데이터(List.of()), 정수_액세스_토큰) + .as(ListCreateResponse.class) + .listId(); + + // when + var 응답 = 리스트_공개_여부_변경_API_호출(정수_액세스_토큰, 정수_리스트_ID); + var 수정_이후_리스트_공개_여부_조회_결과 = 회원용_리스트_상세_조회_API_호출(정수_액세스_토큰, 정수_리스트_ID); + + // then + HTTP_상태_코드를_검증한다(응답, NO_CONTENT); + assertThat(수정_이후_리스트_공개_여부_조회_결과.isPublic()).isFalse(); + } + + @Test + void 내_비공개_리스트_공개로_설정() { + // given + var 정수 = 회원을_저장한다(정수()); + var 정수_액세스_토큰 = 액세스_토큰을_발급한다(정수); + var 정수_리스트_ID = 리스트_저장_API_호출(가장_좋아하는_견종_TOP3_생성_요청_데이터(List.of()), 정수_액세스_토큰) + .as(ListCreateResponse.class) + .listId(); + 리스트_공개_여부_변경_API_호출(정수_액세스_토큰, 정수_리스트_ID); + + // when + var 응답 = 리스트_공개_여부_변경_API_호출(정수_액세스_토큰, 정수_리스트_ID); + var 수정_이후_리스트_공개_여부_조회_결과 = 회원용_리스트_상세_조회_API_호출(정수_액세스_토큰, 정수_리스트_ID); + + // then + HTTP_상태_코드를_검증한다(응답, NO_CONTENT); + assertThat(수정_이후_리스트_공개_여부_조회_결과.isPublic()).isTrue(); + } + + @Test + void 내_리스트가_아니면_공개_여부_설정을_할_수_없다() { + // given + var 정수 = 회원을_저장한다(정수()); + var 동호 = 회원을_저장한다(동호()); + var 정수_액세스_토큰 = 액세스_토큰을_발급한다(정수); + var 동호_액세스_토큰 = 액세스_토큰을_발급한다(동호); + var 동호_리스트_ID = 리스트_저장_API_호출(가장_좋아하는_견종_TOP3_생성_요청_데이터(List.of()), 동호_액세스_토큰) + .as(ListCreateResponse.class) + .listId(); + + // when + var 응답 = 리스트_공개_여부_변경_API_호출(정수_액세스_토큰, 동호_리스트_ID); + + // then + HTTP_상태_코드를_검증한다(응답, FORBIDDEN); + } + } } diff --git a/src/test/java/com/listywave/acceptance/list/ListAcceptanceTestHelper.java b/src/test/java/com/listywave/acceptance/list/ListAcceptanceTestHelper.java index 2b00fa65..3d450b10 100644 --- a/src/test/java/com/listywave/acceptance/list/ListAcceptanceTestHelper.java +++ b/src/test/java/com/listywave/acceptance/list/ListAcceptanceTestHelper.java @@ -248,4 +248,12 @@ public abstract class ListAcceptanceTestHelper { .then().log().all() .extract(); } + + public static ExtractableResponse 리스트_공개_여부_변경_API_호출(String accessToken, Long listId) { + return given() + .header(AUTHORIZATION, "Bearer " + accessToken) + .when().patch("/lists/{listId}/visibility", listId) + .then().log().all() + .extract(); + } } diff --git a/src/test/java/com/listywave/acceptance/user/UserAcceptanceTest.java b/src/test/java/com/listywave/acceptance/user/UserAcceptanceTest.java index 939ab1b4..b3acbb74 100644 --- a/src/test/java/com/listywave/acceptance/user/UserAcceptanceTest.java +++ b/src/test/java/com/listywave/acceptance/user/UserAcceptanceTest.java @@ -2,22 +2,13 @@ import static com.listywave.acceptance.common.CommonAcceptanceHelper.HTTP_상태_코드를_검증한다; import static com.listywave.acceptance.follow.FollowAcceptanceTestHelper.팔로우_요청_API; -import static com.listywave.acceptance.user.UserAcceptanceTestHelper.닉네임_중복_체크_요청; -import static com.listywave.acceptance.user.UserAcceptanceTestHelper.비회원_회원_정보_조회_요청; -import static com.listywave.acceptance.user.UserAcceptanceTestHelper.비회원이_사용자_검색; -import static com.listywave.acceptance.user.UserAcceptanceTestHelper.추천_사용자_조회; -import static com.listywave.acceptance.user.UserAcceptanceTestHelper.프로필_수정_요청; -import static com.listywave.acceptance.user.UserAcceptanceTestHelper.프로필_수정_요청_데이터; -import static com.listywave.acceptance.user.UserAcceptanceTestHelper.회원이_사용자_검색; -import static com.listywave.acceptance.user.UserAcceptanceTestHelper.회원이_회원_정보_조회_요청; +import static com.listywave.acceptance.user.UserAcceptanceTestHelper.*; import static com.listywave.user.fixture.UserFixture.동호; import static com.listywave.user.fixture.UserFixture.유진; import static com.listywave.user.fixture.UserFixture.정수; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -import static org.springframework.http.HttpStatus.BAD_REQUEST; -import static org.springframework.http.HttpStatus.FORBIDDEN; -import static org.springframework.http.HttpStatus.NO_CONTENT; +import static org.springframework.http.HttpStatus.*; import com.listywave.acceptance.common.AcceptanceTest; import com.listywave.user.application.dto.RecommendUsersResponse; diff --git a/src/test/java/com/listywave/acceptance/user/UserAcceptanceTestHelper.java b/src/test/java/com/listywave/acceptance/user/UserAcceptanceTestHelper.java index 2c1520a6..946c3f80 100644 --- a/src/test/java/com/listywave/acceptance/user/UserAcceptanceTestHelper.java +++ b/src/test/java/com/listywave/acceptance/user/UserAcceptanceTestHelper.java @@ -3,6 +3,7 @@ import static com.listywave.acceptance.common.CommonAcceptanceHelper.given; import static org.springframework.http.HttpHeaders.AUTHORIZATION; +import com.listywave.user.presentation.dto.ListVisibilityUpdateRequest; import com.listywave.user.presentation.dto.UserProfileUpdateRequest; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; diff --git a/src/test/java/com/listywave/list/application/domain/list/ListEntityTest.java b/src/test/java/com/listywave/list/application/domain/list/ListEntityTest.java index 2ffb60dd..267ccf5a 100644 --- a/src/test/java/com/listywave/list/application/domain/list/ListEntityTest.java +++ b/src/test/java/com/listywave/list/application/domain/list/ListEntityTest.java @@ -183,7 +183,7 @@ class ListEntityTest { void 공개_여부를_수정할_수_있다() { assertThat(list.isPublic()).isTrue(); - list.updateVisibility(false); + list.updateVisibility(); assertThat(list.isPublic()).isFalse(); }