diff --git a/backend/src/docs/asciidoc/member.adoc b/backend/src/docs/asciidoc/member.adoc index 114112e4d..520b39431 100644 --- a/backend/src/docs/asciidoc/member.adoc +++ b/backend/src/docs/asciidoc/member.adoc @@ -23,3 +23,7 @@ operation::member-controller-test/find-all-topics-in-atlas[snippets='http-reques === 회원의 즐겨찾기 조회 operation::member-controller-test/find-all-topics-in-bookmark[snippets='http-request,http-response'] + +=== 회원의 내 정보 수정 + +operation::member-controller-test/update-my-info[snippets='http-request,http-response'] diff --git a/backend/src/docs/asciidoc/permission.adoc b/backend/src/docs/asciidoc/permission.adoc index 4b232e68c..bfb105200 100644 --- a/backend/src/docs/asciidoc/permission.adoc +++ b/backend/src/docs/asciidoc/permission.adoc @@ -8,9 +8,9 @@ operation::permission-controller-test/add-permission[snippets='http-request,http operation::permission-controller-test/delete-permission[snippets='http-request,http-response'] -=== 토픽에 권한을 가진 회원 목록 조회 +=== 토픽 접근 정보(권한 회원 목록 및 공개 여부) 조회 -operation::permission-controller-test/find-all-topic-permissions[snippets='http-request,http-response'] +operation::permission-controller-test/find-topic-access-detail-by-topic-id[snippets='http-request,http-response'] === 토픽에 권한을 가진 회원 단일 조회 diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionQueryService.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionQueryService.java index 7765d1511..5b4bb4abb 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionQueryService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionQueryService.java @@ -4,9 +4,16 @@ import com.mapbefine.mapbefine.permission.domain.Permission; import com.mapbefine.mapbefine.permission.domain.PermissionRepository; -import com.mapbefine.mapbefine.permission.dto.response.PermissionDetailResponse; -import com.mapbefine.mapbefine.permission.dto.response.PermissionResponse; +import com.mapbefine.mapbefine.permission.dto.response.PermissionMemberDetailResponse; +import com.mapbefine.mapbefine.permission.dto.response.PermissionedMemberResponse; +import com.mapbefine.mapbefine.permission.dto.response.TopicAccessDetailResponse; import com.mapbefine.mapbefine.permission.exception.PermissionException.PermissionNotFoundException; +import com.mapbefine.mapbefine.topic.domain.Publicity; +import com.mapbefine.mapbefine.topic.domain.Topic; +import com.mapbefine.mapbefine.topic.domain.TopicRepository; +import com.mapbefine.mapbefine.topic.domain.TopicStatus; +import com.mapbefine.mapbefine.topic.exception.TopicErrorCode; +import com.mapbefine.mapbefine.topic.exception.TopicException.TopicNotFoundException; import java.util.List; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,22 +23,35 @@ public class PermissionQueryService { private final PermissionRepository permissionRepository; + private final TopicRepository topicRepository; - public PermissionQueryService(PermissionRepository permissionRepository) { + public PermissionQueryService(PermissionRepository permissionRepository, TopicRepository topicRepository) { this.permissionRepository = permissionRepository; + this.topicRepository = topicRepository; } - public List findAllTopicPermissions(Long topicId) { - return permissionRepository.findAllByTopicId(topicId) + public TopicAccessDetailResponse findTopicAccessDetailById(Long topicId) { + Publicity publicity = findTopicPublicityById(topicId); + /// TODO: 2023/09/15 이럴거면 topic.getPermissions 로 하는 게 나을 수도 있나? TopicController 에서 하는 게 더 자연스러운 것 같기도.. + List permissionedMembers = permissionRepository.findAllByTopicId(topicId) .stream() - .map(PermissionResponse::from) + .map(PermissionedMemberResponse::from) .toList(); + + return new TopicAccessDetailResponse(publicity, permissionedMembers); + } + + private Publicity findTopicPublicityById(Long topicId) { + return topicRepository.findById(topicId) + .map(Topic::getTopicStatus) + .map(TopicStatus::getPublicity) + .orElseThrow(() -> new TopicNotFoundException(TopicErrorCode.TOPIC_NOT_FOUND, topicId)); } - public PermissionDetailResponse findPermissionById(Long permissionId) { + public PermissionMemberDetailResponse findPermissionById(Long permissionId) { Permission permission = permissionRepository.findById(permissionId) .orElseThrow(() -> new PermissionNotFoundException(PERMISSION_NOT_FOUND, permissionId)); - return PermissionDetailResponse.from(permission); + return PermissionMemberDetailResponse.from(permission); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/domain/Permission.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/domain/Permission.java index e58678b16..8f6bf1ca6 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/permission/domain/Permission.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/domain/Permission.java @@ -19,6 +19,7 @@ @Getter public class Permission extends BaseTimeEntity { + // TODO 매핑 테이블인데 Id를 가져야 할까? @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionDetailResponse.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionMemberDetailResponse.java similarity index 73% rename from backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionDetailResponse.java rename to backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionMemberDetailResponse.java index 967fa8eb5..d42946de5 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionDetailResponse.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionMemberDetailResponse.java @@ -4,14 +4,14 @@ import com.mapbefine.mapbefine.permission.domain.Permission; import java.time.LocalDateTime; -public record PermissionDetailResponse( +public record PermissionMemberDetailResponse( Long id, LocalDateTime updatedAt, MemberDetailResponse memberDetailResponse ) { - public static PermissionDetailResponse from(Permission permission) { - return new PermissionDetailResponse( + public static PermissionMemberDetailResponse from(Permission permission) { + return new PermissionMemberDetailResponse( permission.getId(), permission.getUpdatedAt(), MemberDetailResponse.from(permission.getMember()) diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionResponse.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionedMemberResponse.java similarity index 68% rename from backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionResponse.java rename to backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionedMemberResponse.java index 9c4f23689..dda91d866 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionResponse.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionedMemberResponse.java @@ -3,13 +3,13 @@ import com.mapbefine.mapbefine.member.dto.response.MemberResponse; import com.mapbefine.mapbefine.permission.domain.Permission; -public record PermissionResponse( +public record PermissionedMemberResponse( Long id, MemberResponse memberResponse ) { - public static PermissionResponse from(Permission permission) { - return new PermissionResponse( + public static PermissionedMemberResponse from(Permission permission) { + return new PermissionedMemberResponse( permission.getId(), MemberResponse.from(permission.getMember()) ); diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/TopicAccessDetailResponse.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/TopicAccessDetailResponse.java new file mode 100644 index 000000000..7d2965666 --- /dev/null +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/TopicAccessDetailResponse.java @@ -0,0 +1,10 @@ +package com.mapbefine.mapbefine.permission.dto.response; + +import com.mapbefine.mapbefine.topic.domain.Publicity; +import java.util.List; + +public record TopicAccessDetailResponse( + Publicity publicity, + List permissionedMembers +) { +} diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/presentation/PermissionController.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/presentation/PermissionController.java index 750b9bc4a..188348ea3 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/permission/presentation/PermissionController.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/presentation/PermissionController.java @@ -5,9 +5,8 @@ import com.mapbefine.mapbefine.permission.application.PermissionCommandService; import com.mapbefine.mapbefine.permission.application.PermissionQueryService; import com.mapbefine.mapbefine.permission.dto.request.PermissionRequest; -import com.mapbefine.mapbefine.permission.dto.response.PermissionDetailResponse; -import com.mapbefine.mapbefine.permission.dto.response.PermissionResponse; -import java.util.List; +import com.mapbefine.mapbefine.permission.dto.response.PermissionMemberDetailResponse; +import com.mapbefine.mapbefine.permission.dto.response.TopicAccessDetailResponse; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -51,16 +50,18 @@ public ResponseEntity deleteMemberTopicPermission(AuthMember authMember, @ @LoginRequired @GetMapping("/topics/{topicId}") - public ResponseEntity> findAllTopicPermissions(@PathVariable Long topicId) { - List responses = permissionQueryService.findAllTopicPermissions(topicId); + public ResponseEntity findTopicAccessDetailByTopicId(@PathVariable Long topicId) { + TopicAccessDetailResponse response = permissionQueryService.findTopicAccessDetailById(topicId); - return ResponseEntity.ok(responses); + return ResponseEntity.ok(response); } + // TODO 이 API를 쓰는 곳이 있나? + 결국 특정 회원을 조회하는 건데 어떤 API인지 알기 어렵다.. + // 회원 정보 조회는 /members 에서 하는 걸로 충분하지 않나? 재사용성이 떨어진다. 테스트의 DisplayName도 매칭이 안된다. @LoginRequired @GetMapping("/{permissionId}") - public ResponseEntity findPermissionById(@PathVariable Long permissionId) { - PermissionDetailResponse response = permissionQueryService.findPermissionById(permissionId); + public ResponseEntity findPermissionById(@PathVariable Long permissionId) { + PermissionMemberDetailResponse response = permissionQueryService.findPermissionById(permissionId); return ResponseEntity.ok(response); } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/Topic.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/Topic.java index d5128022e..a407bcdb7 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/Topic.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/Topic.java @@ -114,6 +114,9 @@ public int countBookmarks() { return bookmarks.size(); } + public Publicity getPublicity() { + return topicStatus.getPublicity(); + } public void removeImage() { this.topicInfo = topicInfo.removeImage(); } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/TopicStatus.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/TopicStatus.java index 987a19a5a..88a793877 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/TopicStatus.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/TopicStatus.java @@ -1,7 +1,7 @@ package com.mapbefine.mapbefine.topic.domain; -import static com.mapbefine.mapbefine.topic.exception.TopicErrorCode.ILLEGAL_PERMISSION_NULL; import static com.mapbefine.mapbefine.topic.exception.TopicErrorCode.ILLEGAL_PERMISSION_FOR_PUBLICITY_PRIVATE; +import static com.mapbefine.mapbefine.topic.exception.TopicErrorCode.ILLEGAL_PERMISSION_NULL; import static com.mapbefine.mapbefine.topic.exception.TopicErrorCode.ILLEGAL_PERMISSION_UPDATE; import static com.mapbefine.mapbefine.topic.exception.TopicErrorCode.ILLEGAL_PUBLICITY_FOR_PERMISSION_ALL_MEMBERS; import static com.mapbefine.mapbefine.topic.exception.TopicErrorCode.ILLEGAL_PUBLICITY_NULL; diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/exception/TopicException.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/exception/TopicException.java index 2c2afb9fe..e9729943d 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/exception/TopicException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/exception/TopicException.java @@ -23,6 +23,10 @@ public static class TopicNotFoundException extends NotFoundException { public TopicNotFoundException(TopicErrorCode errorCode, List ids) { super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), ids)); } + + public TopicNotFoundException(TopicErrorCode errorCode, Long id) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), id)); + } } } diff --git a/backend/src/test/java/com/mapbefine/mapbefine/atlas/AtlasIntegrationTest.java b/backend/src/test/java/com/mapbefine/mapbefine/atlas/AtlasIntegrationTest.java index fa6812504..57fb46dcb 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/atlas/AtlasIntegrationTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/atlas/AtlasIntegrationTest.java @@ -15,16 +15,15 @@ import com.mapbefine.mapbefine.topic.TopicFixture; import com.mapbefine.mapbefine.topic.domain.Topic; import com.mapbefine.mapbefine.topic.domain.TopicRepository; -import io.restassured.RestAssured; -import io.restassured.response.ExtractableResponse; -import io.restassured.response.Response; +import io.restassured.*; +import io.restassured.response.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -public class AtlasIntegrationTest extends IntegrationTest { +class AtlasIntegrationTest extends IntegrationTest { @Autowired TopicRepository topicRepository; diff --git a/backend/src/test/java/com/mapbefine/mapbefine/bookmark/BookmarkIntegrationTest.java b/backend/src/test/java/com/mapbefine/mapbefine/bookmark/BookmarkIntegrationTest.java index 022fefba2..aecb86d01 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/bookmark/BookmarkIntegrationTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/bookmark/BookmarkIntegrationTest.java @@ -1,6 +1,6 @@ package com.mapbefine.mapbefine.bookmark; -import static io.restassured.RestAssured.given; +import static io.restassured.RestAssured.*; import static org.apache.http.HttpHeaders.AUTHORIZATION; import static org.assertj.core.api.Assertions.assertThat; @@ -14,14 +14,13 @@ import com.mapbefine.mapbefine.topic.TopicFixture; import com.mapbefine.mapbefine.topic.domain.Topic; import com.mapbefine.mapbefine.topic.domain.TopicRepository; -import io.restassured.response.ExtractableResponse; -import io.restassured.response.Response; +import io.restassured.response.*; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -public class BookmarkIntegrationTest extends IntegrationTest { +class BookmarkIntegrationTest extends IntegrationTest { @Autowired private MemberRepository memberRepository; diff --git a/backend/src/test/java/com/mapbefine/mapbefine/common/IntegrationTest.java b/backend/src/test/java/com/mapbefine/mapbefine/common/IntegrationTest.java index 9a91e94aa..e20e5caa6 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/common/IntegrationTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/common/IntegrationTest.java @@ -1,7 +1,7 @@ package com.mapbefine.mapbefine.common; import com.mapbefine.mapbefine.DatabaseCleanup; -import io.restassured.RestAssured; +import io.restassured.*; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; diff --git a/backend/src/test/java/com/mapbefine/mapbefine/permission/PermissionIntegrationTest.java b/backend/src/test/java/com/mapbefine/mapbefine/permission/PermissionIntegrationTest.java index cfa164f3c..2a663ea81 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/permission/PermissionIntegrationTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/permission/PermissionIntegrationTest.java @@ -1,7 +1,7 @@ package com.mapbefine.mapbefine.permission; import static com.mapbefine.mapbefine.oauth.domain.OauthServerType.KAKAO; -import static io.restassured.RestAssured.given; +import static io.restassured.RestAssured.*; import static org.apache.http.HttpHeaders.AUTHORIZATION; import static org.assertj.core.api.Assertions.assertThat; @@ -16,14 +16,14 @@ import com.mapbefine.mapbefine.permission.domain.Permission; import com.mapbefine.mapbefine.permission.domain.PermissionRepository; import com.mapbefine.mapbefine.permission.dto.request.PermissionRequest; -import com.mapbefine.mapbefine.permission.dto.response.PermissionDetailResponse; -import com.mapbefine.mapbefine.permission.dto.response.PermissionResponse; +import com.mapbefine.mapbefine.permission.dto.response.PermissionMemberDetailResponse; +import com.mapbefine.mapbefine.permission.dto.response.PermissionedMemberResponse; +import com.mapbefine.mapbefine.permission.dto.response.TopicAccessDetailResponse; import com.mapbefine.mapbefine.topic.TopicFixture; import com.mapbefine.mapbefine.topic.domain.Topic; import com.mapbefine.mapbefine.topic.domain.TopicRepository; -import io.restassured.common.mapper.TypeRef; -import io.restassured.response.ExtractableResponse; -import io.restassured.response.Response; +import io.restassured.common.mapper.*; +import io.restassured.response.*; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.BeforeEach; @@ -33,7 +33,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -public class PermissionIntegrationTest extends IntegrationTest { +class PermissionIntegrationTest extends IntegrationTest { @Autowired private MemberRepository memberRepository; @@ -79,7 +79,7 @@ public void setUp() { } @Test - @DisplayName("Topic 을 만든자가 특정 회원에게 권한을 준다.") + @DisplayName("Topic 을 만든 회원이 특정 회원에게 해당 Topic 에 대한 권한을 준다.") void addPermission() { // given Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); @@ -100,7 +100,7 @@ void addPermission() { } @Test - @DisplayName("Topic 을 만든자가 특정 회원에게 권한을 삭제한다.") + @DisplayName("Topic 을 만든 회원이 특정 회원이 가진 해당 Topic 에 대한 권한을 삭제한다.") void deletePermission() { // given Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); @@ -121,8 +121,8 @@ void deletePermission() { } @Test - @DisplayName("Topic 에 권한을 가진 자들을 모두 조회한다.") - void findMemberTopicPermissionAll() { + @DisplayName("Topic 의 접근 정보(권한 회원 목록 및 공개 여부)를 조회한다.") + void findTopicAccessDetailById() { // given Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); Permission permission1 = @@ -138,22 +138,22 @@ void findMemberTopicPermissionAll() { .when().get("/permissions/topics/" + topic.getId()) .then().log().all() .extract(); + TopicAccessDetailResponse actual = response.as(new TypeRef<>() {}); // then - List permissionResponse = response.as(new TypeRef<>() { - }); assertThat(response.statusCode()) .isEqualTo(HttpStatus.OK.value()); - assertThat(permissionResponse) + assertThat(actual.publicity()).isEqualTo(topic.getPublicity()); + assertThat(actual.permissionedMembers()) .hasSize(2) - .extracting(PermissionResponse::memberResponse) + .extracting(PermissionedMemberResponse::memberResponse) .usingRecursiveComparison() .isEqualTo(List.of(MemberResponse.from(user1), MemberResponse.from(user2))); } @Test @DisplayName("Topic 에 권한을 가진 자를 조회한다.") - void findMemberTopicPermissionById() { + void findPermissionById() { // given Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); Permission permission = @@ -166,14 +166,13 @@ void findMemberTopicPermissionById() { .when().get("/permissions/" + permission.getId()) .then().log().all() .extract(); + PermissionMemberDetailResponse actual = response.as(new TypeRef<>() {}); // then - PermissionDetailResponse permissionDetailResponse = response.as( - PermissionDetailResponse.class); assertThat(response.statusCode()) .isEqualTo(HttpStatus.OK.value()); - assertThat(permissionDetailResponse) - .extracting(PermissionDetailResponse::memberDetailResponse) + assertThat(actual) + .extracting(PermissionMemberDetailResponse::memberDetailResponse) .usingRecursiveComparison() .ignoringFieldsOfTypes(LocalDateTime.class) .isEqualTo(MemberDetailResponse.from(user1)); diff --git a/backend/src/test/java/com/mapbefine/mapbefine/permission/application/PermissionQueryServiceTest.java b/backend/src/test/java/com/mapbefine/mapbefine/permission/application/PermissionQueryServiceTest.java index def49d5f9..43afe105e 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/permission/application/PermissionQueryServiceTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/permission/application/PermissionQueryServiceTest.java @@ -12,8 +12,9 @@ import com.mapbefine.mapbefine.member.dto.response.MemberResponse; import com.mapbefine.mapbefine.permission.domain.Permission; import com.mapbefine.mapbefine.permission.domain.PermissionRepository; -import com.mapbefine.mapbefine.permission.dto.response.PermissionDetailResponse; -import com.mapbefine.mapbefine.permission.dto.response.PermissionResponse; +import com.mapbefine.mapbefine.permission.dto.response.PermissionMemberDetailResponse; +import com.mapbefine.mapbefine.permission.dto.response.PermissionedMemberResponse; +import com.mapbefine.mapbefine.permission.dto.response.TopicAccessDetailResponse; import com.mapbefine.mapbefine.permission.exception.PermissionException.PermissionNotFoundException; import com.mapbefine.mapbefine.topic.TopicFixture; import com.mapbefine.mapbefine.topic.domain.Topic; @@ -36,9 +37,9 @@ class PermissionQueryServiceTest { private PermissionQueryService permissionQueryService; @Test - @DisplayName("Topic 에 권한이 있는자들을 모두 조회한다.") - // creator 는 권한이 있는자들을 조회할 때 조회되어야 할 것인가?? - void findAllWithPermission() { + @DisplayName("특정 지도에 대한 접근 정보(권한 회원 목록 및 공개 여부)를 모두 조회한다. 권한 회원 중 생성자는 제외한다.") + void findTopicAccessDetailById() { + /// TODO: 2023/09/15 리팩터링 // given Member member1InTopic1 = memberRepository.save( MemberFixture.create("member", "member@naver.com", Role.USER) @@ -62,20 +63,26 @@ void findAllWithPermission() { ); // when - List permissionRespons = permissionQueryService.findAllTopicPermissions(topic1.getId()); - MemberResponse memberResponse1 = MemberResponse.from(member1InTopic1); - MemberResponse memberResponse2 = MemberResponse.from(member2InTopic1); + TopicAccessDetailResponse accessDetailResponse = permissionQueryService.findTopicAccessDetailById(topic1.getId()); + MemberResponse member1Response = MemberResponse.from(member1InTopic1); + MemberResponse member2Response = MemberResponse.from(member2InTopic1); // then - assertThat(permissionRespons).hasSize(2) - .extracting(PermissionResponse::memberResponse) + assertThat(accessDetailResponse.publicity()).isEqualTo(topic1.getPublicity()); + List permissionedMembers = accessDetailResponse.permissionedMembers(); + assertThat(permissionedMembers).hasSize(2) + .extracting(PermissionedMemberResponse::memberResponse) .usingRecursiveComparison() - .isEqualTo(List.of(memberResponse1, memberResponse2)); + .isEqualTo(List.of(member1Response, member2Response)); + assertThat(permissionedMembers) + .extracting(PermissionedMemberResponse::memberResponse) + .map(MemberResponse::id) + .doesNotContain(topic1.getCreator().getId()); } @Test @DisplayName("ID 를 통해서 토픽에 권한이 있는자를 조회한다.") - void findMemberTopicPermissionById() { + void findPermissionById() { // given Member creator = memberRepository.save( MemberFixture.create("member", "member@naver.com", Role.USER) @@ -89,20 +96,20 @@ void findMemberTopicPermissionById() { ).getId(); // when - PermissionDetailResponse permissionDetailResponse = + PermissionMemberDetailResponse permissionMemberDetailResponse = permissionQueryService.findPermissionById(savedId); MemberDetailResponse permissionUserResponse = MemberDetailResponse.from(permissionUser); // then - assertThat(permissionDetailResponse) - .extracting(PermissionDetailResponse::memberDetailResponse) + assertThat(permissionMemberDetailResponse) + .extracting(PermissionMemberDetailResponse::memberDetailResponse) .usingRecursiveComparison() .isEqualTo(permissionUserResponse); } @Test @DisplayName("ID 를 통해서 토픽에 권한이 있는자를 조회하려 할 때, 결과가 존재하지 않을 때 예외가 발생한다.") - void findMemberTopicPermissionById_whenNoneExistsPermission_thenFail() { + void findPermissionById_whenNoneExistsPermission_thenFail() { // given when then assertThatThrownBy(() -> permissionQueryService.findPermissionById(Long.MAX_VALUE)) .isInstanceOf(PermissionNotFoundException.class); diff --git a/backend/src/test/java/com/mapbefine/mapbefine/permission/presentation/PermissionControllerTest.java b/backend/src/test/java/com/mapbefine/mapbefine/permission/presentation/PermissionControllerTest.java index e68852679..e2311f476 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/permission/presentation/PermissionControllerTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/permission/presentation/PermissionControllerTest.java @@ -5,16 +5,14 @@ import static org.mockito.BDDMockito.given; import com.mapbefine.mapbefine.common.RestDocsIntegration; -import com.mapbefine.mapbefine.member.MemberFixture; -import com.mapbefine.mapbefine.member.domain.Member; -import com.mapbefine.mapbefine.member.domain.Role; import com.mapbefine.mapbefine.member.dto.response.MemberDetailResponse; import com.mapbefine.mapbefine.member.dto.response.MemberResponse; -import com.mapbefine.mapbefine.permission.application.PermissionCommandService; import com.mapbefine.mapbefine.permission.application.PermissionQueryService; import com.mapbefine.mapbefine.permission.dto.request.PermissionRequest; -import com.mapbefine.mapbefine.permission.dto.response.PermissionDetailResponse; -import com.mapbefine.mapbefine.permission.dto.response.PermissionResponse; +import com.mapbefine.mapbefine.permission.dto.response.PermissionMemberDetailResponse; +import com.mapbefine.mapbefine.permission.dto.response.PermissionedMemberResponse; +import com.mapbefine.mapbefine.permission.dto.response.TopicAccessDetailResponse; +import com.mapbefine.mapbefine.topic.domain.Publicity; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -27,13 +25,10 @@ class PermissionControllerTest extends RestDocsIntegration { @MockBean private PermissionQueryService permissionQueryService; - @MockBean - private PermissionCommandService permissionCommandService; @Test @DisplayName("권한 추가") void addPermission() throws Exception { - Member member = MemberFixture.create("member", "member@naver.com", Role.ADMIN); PermissionRequest request = new PermissionRequest(1L, List.of(1L, 2L, 3L)); mockMvc.perform( @@ -47,8 +42,6 @@ void addPermission() throws Exception { @Test @DisplayName("권한 삭제") void deletePermission() throws Exception { - Member member = MemberFixture.create("member", "member@naver.com", Role.ADMIN); - mockMvc.perform( MockMvcRequestBuilders.delete("/permissions/1") .header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L)) @@ -56,28 +49,15 @@ void deletePermission() throws Exception { } @Test - @DisplayName("권한이 있는 자들 모두 조회") - void findAllTopicPermissions() throws Exception { - List permissionResponses = List.of( - new PermissionResponse( - 1L, - new MemberResponse( - 1L, - "member", - "member@naver.com" - ) - ), - new PermissionResponse( - 1L, - new MemberResponse( - 2L, - "memberr", - "memberr@naver.com" - ) - ) + @DisplayName("특정 토픽 접근 정보 조회(권한 회원 목록, 공개 여부)") + void findTopicAccessDetailByTopicId() throws Exception { + List permissionedMembers = List.of( + new PermissionedMemberResponse(1L, new MemberResponse(1L, "member", "member@naver.com")), + new PermissionedMemberResponse(1L, new MemberResponse(2L, "memberr", "memberr@naver.com")) ); + TopicAccessDetailResponse response = new TopicAccessDetailResponse(Publicity.PUBLIC, permissionedMembers); - given(permissionQueryService.findAllTopicPermissions(any())).willReturn(permissionResponses); + given(permissionQueryService.findTopicAccessDetailById(any())).willReturn(response); mockMvc.perform( MockMvcRequestBuilders.get("/permissions/topics/1") @@ -88,7 +68,7 @@ void findAllTopicPermissions() throws Exception { @Test @DisplayName("권한이 있는 자들 모두 조회") void findPermissionById() throws Exception { - PermissionDetailResponse permissionDetailResponse = new PermissionDetailResponse( + PermissionMemberDetailResponse permissionMemberDetailResponse = new PermissionMemberDetailResponse( 1L, LocalDateTime.now(), new MemberDetailResponse( @@ -100,7 +80,7 @@ void findPermissionById() throws Exception { ) ); - given(permissionQueryService.findPermissionById(any())).willReturn(permissionDetailResponse); + given(permissionQueryService.findPermissionById(any())).willReturn(permissionMemberDetailResponse); mockMvc.perform( MockMvcRequestBuilders.get("/permissions/1") diff --git a/backend/src/test/java/com/mapbefine/mapbefine/pin/PinIntegrationTest.java b/backend/src/test/java/com/mapbefine/mapbefine/pin/PinIntegrationTest.java index c154156b7..eed8c54f8 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/pin/PinIntegrationTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/pin/PinIntegrationTest.java @@ -18,9 +18,8 @@ import com.mapbefine.mapbefine.topic.TopicFixture; import com.mapbefine.mapbefine.topic.domain.Topic; import com.mapbefine.mapbefine.topic.domain.TopicRepository; -import io.restassured.RestAssured; -import io.restassured.response.ExtractableResponse; -import io.restassured.response.Response; +import io.restassured.*; +import io.restassured.response.*; import java.io.File; import java.util.List; import org.junit.jupiter.api.BeforeEach; diff --git a/backend/src/test/java/com/mapbefine/mapbefine/pin/presentation/PinControllerTest.java b/backend/src/test/java/com/mapbefine/mapbefine/pin/presentation/PinControllerTest.java index b5c9eafc3..17dc5a8b7 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/pin/presentation/PinControllerTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/pin/presentation/PinControllerTest.java @@ -3,16 +3,13 @@ import static org.apache.http.HttpHeaders.AUTHORIZATION; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; -import com.mapbefine.mapbefine.FileFixture; import com.mapbefine.mapbefine.common.RestDocsIntegration; import com.mapbefine.mapbefine.pin.application.PinCommandService; import com.mapbefine.mapbefine.pin.application.PinQueryService; import com.mapbefine.mapbefine.pin.dto.request.PinCreateRequest; -import com.mapbefine.mapbefine.pin.dto.request.PinImageCreateRequest; import com.mapbefine.mapbefine.pin.dto.request.PinUpdateRequest; import com.mapbefine.mapbefine.pin.dto.response.PinDetailResponse; import com.mapbefine.mapbefine.pin.dto.response.PinImageResponse; diff --git a/backend/src/test/java/com/mapbefine/mapbefine/topic/TopicIntegrationTest.java b/backend/src/test/java/com/mapbefine/mapbefine/topic/TopicIntegrationTest.java index 80c13a9f3..6d648853f 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/topic/TopicIntegrationTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/topic/TopicIntegrationTest.java @@ -3,7 +3,6 @@ import static org.apache.http.HttpHeaders.AUTHORIZATION; import static org.assertj.core.api.Assertions.assertThat; -import com.mapbefine.mapbefine.FileFixture; import com.mapbefine.mapbefine.bookmark.domain.Bookmark; import com.mapbefine.mapbefine.bookmark.domain.BookmarkRepository; import com.mapbefine.mapbefine.common.IntegrationTest; @@ -21,7 +20,6 @@ import com.mapbefine.mapbefine.topic.domain.Publicity; import com.mapbefine.mapbefine.topic.domain.Topic; import com.mapbefine.mapbefine.topic.domain.TopicRepository; -import com.mapbefine.mapbefine.topic.dto.request.TopicCreateRequest; import com.mapbefine.mapbefine.topic.dto.request.TopicCreateRequestWithOutImage; import com.mapbefine.mapbefine.topic.dto.request.TopicMergeRequest; import com.mapbefine.mapbefine.topic.dto.request.TopicUpdateRequest; @@ -38,7 +36,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.mock.web.MockMultipartFile; class TopicIntegrationTest extends IntegrationTest { @@ -329,7 +326,6 @@ void findTopicDetailsByIds_Success() { // then assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); assertThat(responses).hasSize(2); - assertThat(responses).hasSize(2); } @Test diff --git a/backend/src/test/java/com/mapbefine/mapbefine/topic/presentation/TopicControllerTest.java b/backend/src/test/java/com/mapbefine/mapbefine/topic/presentation/TopicControllerTest.java index da72796fe..23dc09459 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/topic/presentation/TopicControllerTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/topic/presentation/TopicControllerTest.java @@ -3,16 +3,13 @@ import static org.apache.http.HttpHeaders.AUTHORIZATION; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import com.mapbefine.mapbefine.FileFixture; import com.mapbefine.mapbefine.common.RestDocsIntegration; import com.mapbefine.mapbefine.pin.dto.response.PinResponse; import com.mapbefine.mapbefine.topic.application.TopicCommandService; import com.mapbefine.mapbefine.topic.application.TopicQueryService; import com.mapbefine.mapbefine.topic.domain.PermissionType; import com.mapbefine.mapbefine.topic.domain.Publicity; -import com.mapbefine.mapbefine.topic.dto.request.TopicCreateRequest; import com.mapbefine.mapbefine.topic.dto.request.TopicCreateRequestWithOutImage; import com.mapbefine.mapbefine.topic.dto.request.TopicMergeRequest; import com.mapbefine.mapbefine.topic.dto.request.TopicUpdateRequest; @@ -20,18 +17,11 @@ import com.mapbefine.mapbefine.topic.dto.response.TopicResponse; import java.io.File; import java.time.LocalDateTime; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap;