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

refactor: 내 피드 리스트 공개 상태 여부 정책 변경에 따른 API 수정 #290

Merged
merged 4 commits into from
Sep 8, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Comment on lines +308 to +313
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상당히 깔끔하군요 👍

}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ ResponseEntity<Void> deleteLists(
@RequestBody ListsDeleteRequest request
) {
listService.deleteLists(userId, request.listId());
return ResponseEntity.ok().build();
return ResponseEntity.noContent().build();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

@PatchMapping("/lists/{listId}/visibility")
ResponseEntity<Void> changeVisibility(
@Auth Long loginUserId,
@PathVariable("listId") Long listId
) {
listService.changeVisibility(loginUserId, listId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
@RequiredArgsConstructor
public class UserService {

private final ListRepository listRepository;
private final UserRepository userRepository;
private final FollowRepository followRepository;
private final UserElasticRepository userElasticRepository;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ ResponseEntity<Void> deleteFollower(
return ResponseEntity.noContent().build();
}

@PatchMapping("/users/list-visibility")
ResponseEntity<Void> updateListVisibility(
@Auth Long loginUserId,
@RequestBody ListVisibilityUpdateRequest request
) {
userService.updateListVisibility(loginUserId, request.listId(), request.isPublic());
return ResponseEntity.ok().build();
}

@GetMapping("/v2/users")
ResponseEntity<UserElasticSearchResponse> searchUserByElastic(
@OptionalAuth Long loginUserId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_순위_변경;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,12 @@ public abstract class ListAcceptanceTestHelper {
.then().log().all()
.extract();
}

public static ExtractableResponse<Response> 리스트_공개_여부_변경_API_호출(String accessToken, Long listId) {
return given()
.header(AUTHORIZATION, "Bearer " + accessToken)
.when().patch("/lists/{listId}/visibility", listId)
.then().log().all()
.extract();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class ListEntityTest {
void 공개_여부를_수정할_수_있다() {
assertThat(list.isPublic()).isTrue();

list.updateVisibility(false);
list.updateVisibility();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


assertThat(list.isPublic()).isFalse();
}
Expand Down
Loading