diff --git a/backend/src/docs/asciidoc/index.adoc b/backend/src/docs/asciidoc/index.adoc index 4cae5b937..b6cbd853d 100644 --- a/backend/src/docs/asciidoc/index.adoc +++ b/backend/src/docs/asciidoc/index.adoc @@ -11,4 +11,5 @@ toc::[] include::topic.adoc[] include::pin.adoc[] include::member.adoc[] +include::permission.adoc[] include::oauth.adoc[] diff --git a/backend/src/docs/asciidoc/member.adoc b/backend/src/docs/asciidoc/member.adoc index 8f5d7acca..fc40578c3 100644 --- a/backend/src/docs/asciidoc/member.adoc +++ b/backend/src/docs/asciidoc/member.adoc @@ -1,21 +1,5 @@ == 유저 -=== 유저 권한 부여 - -operation::member-controller-test/add-member-topic-permission[snippets='http-request,http-response'] - -=== 유저 권한 삭제 - -operation::member-controller-test/delete-member-topic-permission[snippets='http-request,http-response'] - -=== 토픽에 권한을 가진 유저 목록 조회 - -operation::member-controller-test/find-member-topic-permission-all[snippets='http-request,http-response'] - -=== 토픽에 권한을 가진 유저 단일 조회 - -operation::member-controller-test/find-member-topic-permission-by-id[snippets='http-request,http-response'] - === 유저 목록 조회 operation::member-controller-test/find-all-member[snippets='http-request,http-response'] diff --git a/backend/src/docs/asciidoc/permission.adoc b/backend/src/docs/asciidoc/permission.adoc new file mode 100644 index 000000000..c704d7ed3 --- /dev/null +++ b/backend/src/docs/asciidoc/permission.adoc @@ -0,0 +1,17 @@ +== 권한 + +=== 권한 부여 + +operation::permission-controller-test/add-permission[snippets='http-request,http-response'] + +=== 권한 삭제 + +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-permission-by-id[snippets='http-request,http-response'] diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberCommandService.java b/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberCommandService.java index d5a3a0c4e..e69de29bb 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberCommandService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberCommandService.java @@ -1,90 +0,0 @@ -package com.mapbefine.mapbefine.member.application; - -import com.mapbefine.mapbefine.auth.domain.AuthMember; -import com.mapbefine.mapbefine.member.domain.Member; -import com.mapbefine.mapbefine.member.domain.MemberRepository; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermission; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermissionRepository; -import com.mapbefine.mapbefine.member.dto.request.MemberTopicPermissionCreateRequest; -import com.mapbefine.mapbefine.topic.domain.Topic; -import com.mapbefine.mapbefine.topic.domain.TopicRepository; -import java.util.NoSuchElementException; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional -public class MemberCommandService { - - private final MemberRepository memberRepository; - private final TopicRepository topicRepository; - private final MemberTopicPermissionRepository memberTopicPermissionRepository; - - public MemberCommandService( - MemberRepository memberRepository, - TopicRepository topicRepository, - MemberTopicPermissionRepository memberTopicPermissionRepository - ) { - this.memberRepository = memberRepository; - this.topicRepository = topicRepository; - this.memberTopicPermissionRepository = memberTopicPermissionRepository; - } - - public Long saveMemberTopicPermission(AuthMember authMember, MemberTopicPermissionCreateRequest request) { - Member member = memberRepository.findById(request.memberId()) - .orElseThrow(NoSuchElementException::new); - Topic topic = topicRepository.findById(request.topicId()) - .orElseThrow(NoSuchElementException::new); - - validateSaveMemberTopicPermission(authMember, request, member, topic); - - MemberTopicPermission memberTopicPermission = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, member); - - return memberTopicPermissionRepository.save(memberTopicPermission).getId(); - } - - private void validateSaveMemberTopicPermission( - AuthMember authMember, - MemberTopicPermissionCreateRequest request, - Member member, - Topic topic - ) { - validateMemberCanTopicUpdate(authMember, topic); - validateSelfPermission(authMember, request); - validateDuplicatePermission(topic.getId(), member.getId()); - } - - private void validateMemberCanTopicUpdate(AuthMember authMember, Topic topic) { - if (authMember.canTopicUpdate(topic)) { - return; - } - - throw new IllegalArgumentException("해당 유저는 해당 토픽에서 다른 유저에게 권한을 줄 수 없습니다."); - } - - private void validateSelfPermission( - AuthMember authMember, - MemberTopicPermissionCreateRequest request - ) { - if (authMember.getMemberId().equals(request.memberId())) { - throw new IllegalArgumentException("본인에게 권한을 줄 수 없습니다."); - } - } - - private void validateDuplicatePermission(Long topicId, Long memberId) { - if (memberTopicPermissionRepository.existsByTopicIdAndMemberId(topicId, memberId)) { - throw new IllegalArgumentException("권한은 중복으로 줄 수 없습니다."); - } - } - - public void deleteMemberTopicPermission(AuthMember authMember, Long permissionId) { - MemberTopicPermission memberTopicPermission = memberTopicPermissionRepository.findById(permissionId) - .orElseThrow(NoSuchElementException::new); - - validateMemberCanTopicUpdate(authMember, memberTopicPermission.getTopic()); - - memberTopicPermissionRepository.delete(memberTopicPermission); - } - -} diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberQueryService.java b/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberQueryService.java index fc6515b67..6614e6dd6 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberQueryService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberQueryService.java @@ -3,12 +3,8 @@ import com.mapbefine.mapbefine.auth.domain.AuthMember; import com.mapbefine.mapbefine.member.domain.Member; import com.mapbefine.mapbefine.member.domain.MemberRepository; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermission; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermissionRepository; import com.mapbefine.mapbefine.member.dto.response.MemberDetailResponse; import com.mapbefine.mapbefine.member.dto.response.MemberResponse; -import com.mapbefine.mapbefine.member.dto.response.MemberTopicPermissionDetailResponse; -import com.mapbefine.mapbefine.member.dto.response.MemberTopicPermissionResponse; import com.mapbefine.mapbefine.pin.domain.Pin; import com.mapbefine.mapbefine.pin.domain.PinRepository; import com.mapbefine.mapbefine.pin.dto.response.PinResponse; @@ -28,18 +24,15 @@ public class MemberQueryService { private final MemberRepository memberRepository; private final TopicRepository topicRepository; private final PinRepository pinRepository; - private final MemberTopicPermissionRepository memberTopicPermissionRepository; public MemberQueryService( MemberRepository memberRepository, TopicRepository topicRepository, - PinRepository pinRepository, - MemberTopicPermissionRepository memberTopicPermissionRepository + PinRepository pinRepository ) { this.memberRepository = memberRepository; this.topicRepository = topicRepository; this.pinRepository = pinRepository; - this.memberTopicPermissionRepository = memberTopicPermissionRepository; } public MemberDetailResponse findById(Long id) { @@ -49,6 +42,7 @@ public MemberDetailResponse findById(Long id) { return MemberDetailResponse.from(member); } + // TODO: 2023/08/14 해당 메서드는 ADMIN만 접근 가능하게 리팩터링 하기 public List findAll() { return memberRepository.findAll() .stream() @@ -56,6 +50,7 @@ public List findAll() { .toList(); } + // TODO: 2023/08/14 해당 메서드는 TopicQueryService로 옮기기 public List findTopicsByMember(AuthMember authMember) { validateNonExistsMember(authMember.getMemberId()); List topicsByCreator = topicRepository.findByCreatorId(authMember.getMemberId()); @@ -65,6 +60,7 @@ public List findTopicsByMember(AuthMember authMember) { .toList(); } + // TODO: 2023/08/14 해당 메서드는 PinQueryService로 옮기기 public List findPinsByMember(AuthMember authMember) { validateNonExistsMember(authMember.getMemberId()); List pinsByCreator = pinRepository.findByCreatorId(authMember.getMemberId()); @@ -73,28 +69,11 @@ public List findPinsByMember(AuthMember authMember) { .map(PinResponse::from) .toList(); } - - public void validateNonExistsMember(Long memberId) { + + private void validateNonExistsMember(Long memberId) { if (Objects.isNull(memberId)) { throw new IllegalArgumentException("존재하지 않는 유저입니다."); } } - public List findAllWithPermission(Long topicId) { - Topic topic = topicRepository.findById(topicId) - .orElseThrow(NoSuchElementException::new); - - return memberTopicPermissionRepository.findAllByTopic(topic) - .stream() - .map(MemberTopicPermissionResponse::from) - .toList(); - } - - public MemberTopicPermissionDetailResponse findMemberTopicPermissionById(Long permissionId) { - MemberTopicPermission memberTopicPermission = memberTopicPermissionRepository.findById(permissionId) - .orElseThrow(NoSuchElementException::new); - - return MemberTopicPermissionDetailResponse.from(memberTopicPermission); - } - } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/domain/Member.java b/backend/src/main/java/com/mapbefine/mapbefine/member/domain/Member.java index c82759538..8a67118d4 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/domain/Member.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/member/domain/Member.java @@ -4,6 +4,7 @@ import static lombok.AccessLevel.PROTECTED; import com.mapbefine.mapbefine.common.entity.BaseTimeEntity; +import com.mapbefine.mapbefine.permission.domain.Permission; import com.mapbefine.mapbefine.pin.domain.Pin; import com.mapbefine.mapbefine.topic.domain.Topic; import jakarta.persistence.Embedded; @@ -42,7 +43,7 @@ public class Member extends BaseTimeEntity { private List createdPins = new ArrayList<>(); @OneToMany(mappedBy = "member") - private List topicsWithPermissions = new ArrayList<>(); + private List topicsWithPermissions = new ArrayList<>(); private Member(MemberInfo memberInfo, OauthId oauthId) { this.memberInfo = memberInfo; @@ -105,8 +106,8 @@ public void addPin(Pin pin) { createdPins.add(pin); } - public void addMemberTopicPermission(MemberTopicPermission memberTopicPermission) { - topicsWithPermissions.add(memberTopicPermission); + public void addMemberTopicPermission(Permission permission) { + topicsWithPermissions.add(permission); } public String getRoleKey() { @@ -122,7 +123,7 @@ public boolean isUser() { public List getTopicsWithPermissions() { return topicsWithPermissions.stream() - .map(MemberTopicPermission::getTopic) + .map(Permission::getTopic) .toList(); } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/domain/MemberTopicPermissionRepository.java b/backend/src/main/java/com/mapbefine/mapbefine/member/domain/MemberTopicPermissionRepository.java deleted file mode 100644 index 0ab5dde24..000000000 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/domain/MemberTopicPermissionRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mapbefine.mapbefine.member.domain; - -import com.mapbefine.mapbefine.topic.domain.Topic; -import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface MemberTopicPermissionRepository extends JpaRepository { - - List findAllByTopic(Topic topic); - - boolean existsByTopicIdAndMemberId(Long topicId, Long memberId); - -} diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/dto/request/MemberTopicPermissionCreateRequest.java b/backend/src/main/java/com/mapbefine/mapbefine/member/dto/request/MemberTopicPermissionCreateRequest.java deleted file mode 100644 index 55b3ea7d1..000000000 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/dto/request/MemberTopicPermissionCreateRequest.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.mapbefine.mapbefine.member.dto.request; - -public record MemberTopicPermissionCreateRequest( - Long topicId, - Long memberId -) { -} diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/dto/response/MemberTopicPermissionDetailResponse.java b/backend/src/main/java/com/mapbefine/mapbefine/member/dto/response/MemberTopicPermissionDetailResponse.java deleted file mode 100644 index 50c554681..000000000 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/dto/response/MemberTopicPermissionDetailResponse.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.mapbefine.mapbefine.member.dto.response; - -import com.mapbefine.mapbefine.member.domain.MemberTopicPermission; -import java.time.LocalDateTime; - -public record MemberTopicPermissionDetailResponse( - Long id, - LocalDateTime updatedAt, - MemberDetailResponse memberDetailResponse -) { - - public static MemberTopicPermissionDetailResponse from(MemberTopicPermission memberTopicPermission) { - return new MemberTopicPermissionDetailResponse( - memberTopicPermission.getId(), - memberTopicPermission.getUpdatedAt(), - MemberDetailResponse.from(memberTopicPermission.getMember()) - ); - } - -} diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/dto/response/MemberTopicPermissionResponse.java b/backend/src/main/java/com/mapbefine/mapbefine/member/dto/response/MemberTopicPermissionResponse.java deleted file mode 100644 index 0e0dc6daa..000000000 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/dto/response/MemberTopicPermissionResponse.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.mapbefine.mapbefine.member.dto.response; - -import com.mapbefine.mapbefine.member.domain.MemberTopicPermission; - -public record MemberTopicPermissionResponse( - Long id, - MemberResponse memberResponse -) { - - public static MemberTopicPermissionResponse from(MemberTopicPermission memberTopicPermission) { - return new MemberTopicPermissionResponse( - memberTopicPermission.getId(), - MemberResponse.from(memberTopicPermission.getMember()) - ); - } - -} diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/presentation/MemberController.java b/backend/src/main/java/com/mapbefine/mapbefine/member/presentation/MemberController.java index 7a189e309..b2165c32a 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/presentation/MemberController.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/member/presentation/MemberController.java @@ -2,23 +2,15 @@ import com.mapbefine.mapbefine.auth.domain.AuthMember; import com.mapbefine.mapbefine.common.interceptor.LoginRequired; -import com.mapbefine.mapbefine.member.application.MemberCommandService; import com.mapbefine.mapbefine.member.application.MemberQueryService; -import com.mapbefine.mapbefine.member.dto.request.MemberTopicPermissionCreateRequest; import com.mapbefine.mapbefine.member.dto.response.MemberDetailResponse; import com.mapbefine.mapbefine.member.dto.response.MemberResponse; -import com.mapbefine.mapbefine.member.dto.response.MemberTopicPermissionDetailResponse; -import com.mapbefine.mapbefine.member.dto.response.MemberTopicPermissionResponse; import com.mapbefine.mapbefine.pin.dto.response.PinResponse; import com.mapbefine.mapbefine.topic.dto.response.TopicResponse; -import java.net.URI; import java.util.List; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -26,26 +18,18 @@ @RequestMapping("/members") public class MemberController { - private final MemberCommandService memberCommandService; private final MemberQueryService memberQueryService; - public MemberController( - MemberCommandService memberCommandService, - MemberQueryService memberQueryService - ) { - this.memberCommandService = memberCommandService; + public MemberController(MemberQueryService memberQueryService) { this.memberQueryService = memberQueryService; } @LoginRequired - @PostMapping("/permissions") - public ResponseEntity addMemberTopicPermission( - AuthMember authMember, - @RequestBody MemberTopicPermissionCreateRequest request - ) { - Long savedId = memberCommandService.saveMemberTopicPermission(authMember, request); + @GetMapping + public ResponseEntity> findAllMember() { + List responses = memberQueryService.findAll(); - return ResponseEntity.created(URI.create("/members/permissions/" + savedId)).build(); + return ResponseEntity.ok(responses); } @LoginRequired @@ -56,14 +40,6 @@ public ResponseEntity findMemberById(@PathVariable Long me return ResponseEntity.ok(response); } - @LoginRequired - @GetMapping - public ResponseEntity> findAllMember() { - List responses = memberQueryService.findAll(); - - return ResponseEntity.ok(responses); - } - @LoginRequired @GetMapping("/topics") public ResponseEntity> findTopicsByMember(AuthMember authMember) { @@ -80,32 +56,4 @@ public ResponseEntity> findPinsByMember(AuthMember authMember) return ResponseEntity.ok(responses); } - @LoginRequired - @GetMapping("/permissions/topics/{topicId}") - public ResponseEntity> findMemberTopicPermissionAll( - @PathVariable Long topicId - ) { - List responses = memberQueryService.findAllWithPermission(topicId); - - return ResponseEntity.ok(responses); - } - - @LoginRequired - @GetMapping("/permissions/{permissionId}") - public ResponseEntity findMemberTopicPermissionById( - @PathVariable Long permissionId - ) { - MemberTopicPermissionDetailResponse response = memberQueryService.findMemberTopicPermissionById(permissionId); - - return ResponseEntity.ok(response); - } - - @LoginRequired - @DeleteMapping("/permissions/{permissionId}") - public ResponseEntity deleteMemberTopicPermission(AuthMember authMember, @PathVariable Long permissionId) { - memberCommandService.deleteMemberTopicPermission(authMember, permissionId); - - return ResponseEntity.noContent().build(); - } - } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/oauth/presentation/OauthController.java b/backend/src/main/java/com/mapbefine/mapbefine/oauth/presentation/OauthController.java index 65d747f40..410697c9b 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/oauth/presentation/OauthController.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/oauth/presentation/OauthController.java @@ -5,7 +5,6 @@ import com.mapbefine.mapbefine.oauth.dto.LoginInfoResponse; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -31,7 +30,7 @@ public ResponseEntity redirection( String redirectUrl = oauthService.getAuthCodeRequestUrl(oauthServerType); response.sendRedirect(redirectUrl); - return ResponseEntity.status(HttpStatus.FOUND).build(); + return ResponseEntity.ok().build(); } @GetMapping("/login/{oauthServerType}") diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionCommandService.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionCommandService.java new file mode 100644 index 000000000..4a64110f6 --- /dev/null +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionCommandService.java @@ -0,0 +1,96 @@ +package com.mapbefine.mapbefine.permission.application; + +import com.mapbefine.mapbefine.auth.domain.AuthMember; +import com.mapbefine.mapbefine.member.domain.Member; +import com.mapbefine.mapbefine.member.domain.MemberRepository; +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.topic.domain.Topic; +import com.mapbefine.mapbefine.topic.domain.TopicRepository; +import java.util.NoSuchElementException; +import java.util.Objects; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +public class PermissionCommandService { + + private final MemberRepository memberRepository; + private final TopicRepository topicRepository; + private final PermissionRepository permissionRepository; + + public PermissionCommandService( + MemberRepository memberRepository, + TopicRepository topicRepository, + PermissionRepository permissionRepository + ) { + this.memberRepository = memberRepository; + this.topicRepository = topicRepository; + this.permissionRepository = permissionRepository; + } + + public Long savePermission(AuthMember authMember, PermissionRequest request) { + validateUser(authMember); + validateSelfPermission(authMember, request); + validateDuplicatePermission(request); + + Topic topic = findTopic(request); + validateMemberCanTopicUpdate(authMember, topic); + + Member member = findMember(request); + Permission permission = + Permission.createPermissionAssociatedWithTopicAndMember(topic, member); + + return permissionRepository.save(permission).getId(); + } + + private void validateUser(AuthMember authMember) { + if (Objects.isNull(authMember.getMemberId())) { + throw new IllegalArgumentException("Guest는 권한을 줄 수 없습니다."); + } + } + + private void validateSelfPermission(AuthMember authMember, PermissionRequest request) { + Long sourceMemberId = authMember.getMemberId(); + Long targetMemberId = request.memberId(); + + if (sourceMemberId.equals(targetMemberId)) { + throw new IllegalArgumentException("본인에게 권한을 줄 수 없습니다."); + } + } + + private void validateDuplicatePermission(PermissionRequest request) { + if (permissionRepository.existsByTopicIdAndMemberId(request.topicId(), request.memberId())) { + throw new IllegalArgumentException("권한은 중복으로 줄 수 없습니다."); + } + } + + private Topic findTopic(PermissionRequest request) { + return topicRepository.findById(request.topicId()) + .orElseThrow(NoSuchElementException::new); + } + + private void validateMemberCanTopicUpdate(AuthMember authMember, Topic topic) { + if (authMember.canTopicUpdate(topic)) { + return; + } + throw new IllegalArgumentException("해당 지도에서 다른 유저에게 권한을 줄 수 없습니다."); + } + + private Member findMember(PermissionRequest request) { + return memberRepository.findById(request.memberId()) + .orElseThrow(NoSuchElementException::new); + } + + public void deleteMemberTopicPermission(AuthMember authMember, Long permissionId) { + Permission permission = permissionRepository.findById(permissionId) + .orElseThrow(NoSuchElementException::new); + + validateMemberCanTopicUpdate(authMember, permission.getTopic()); + + permissionRepository.delete(permission); + } + +} 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 new file mode 100644 index 000000000..5ca53ba2f --- /dev/null +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionQueryService.java @@ -0,0 +1,35 @@ +package com.mapbefine.mapbefine.permission.application; + +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 java.util.List; +import java.util.NoSuchElementException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +public class PermissionQueryService { + + private final PermissionRepository permissionRepository; + + public PermissionQueryService(PermissionRepository permissionRepository) { + this.permissionRepository = permissionRepository; + } + + public List findAllTopicPermissions(Long topicId) { + return permissionRepository.findAllByTopicId(topicId) + .stream() + .map(PermissionResponse::from) + .toList(); + } + + public PermissionDetailResponse findPermissionById(Long permissionId) { + Permission permission = permissionRepository.findById(permissionId) + .orElseThrow(NoSuchElementException::new); + + return PermissionDetailResponse.from(permission); + } +} diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/domain/MemberTopicPermission.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/domain/Permission.java similarity index 63% rename from backend/src/main/java/com/mapbefine/mapbefine/member/domain/MemberTopicPermission.java rename to backend/src/main/java/com/mapbefine/mapbefine/permission/domain/Permission.java index 2cd41de02..df3fe9ec2 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/domain/MemberTopicPermission.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/domain/Permission.java @@ -1,8 +1,9 @@ -package com.mapbefine.mapbefine.member.domain; +package com.mapbefine.mapbefine.permission.domain; import static lombok.AccessLevel.PROTECTED; import com.mapbefine.mapbefine.common.entity.BaseTimeEntity; +import com.mapbefine.mapbefine.member.domain.Member; import com.mapbefine.mapbefine.topic.domain.Topic; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -16,7 +17,7 @@ @Entity @NoArgsConstructor(access = PROTECTED) @Getter -public class MemberTopicPermission extends BaseTimeEntity { +public class Permission extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -30,20 +31,20 @@ public class MemberTopicPermission extends BaseTimeEntity { @JoinColumn(name = "member_id", nullable = false) private Member member; - private MemberTopicPermission(Topic topic, Member member) { + private Permission(Topic topic, Member member) { this.topic = topic; this.member = member; } - public static MemberTopicPermission createPermissionAssociatedWithTopicAndMember( + public static Permission createPermissionAssociatedWithTopicAndMember( Topic topic, Member member ) { - MemberTopicPermission memberTopicPermission = new MemberTopicPermission(topic, member); - topic.addMemberTopicPermission(memberTopicPermission); - member.addMemberTopicPermission(memberTopicPermission); + Permission permission = new Permission(topic, member); + topic.addMemberTopicPermission(permission); + member.addMemberTopicPermission(permission); - return memberTopicPermission; + return permission; } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/domain/PermissionRepository.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/domain/PermissionRepository.java new file mode 100644 index 000000000..da8dca9b9 --- /dev/null +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/domain/PermissionRepository.java @@ -0,0 +1,12 @@ +package com.mapbefine.mapbefine.permission.domain; + +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PermissionRepository extends JpaRepository { + + List findAllByTopicId(Long topicId); + + boolean existsByTopicIdAndMemberId(Long topicId, Long memberId); + +} diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/request/PermissionRequest.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/request/PermissionRequest.java new file mode 100644 index 000000000..a0dd1f421 --- /dev/null +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/request/PermissionRequest.java @@ -0,0 +1,7 @@ +package com.mapbefine.mapbefine.permission.dto.request; + +public record PermissionRequest( + Long topicId, + Long memberId +) { +} 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/PermissionDetailResponse.java new file mode 100644 index 000000000..967fa8eb5 --- /dev/null +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionDetailResponse.java @@ -0,0 +1,21 @@ +package com.mapbefine.mapbefine.permission.dto.response; + +import com.mapbefine.mapbefine.member.dto.response.MemberDetailResponse; +import com.mapbefine.mapbefine.permission.domain.Permission; +import java.time.LocalDateTime; + +public record PermissionDetailResponse( + Long id, + LocalDateTime updatedAt, + MemberDetailResponse memberDetailResponse +) { + + public static PermissionDetailResponse from(Permission permission) { + return new PermissionDetailResponse( + 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/PermissionResponse.java new file mode 100644 index 000000000..9c4f23689 --- /dev/null +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/dto/response/PermissionResponse.java @@ -0,0 +1,18 @@ +package com.mapbefine.mapbefine.permission.dto.response; + +import com.mapbefine.mapbefine.member.dto.response.MemberResponse; +import com.mapbefine.mapbefine.permission.domain.Permission; + +public record PermissionResponse( + Long id, + MemberResponse memberResponse +) { + + public static PermissionResponse from(Permission permission) { + return new PermissionResponse( + permission.getId(), + MemberResponse.from(permission.getMember()) + ); + } + +} 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 new file mode 100644 index 000000000..2cd732809 --- /dev/null +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/presentation/PermissionController.java @@ -0,0 +1,68 @@ +package com.mapbefine.mapbefine.permission.presentation; + +import com.mapbefine.mapbefine.auth.domain.AuthMember; +import com.mapbefine.mapbefine.common.interceptor.LoginRequired; +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.net.URI; +import java.util.List; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/permissions") +public class PermissionController { + + private final PermissionCommandService permissionCommandService; + private final PermissionQueryService permissionQueryService; + + public PermissionController( + PermissionCommandService permissionCommandService, + PermissionQueryService permissionQueryService + ) { + this.permissionCommandService = permissionCommandService; + this.permissionQueryService = permissionQueryService; + } + + @LoginRequired + @PostMapping + public ResponseEntity addPermission(AuthMember authMember, @RequestBody PermissionRequest request) { + Long savedId = permissionCommandService.savePermission(authMember, request); + + return ResponseEntity.created(URI.create("/permissions/" + savedId)).build(); + } + + @LoginRequired + @DeleteMapping("/{permissionId}") + public ResponseEntity deleteMemberTopicPermission(AuthMember authMember, @PathVariable Long permissionId) { + permissionCommandService.deleteMemberTopicPermission(authMember, permissionId); + + return ResponseEntity.noContent().build(); + } + + @LoginRequired + @GetMapping("/topics/{topicId}") + public ResponseEntity> findAllTopicPermissions(@PathVariable Long topicId) { + List responses = permissionQueryService.findAllTopicPermissions(topicId); + + return ResponseEntity.ok(responses); + } + + @LoginRequired + @GetMapping("/{permissionId}") + public ResponseEntity findPermissionById(@PathVariable Long permissionId) { + PermissionDetailResponse response = permissionQueryService.findPermissionById(permissionId); + + return ResponseEntity.ok(response); + } + +} diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicCommandService.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicCommandService.java index 96e1d024d..1145a860b 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicCommandService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicCommandService.java @@ -56,7 +56,7 @@ private Topic convertToTopic(AuthMember member, TopicCreateRequest request) { request.description(), request.image(), request.publicity(), - request.permission(), + request.permissionType(), creator ); } @@ -126,7 +126,7 @@ private Topic convertToTopic(AuthMember member, TopicMergeRequest request) { request.description(), request.image(), request.publicity(), - request.permission(), + request.permissionType(), creator ); } @@ -168,7 +168,7 @@ public void updateTopicInfo( validateUpdateAuth(member, topic); topic.updateTopicInfo(request.name(), request.description(), request.image()); - topic.updateTopicStatus(request.publicity(), request.permission()); + topic.updateTopicStatus(request.publicity(), request.permissionType()); } private Topic findTopic(Long topicId) { diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/Permission.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/PermissionType.java similarity index 85% rename from backend/src/main/java/com/mapbefine/mapbefine/topic/domain/Permission.java rename to backend/src/main/java/com/mapbefine/mapbefine/topic/domain/PermissionType.java index a5f0ac532..aa145d4ad 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/Permission.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/domain/PermissionType.java @@ -3,14 +3,14 @@ import lombok.Getter; @Getter -public enum Permission { +public enum PermissionType { ALL_MEMBERS("모든 회원"), GROUP_ONLY("소속 회원"); private final String title; - Permission(String title) { + PermissionType(String title) { this.title = title; } 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 f9d62f9fb..ba6f9ec3e 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 @@ -4,7 +4,7 @@ import com.mapbefine.mapbefine.common.entity.BaseTimeEntity; import com.mapbefine.mapbefine.member.domain.Member; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermission; +import com.mapbefine.mapbefine.permission.domain.Permission; import com.mapbefine.mapbefine.pin.domain.Pin; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; @@ -42,7 +42,7 @@ public class Topic extends BaseTimeEntity { private Member creator; @OneToMany(mappedBy = "topic") - private List memberTopicPermissions = new ArrayList<>(); + private List permissions = new ArrayList<>(); @OneToMany(mappedBy = "topic", cascade = CascadeType.PERSIST) private List pins = new ArrayList<>(); @@ -66,11 +66,11 @@ public static Topic createTopicAssociatedWithCreator( String description, String imageUrl, Publicity publicity, - Permission permission, + PermissionType permissionType, Member creator ) { TopicInfo topicInfo = TopicInfo.of(name, description, imageUrl); - TopicStatus topicStatus = TopicStatus.of(publicity, permission); + TopicStatus topicStatus = TopicStatus.of(publicity, permissionType); Topic topic = new Topic(topicInfo, topicStatus, creator); creator.addTopic(topic); @@ -86,8 +86,8 @@ public void updateTopicInfo( this.topicInfo = TopicInfo.of(name, description, imageUrl); } - public void updateTopicStatus(Publicity publicity, Permission permission) { - topicStatus.update(publicity, permission); + public void updateTopicStatus(Publicity publicity, PermissionType permissionType) { + topicStatus.update(publicity, permissionType); } public int countPins() { @@ -98,8 +98,8 @@ public void addPin(Pin pin) { pins.add(pin); } - public void addMemberTopicPermission(MemberTopicPermission memberTopicPermission) { - memberTopicPermissions.add(memberTopicPermission); + public void addMemberTopicPermission(Permission permission) { + permissions.add(permission); } } 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 5e79662c0..1232830a1 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 @@ -21,50 +21,50 @@ public class TopicStatus { @Enumerated(EnumType.STRING) @Column(nullable = false) - private Permission permission; + private PermissionType permissionType; - private TopicStatus(Publicity publicity, Permission permission) { + private TopicStatus(Publicity publicity, PermissionType permissionType) { this.publicity = publicity; - this.permission = permission; + this.permissionType = permissionType; } - public static TopicStatus of(Publicity publicity, Permission permission) { - validateTopicStatus(publicity, permission); + public static TopicStatus of(Publicity publicity, PermissionType permissionType) { + validateTopicStatus(publicity, permissionType); - return new TopicStatus(publicity, permission); + return new TopicStatus(publicity, permissionType); } - private static void validateTopicStatus(Publicity publicity, Permission permission) { + private static void validateTopicStatus(Publicity publicity, PermissionType permissionType) { if (Objects.isNull(publicity)) { throw new IllegalArgumentException("공개 범위는 null일 수 없습니다."); } - if (Objects.isNull(permission)) { + if (Objects.isNull(permissionType)) { throw new IllegalArgumentException("권한 설정은 null일 수 없습니다."); } - if (publicity.isPrivate() && permission.isAllMembers()) { + if (publicity.isPrivate() && permissionType.isAllMembers()) { throw new IllegalArgumentException("공개 범위가 혼자 볼 지도인 경우, 권한 설정이 소속 회원이어야합니다."); } } - public void update(Publicity publicity, Permission permission) { - validatePublicity(publicity, permission); - validatePermission(permission); + public void update(Publicity publicity, PermissionType permissionType) { + validatePublicity(publicity, permissionType); + validatePermission(permissionType); this.publicity = publicity; - this.permission = permission; + this.permissionType = permissionType; } - private void validatePublicity(Publicity publicity, Permission permission) { - if (publicity.isPrivate() && permission.isAllMembers()) { + private void validatePublicity(Publicity publicity, PermissionType permissionType) { + if (publicity.isPrivate() && permissionType.isAllMembers()) { throw new IllegalArgumentException("권한 범위가 모든 멤버인 경우, 공개 범위를 혼자 볼 지도로 설정할 수 없습니다."); } } // TODO: 2023/08/09 해당 정책으로 인해, TopicStatus는 불변 객체로 만들 수 없을까 ? - private void validatePermission(Permission permission) { - if (this.permission.isAllMembers() && permission.isGroupOnly()) { + private void validatePermission(PermissionType permissionType) { + if (this.permissionType.isAllMembers() && permissionType.isGroupOnly()) { throw new IllegalArgumentException("권한 범위는 줄어들 수 없습니다."); } } @@ -78,11 +78,11 @@ public boolean isPrivate() { } public boolean isAllMembers() { - return permission.isAllMembers(); + return permissionType.isAllMembers(); } public boolean isGroupOnly() { - return permission.isGroupOnly(); + return permissionType.isGroupOnly(); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicCreateRequest.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicCreateRequest.java index 873d46c40..e7dc64c52 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicCreateRequest.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicCreateRequest.java @@ -1,6 +1,6 @@ package com.mapbefine.mapbefine.topic.dto.request; -import com.mapbefine.mapbefine.topic.domain.Permission; +import com.mapbefine.mapbefine.topic.domain.PermissionType; import com.mapbefine.mapbefine.topic.domain.Publicity; import java.util.List; @@ -9,7 +9,7 @@ public record TopicCreateRequest( String image, String description, Publicity publicity, - Permission permission, + PermissionType permissionType, List pins ) { } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicMergeRequest.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicMergeRequest.java index 18d468ace..deb14c79b 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicMergeRequest.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicMergeRequest.java @@ -1,6 +1,6 @@ package com.mapbefine.mapbefine.topic.dto.request; -import com.mapbefine.mapbefine.topic.domain.Permission; +import com.mapbefine.mapbefine.topic.domain.PermissionType; import com.mapbefine.mapbefine.topic.domain.Publicity; import java.util.List; @@ -9,7 +9,7 @@ public record TopicMergeRequest( String image, String description, Publicity publicity, - Permission permission, + PermissionType permissionType, List topics ) { } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicUpdateRequest.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicUpdateRequest.java index c3d616844..76bd803aa 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicUpdateRequest.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/request/TopicUpdateRequest.java @@ -1,6 +1,6 @@ package com.mapbefine.mapbefine.topic.dto.request; -import com.mapbefine.mapbefine.topic.domain.Permission; +import com.mapbefine.mapbefine.topic.domain.PermissionType; import com.mapbefine.mapbefine.topic.domain.Publicity; public record TopicUpdateRequest( @@ -8,7 +8,7 @@ public record TopicUpdateRequest( String image, String description, Publicity publicity, - Permission permission + PermissionType permissionType ) { } diff --git a/backend/src/test/java/com/mapbefine/mapbefine/member/application/MemberQueryServiceTest.java b/backend/src/test/java/com/mapbefine/mapbefine/member/application/MemberQueryServiceTest.java index db7757efe..db54086c0 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/member/application/MemberQueryServiceTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/member/application/MemberQueryServiceTest.java @@ -13,13 +13,9 @@ import com.mapbefine.mapbefine.member.MemberFixture; import com.mapbefine.mapbefine.member.domain.Member; import com.mapbefine.mapbefine.member.domain.MemberRepository; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermission; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermissionRepository; 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.member.dto.response.MemberTopicPermissionDetailResponse; -import com.mapbefine.mapbefine.member.dto.response.MemberTopicPermissionResponse; import com.mapbefine.mapbefine.pin.PinFixture; import com.mapbefine.mapbefine.pin.domain.Pin; import com.mapbefine.mapbefine.pin.domain.PinRepository; @@ -46,88 +42,12 @@ class MemberQueryServiceTest { @Autowired private MemberRepository memberRepository; - @Autowired - private MemberTopicPermissionRepository memberTopicPermissionRepository; - @Autowired private LocationRepository locationRepository; @Autowired private PinRepository pinRepository; - @Test - @DisplayName("Topic 에 권한이 있는자들을 모두 조회한다.") // creator 는 권한이 있는자들을 조회할 때 조회되어야 할 것인가?? - void findAllWithPermission() { - // given - Member member1InTopic1 = memberRepository.save( - MemberFixture.create("member", "member@naver.com", Role.USER) - ); - Member member2InTopic1 = memberRepository.save( - MemberFixture.create("members", "members@naver.com", Role.USER) - ); - Member member3InTopic2 = memberRepository.save( - MemberFixture.create("memberss", "memberss@naver.com", Role.USER) - ); - Topic topic1 = topicRepository.save(TopicFixture.createByName("topic1", member3InTopic2)); - Topic topic2 = topicRepository.save(TopicFixture.createByName("topic2", member1InTopic1)); - memberTopicPermissionRepository.save( - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic1, member1InTopic1) - ); - memberTopicPermissionRepository.save( - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic1, member2InTopic1) - ); - memberTopicPermissionRepository.save( - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic2, member3InTopic2) - ); - - // when - List memberTopicPermissionResponses = memberQueryService.findAllWithPermission(topic1.getId()); - MemberResponse memberResponse1 = MemberResponse.from(member1InTopic1); - MemberResponse memberResponse2 = MemberResponse.from(member2InTopic1); - - // then - assertThat(memberTopicPermissionResponses).hasSize(2) - .extracting(MemberTopicPermissionResponse::memberResponse) - .usingRecursiveComparison() - .isEqualTo(List.of(memberResponse1, memberResponse2)); - } - - @Test - @DisplayName("ID 를 통해서 토픽에 권한이 있는자를 조회한다.") - void findMemberTopicPermissionById() { - // given - Member creator = memberRepository.save( - MemberFixture.create("member", "member@naver.com", Role.USER) - ); - Member permissionUser = memberRepository.save( - MemberFixture.create("members", "members@naver.com", Role.USER) - ); - Topic topic = topicRepository.save(TopicFixture.createByName("topic", creator)); - Long savedId = memberTopicPermissionRepository.save( - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, permissionUser) - ).getId(); - - // when - MemberTopicPermissionDetailResponse memberTopicPermissionDetailResponse = - memberQueryService.findMemberTopicPermissionById(savedId); - MemberDetailResponse permissionUserResponse = MemberDetailResponse.from(permissionUser); - - // then - assertThat(memberTopicPermissionDetailResponse) - .extracting(MemberTopicPermissionDetailResponse::memberDetailResponse) - .usingRecursiveComparison() - .isEqualTo(permissionUserResponse); - } - - @Test - @DisplayName("ID 를 통해서 토픽에 권한이 있는자를 조회하려 할 때, 결과가 존재하지 않을 때 예외가 발생한다.") - void findMemberTopicPermissionById_whenNoneExistsPermission_thenFail() { - // given when then - assertThatThrownBy(() -> memberQueryService.findMemberTopicPermissionById(Long.MAX_VALUE)) - .isInstanceOf(NoSuchElementException.class); - } - - @Test @DisplayName("유저 목록을 조회한다.") void findAllMember() { diff --git a/backend/src/test/java/com/mapbefine/mapbefine/member/presentation/MemberControllerTest.java b/backend/src/test/java/com/mapbefine/mapbefine/member/presentation/MemberControllerTest.java index 8d59d65d9..f92455c1d 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/member/presentation/MemberControllerTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/member/presentation/MemberControllerTest.java @@ -5,16 +5,9 @@ import static org.mockito.BDDMockito.given; import com.mapbefine.mapbefine.common.RestDocsIntegration; -import com.mapbefine.mapbefine.member.MemberFixture; -import com.mapbefine.mapbefine.member.application.MemberCommandService; import com.mapbefine.mapbefine.member.application.MemberQueryService; -import com.mapbefine.mapbefine.member.domain.Member; -import com.mapbefine.mapbefine.member.domain.Role; -import com.mapbefine.mapbefine.member.dto.request.MemberTopicPermissionCreateRequest; import com.mapbefine.mapbefine.member.dto.response.MemberDetailResponse; import com.mapbefine.mapbefine.member.dto.response.MemberResponse; -import com.mapbefine.mapbefine.member.dto.response.MemberTopicPermissionDetailResponse; -import com.mapbefine.mapbefine.member.dto.response.MemberTopicPermissionResponse; import com.mapbefine.mapbefine.pin.dto.response.PinResponse; import com.mapbefine.mapbefine.topic.dto.response.TopicResponse; import java.time.LocalDateTime; @@ -23,112 +16,13 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; class MemberControllerTest extends RestDocsIntegration { - @MockBean - private MemberCommandService memberCommandService; - @MockBean private MemberQueryService memberQueryService; - @Test - @DisplayName("권한 추가") - void addMemberTopicPermission() throws Exception { - Member member = MemberFixture.create("member", "member@naver.com", Role.ADMIN); - MemberTopicPermissionCreateRequest request = new MemberTopicPermissionCreateRequest( - 1L, - 2L - ); - String authHeader = Base64.encodeBase64String( - ("Basic " + member.getMemberInfo().getEmail()).getBytes() - ); - - given(memberCommandService.saveMemberTopicPermission(any(), any())).willReturn(1L); - - mockMvc.perform( - MockMvcRequestBuilders.post("/members/permissions") - .header(AUTHORIZATION, authHeader) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - ).andDo(restDocs.document()); - } - - @Test - @DisplayName("권한 삭제") - void deleteMemberTopicPermission() throws Exception { - Member member = MemberFixture.create("member", "member@naver.com", Role.ADMIN); - String authHeader = Base64.encodeBase64String( - ("Basic " + member.getMemberInfo().getEmail()).getBytes() - ); - - mockMvc.perform( - MockMvcRequestBuilders.delete("/members/permissions/1") - .header(AUTHORIZATION, authHeader) - ).andDo(restDocs.document()); - } - - @Test - @DisplayName("권한이 있는 자들 모두 조회") - void findMemberTopicPermissionAll() throws Exception { - List memberTopicPermissionResponses = List.of( - new MemberTopicPermissionResponse( - 1L, - new MemberResponse( - 1L, - "member", - "member@naver.com" - ) - ), - new MemberTopicPermissionResponse( - 1L, - new MemberResponse( - 2L, - "memberr", - "memberr@naver.com" - ) - ) - ); - String authHeader = Base64.encodeBase64String( - ("Basic " + memberTopicPermissionResponses.get(0).memberResponse().email()).getBytes() - ); - - given(memberQueryService.findAllWithPermission(any())).willReturn(memberTopicPermissionResponses); - - mockMvc.perform( - MockMvcRequestBuilders.get("/members/permissions/topics/1") - .header(AUTHORIZATION, authHeader) - ).andDo(restDocs.document()); - } - - @Test - @DisplayName("권한이 있는 자들 모두 조회") - void findMemberTopicPermissionById() throws Exception { - MemberTopicPermissionDetailResponse memberTopicPermissionDetailResponse = new MemberTopicPermissionDetailResponse( - 1L, - LocalDateTime.now(), - new MemberDetailResponse( - 1L, - "member", - "member@naver.com", - "https://map-befine-official.github.io/favicon.png", - LocalDateTime.now() - ) - ); - String authHeader = Base64.encodeBase64String( - ("Basic " + memberTopicPermissionDetailResponse.memberDetailResponse().email()).getBytes() - ); - - given(memberQueryService.findMemberTopicPermissionById(any())).willReturn(memberTopicPermissionDetailResponse); - - mockMvc.perform( - MockMvcRequestBuilders.get("/members/permissions/1") - .header(AUTHORIZATION, authHeader) - ).andDo(restDocs.document()); - } - @Test @DisplayName("유저 목록 조회") void findAllMember() throws Exception { diff --git a/backend/src/test/java/com/mapbefine/mapbefine/member/presentation/MemberIntegrationTest.java b/backend/src/test/java/com/mapbefine/mapbefine/member/presentation/MemberIntegrationTest.java index 42c4af81f..edd2fdb3d 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/member/presentation/MemberIntegrationTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/member/presentation/MemberIntegrationTest.java @@ -12,15 +12,10 @@ import com.mapbefine.mapbefine.member.MemberFixture; import com.mapbefine.mapbefine.member.domain.Member; import com.mapbefine.mapbefine.member.domain.MemberRepository; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermission; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermissionRepository; import com.mapbefine.mapbefine.member.domain.OauthId; import com.mapbefine.mapbefine.member.domain.Role; -import com.mapbefine.mapbefine.member.dto.request.MemberTopicPermissionCreateRequest; import com.mapbefine.mapbefine.member.dto.response.MemberDetailResponse; import com.mapbefine.mapbefine.member.dto.response.MemberResponse; -import com.mapbefine.mapbefine.member.dto.response.MemberTopicPermissionDetailResponse; -import com.mapbefine.mapbefine.member.dto.response.MemberTopicPermissionResponse; import com.mapbefine.mapbefine.pin.PinFixture; import com.mapbefine.mapbefine.pin.domain.Pin; import com.mapbefine.mapbefine.pin.domain.PinRepository; @@ -54,9 +49,6 @@ class MemberIntegrationTest extends IntegrationTest { @Autowired private LocationRepository locationRepository; - @Autowired - private MemberTopicPermissionRepository memberTopicPermissionRepository; - private Member creator; private Member user1; private Member user2; @@ -95,110 +87,6 @@ public void setUp() { user1AuthHeader = testAuthHeaderProvider.createAuthHeader(user1); } - @Test - @DisplayName("Topic 을 만든자가 특정 유저에게 권한을 준다.") - void addMemberTopicPermission() { - // given - Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); - - // when - MemberTopicPermissionCreateRequest request = new MemberTopicPermissionCreateRequest( - topic.getId(), - user1.getId() - ); - ExtractableResponse response = given().log().all() - .header(AUTHORIZATION, creatorAuthHeader) - .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(request) - .when().post("/members/permissions") - .then().log().all() - .extract(); - - // then - assertThat(response.header("Location")).isNotBlank(); - assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED.value()); - } - - @Test - @DisplayName("Topic 을 만든자가 특정 유저에게 권한을 삭제한다.") - void deleteMemberTopicPermission() { - // given - Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); - MemberTopicPermission memberTopicPermission = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, user1); - Long savedId = memberTopicPermissionRepository.save(memberTopicPermission).getId(); - - // when - ExtractableResponse response = given().log().all() - .header(AUTHORIZATION, creatorAuthHeader) - .when().delete("/members/permissions/" + savedId) - .then().log().all() - .extract(); - - // then - assertThat(response.statusCode()) - .isEqualTo(HttpStatus.NO_CONTENT.value()); - } - - @Test - @DisplayName("Topic 에 권한을 가진 자들을 모두 조회한다.") - void findMemberTopicPermissionAll() { - // given - Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); - MemberTopicPermission memberTopicPermission1 = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, user1); - MemberTopicPermission memberTopicPermission2 = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, user2); - memberTopicPermissionRepository.save(memberTopicPermission1); - memberTopicPermissionRepository.save(memberTopicPermission2); - - // when - ExtractableResponse response = given().log().all() - .header(AUTHORIZATION, creatorAuthHeader) - .when().get("/members/permissions/topics/" + topic.getId()) - .then().log().all() - .extract(); - - // then - List memberTopicPermissionResponses = response.as(new TypeRef<>() { - }); - assertThat(response.statusCode()) - .isEqualTo(HttpStatus.OK.value()); - assertThat(memberTopicPermissionResponses) - .hasSize(2) - .extracting(MemberTopicPermissionResponse::memberResponse) - .usingRecursiveComparison() - .isEqualTo(List.of(MemberResponse.from(user1), MemberResponse.from(user2))); - } - - @Test - @DisplayName("Topic 에 권한을 가진 자를 조회한다.") - void findMemberTopicPermissionById() { - // given - Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); - MemberTopicPermission memberTopicPermission = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, user1); - memberTopicPermission = memberTopicPermissionRepository.save(memberTopicPermission); - - // when - ExtractableResponse response = given().log().all() - .header(AUTHORIZATION, creatorAuthHeader) - .when().get("/members/permissions/" + memberTopicPermission.getId()) - .then().log().all() - .extract(); - - // then - MemberTopicPermissionDetailResponse memberTopicPermissionDetailResponse = response.as( - MemberTopicPermissionDetailResponse.class); - assertThat(response.statusCode()) - .isEqualTo(HttpStatus.OK.value()); - assertThat(memberTopicPermissionDetailResponse) - .extracting(MemberTopicPermissionDetailResponse::memberDetailResponse) - .usingRecursiveComparison() - .ignoringFieldsOfTypes(LocalDateTime.class) - .isEqualTo(MemberDetailResponse.from(user1)); - } - @Test @DisplayName("유저 목록을 조회한다.") void findAllMember() { diff --git a/backend/src/test/java/com/mapbefine/mapbefine/permission/PermissionIntegrationTest.java b/backend/src/test/java/com/mapbefine/mapbefine/permission/PermissionIntegrationTest.java new file mode 100644 index 000000000..12e82ae9c --- /dev/null +++ b/backend/src/test/java/com/mapbefine/mapbefine/permission/PermissionIntegrationTest.java @@ -0,0 +1,183 @@ +package com.mapbefine.mapbefine.permission; + +import static com.mapbefine.mapbefine.oauth.domain.OauthServerType.KAKAO; +import static io.restassured.RestAssured.*; +import static org.apache.http.HttpHeaders.AUTHORIZATION; +import static org.assertj.core.api.Assertions.assertThat; + +import com.mapbefine.mapbefine.common.IntegrationTest; +import com.mapbefine.mapbefine.member.MemberFixture; +import com.mapbefine.mapbefine.member.domain.Member; +import com.mapbefine.mapbefine.member.domain.MemberRepository; +import com.mapbefine.mapbefine.member.domain.OauthId; +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.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.topic.TopicFixture; +import com.mapbefine.mapbefine.topic.domain.Topic; +import com.mapbefine.mapbefine.topic.domain.TopicRepository; +import io.restassured.common.mapper.*; +import io.restassured.response.*; +import java.time.LocalDateTime; +import java.util.List; +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; +import org.springframework.http.MediaType; + +public class PermissionIntegrationTest extends IntegrationTest { + + @Autowired + private MemberRepository memberRepository; + @Autowired + private TopicRepository topicRepository; + @Autowired + private PermissionRepository permissionRepository; + + private Member creator; + private Member user1; + private Member user2; + private String creatorAuthHeader; + + @Override + @BeforeEach + public void setUp() { + super.setUp(); + creator = memberRepository.save( + MemberFixture.createWithOauthId( + "creator", + "creator@naver.com", + Role.USER, + new OauthId(1L, KAKAO) + ) + ); + user1 = memberRepository.save( + MemberFixture.createWithOauthId( + "user1", + "user1@naver.com", + Role.USER, + new OauthId(2L, KAKAO) + ) + ); + user2 = memberRepository.save( + MemberFixture.createWithOauthId( + "user2", + "user2@naver.com", + Role.USER, + new OauthId(3L, KAKAO) + ) + ); + creatorAuthHeader = testAuthHeaderProvider.createAuthHeader(creator); + } + + @Test + @DisplayName("Topic 을 만든자가 특정 유저에게 권한을 준다.") + void addPermission() { + // given + Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); + + // when + PermissionRequest request = new PermissionRequest(topic.getId(), user1.getId()); + + ExtractableResponse response = given().log().all() + .header(AUTHORIZATION, creatorAuthHeader) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .body(request) + .when().post("/permissions") + .then().log().all() + .extract(); + + // then + assertThat(response.header("Location")).isNotBlank(); + assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED.value()); + } + + @Test + @DisplayName("Topic 을 만든자가 특정 유저에게 권한을 삭제한다.") + void deletePermission() { + // given + Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); + Permission permission = + Permission.createPermissionAssociatedWithTopicAndMember(topic, user1); + Long savedId = permissionRepository.save(permission).getId(); + + // when + ExtractableResponse response = given().log().all() + .header(AUTHORIZATION, creatorAuthHeader) + .when().delete("/permissions/" + savedId) + .then().log().all() + .extract(); + + // then + assertThat(response.statusCode()) + .isEqualTo(HttpStatus.NO_CONTENT.value()); + } + + @Test + @DisplayName("Topic 에 권한을 가진 자들을 모두 조회한다.") + void findMemberTopicPermissionAll() { + // given + Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); + Permission permission1 = + Permission.createPermissionAssociatedWithTopicAndMember(topic, user1); + Permission permission2 = + Permission.createPermissionAssociatedWithTopicAndMember(topic, user2); + permissionRepository.save(permission1); + permissionRepository.save(permission2); + + // when + ExtractableResponse response = given().log().all() + .header(AUTHORIZATION, creatorAuthHeader) + .when().get("/permissions/topics/" + topic.getId()) + .then().log().all() + .extract(); + + // then + List permissionResponse = response.as(new TypeRef<>() { + }); + assertThat(response.statusCode()) + .isEqualTo(HttpStatus.OK.value()); + assertThat(permissionResponse) + .hasSize(2) + .extracting(PermissionResponse::memberResponse) + .usingRecursiveComparison() + .isEqualTo(List.of(MemberResponse.from(user1), MemberResponse.from(user2))); + } + + @Test + @DisplayName("Topic 에 권한을 가진 자를 조회한다.") + void findMemberTopicPermissionById() { + // given + Topic topic = topicRepository.save(TopicFixture.createByName("topicName", creator)); + Permission permission = + Permission.createPermissionAssociatedWithTopicAndMember(topic, user1); + permission = permissionRepository.save(permission); + + // when + ExtractableResponse response = given().log().all() + .header(AUTHORIZATION, creatorAuthHeader) + .when().get("/permissions/" + permission.getId()) + .then().log().all() + .extract(); + + // then + PermissionDetailResponse permissionDetailResponse = response.as( + PermissionDetailResponse.class); + assertThat(response.statusCode()) + .isEqualTo(HttpStatus.OK.value()); + assertThat(permissionDetailResponse) + .extracting(PermissionDetailResponse::memberDetailResponse) + .usingRecursiveComparison() + .ignoringFieldsOfTypes(LocalDateTime.class) + .isEqualTo(MemberDetailResponse.from(user1)); + } + + +} diff --git a/backend/src/test/java/com/mapbefine/mapbefine/member/application/MemberCommandServiceTest.java b/backend/src/test/java/com/mapbefine/mapbefine/permission/application/PermissionCommandServiceTest.java similarity index 74% rename from backend/src/test/java/com/mapbefine/mapbefine/member/application/MemberCommandServiceTest.java rename to backend/src/test/java/com/mapbefine/mapbefine/permission/application/PermissionCommandServiceTest.java index 4e697d050..4d7352762 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/member/application/MemberCommandServiceTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/permission/application/PermissionCommandServiceTest.java @@ -1,4 +1,4 @@ -package com.mapbefine.mapbefine.member.application; +package com.mapbefine.mapbefine.permission.application; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -10,13 +10,11 @@ import com.mapbefine.mapbefine.common.annotation.ServiceTest; import com.mapbefine.mapbefine.member.MemberFixture; import com.mapbefine.mapbefine.member.domain.Member; -import com.mapbefine.mapbefine.member.domain.MemberInfo; import com.mapbefine.mapbefine.member.domain.MemberRepository; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermission; -import com.mapbefine.mapbefine.member.domain.MemberTopicPermissionRepository; import com.mapbefine.mapbefine.member.domain.Role; -import com.mapbefine.mapbefine.member.dto.request.MemberCreateRequest; -import com.mapbefine.mapbefine.member.dto.request.MemberTopicPermissionCreateRequest; +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.topic.TopicFixture; import com.mapbefine.mapbefine.topic.domain.Topic; import com.mapbefine.mapbefine.topic.domain.TopicRepository; @@ -27,10 +25,10 @@ import org.springframework.beans.factory.annotation.Autowired; @ServiceTest -class MemberCommandServiceTest { +class PermissionCommandServiceTest { @Autowired - private MemberCommandService memberCommandService; + private PermissionCommandService permissionCommandService; @Autowired private TopicRepository topicRepository; @@ -39,7 +37,7 @@ class MemberCommandServiceTest { private MemberRepository memberRepository; @Autowired - private MemberTopicPermissionRepository memberTopicPermissionRepository; + private PermissionRepository permissionRepository; @Test @DisplayName("Admin 이 권한을 주는 경우 정상적으로 권한이 주어진다.") @@ -49,16 +47,16 @@ void saveMemberTopicPermissionByAdmin() { Member member = memberRepository.save(MemberFixture.create("members", "members@naver.com", Role.USER)); Topic topic = topicRepository.save(TopicFixture.createByName("topic", admin)); AuthMember authAdmin = new Admin(admin.getId()); - MemberTopicPermissionCreateRequest request = new MemberTopicPermissionCreateRequest( + PermissionRequest request = new PermissionRequest( topic.getId(), member.getId() ); // when - Long savedId = memberCommandService.saveMemberTopicPermission(authAdmin, request); - MemberTopicPermission memberTopicPermission = memberTopicPermissionRepository.findById(savedId) + Long savedId = permissionCommandService.savePermission(authAdmin, request); + Permission permission = permissionRepository.findById(savedId) .orElseThrow(NoSuchElementException::new); - Member memberWithPermission = memberTopicPermission.getMember(); + Member memberWithPermission = permission.getMember(); // then assertThat(member).usingRecursiveComparison() @@ -78,16 +76,16 @@ void saveMemberTopicPermissionByCreator() { getCreatedTopics(creator), getTopicsWithPermission(creator) ); - MemberTopicPermissionCreateRequest request = new MemberTopicPermissionCreateRequest( + PermissionRequest request = new PermissionRequest( topic.getId(), member.getId() ); // when - Long savedId = memberCommandService.saveMemberTopicPermission(authCreator, request); - MemberTopicPermission memberTopicPermission = memberTopicPermissionRepository.findById(savedId) + Long savedId = permissionCommandService.savePermission(authCreator, request); + Permission permission = permissionRepository.findById(savedId) .orElseThrow(NoSuchElementException::new); - Member memberWithPermission = memberTopicPermission.getMember(); + Member memberWithPermission = permission.getMember(); // then assertThat(member).usingRecursiveComparison() @@ -108,13 +106,13 @@ void saveMemberTopicPermissionByUser() { getCreatedTopics(notCreator), getTopicsWithPermission(notCreator) ); - MemberTopicPermissionCreateRequest request = new MemberTopicPermissionCreateRequest( + PermissionRequest request = new PermissionRequest( topic.getId(), member.getId() ); // when then - assertThatThrownBy(() -> memberCommandService.saveMemberTopicPermission(authNotCreator, request)) + assertThatThrownBy(() -> permissionCommandService.savePermission(authNotCreator, request)) .isInstanceOf(IllegalArgumentException.class); } @@ -126,13 +124,13 @@ void saveMemberTopicPermissionByGuest() { Member member = memberRepository.save(MemberFixture.create("memberss", "memberss@naver.com", Role.USER)); Topic topic = topicRepository.save(TopicFixture.createByName("topic", creator)); AuthMember guest = new Guest(); - MemberTopicPermissionCreateRequest request = new MemberTopicPermissionCreateRequest( + PermissionRequest request = new PermissionRequest( topic.getId(), member.getId() ); // when then - assertThatThrownBy(() -> memberCommandService.saveMemberTopicPermission(guest, request)) + assertThatThrownBy(() -> permissionCommandService.savePermission(guest, request)) .isInstanceOf(IllegalArgumentException.class); } @@ -147,13 +145,13 @@ void saveMemberTopicPermissionByCreator_whenSelf_thenFail() { getCreatedTopics(creator), getTopicsWithPermission(creator) ); - MemberTopicPermissionCreateRequest request = new MemberTopicPermissionCreateRequest( + PermissionRequest request = new PermissionRequest( topic.getId(), creator.getId() ); // when then - assertThatThrownBy(() -> memberCommandService.saveMemberTopicPermission(authCreator, request)) + assertThatThrownBy(() -> permissionCommandService.savePermission(authCreator, request)) .isInstanceOf(IllegalArgumentException.class); } @@ -176,21 +174,21 @@ void saveMemberTopicPermissionByCreator_whenDuplicate_thenFail() { ) ); Topic topic = topicRepository.save(TopicFixture.createByName("topic", creator)); - MemberTopicPermission memberTopicPermission = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, member); - memberTopicPermissionRepository.save(memberTopicPermission); + Permission permission = + Permission.createPermissionAssociatedWithTopicAndMember(topic, member); + permissionRepository.save(permission); AuthMember authCreator = new User( creator.getId(), getCreatedTopics(creator), getTopicsWithPermission(creator) ); - MemberTopicPermissionCreateRequest request = new MemberTopicPermissionCreateRequest( + PermissionRequest request = new PermissionRequest( topic.getId(), member.getId() ); // when then - assertThatThrownBy(() -> memberCommandService.saveMemberTopicPermission(authCreator, request)) + assertThatThrownBy(() -> permissionCommandService.savePermission(authCreator, request)) .isInstanceOf(IllegalArgumentException.class); } @@ -204,10 +202,10 @@ void deleteMemberTopicPermissionByAdmin() { AuthMember authAdmin = new Admin(admin.getId()); // when - MemberTopicPermission memberTopicPermission = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, member); - Long savedId = memberTopicPermissionRepository.save(memberTopicPermission).getId(); - memberCommandService.deleteMemberTopicPermission(authAdmin, savedId); + Permission permission = + Permission.createPermissionAssociatedWithTopicAndMember(topic, member); + Long savedId = permissionRepository.save(permission).getId(); + permissionCommandService.deleteMemberTopicPermission(authAdmin, savedId); // then assertThat(memberRepository.existsById(savedId)).isFalse(); @@ -227,10 +225,10 @@ void deleteMemberTopicPermissionByCreator() { ); // when - MemberTopicPermission memberTopicPermission = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, member); - Long savedId = memberTopicPermissionRepository.save(memberTopicPermission).getId(); - memberCommandService.deleteMemberTopicPermission(authCreator, savedId); + Permission permission = + Permission.createPermissionAssociatedWithTopicAndMember(topic, member); + Long savedId = permissionRepository.save(permission).getId(); + permissionCommandService.deleteMemberTopicPermission(authCreator, savedId); // then assertThat(memberRepository.existsById(savedId)).isFalse(); @@ -251,12 +249,12 @@ void deleteMemberTopicPermissionByUser() { ); // when - MemberTopicPermission memberTopicPermission = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, member); - Long savedId = memberTopicPermissionRepository.save(memberTopicPermission).getId(); + Permission permission = + Permission.createPermissionAssociatedWithTopicAndMember(topic, member); + Long savedId = permissionRepository.save(permission).getId(); // then - assertThatThrownBy(() -> memberCommandService.deleteMemberTopicPermission(authNonCreator, savedId)) + assertThatThrownBy(() -> permissionCommandService.deleteMemberTopicPermission(authNonCreator, savedId)) .isInstanceOf(IllegalArgumentException.class); } @@ -278,7 +276,7 @@ void deleteMemberTopicPermissionByCreator_whenNoneExistsPermission_thenFail() { ); // when then - assertThatThrownBy(() -> memberCommandService.deleteMemberTopicPermission(authCreator, Long.MAX_VALUE)) + assertThatThrownBy(() -> permissionCommandService.deleteMemberTopicPermission(authCreator, Long.MAX_VALUE)) .isInstanceOf(NoSuchElementException.class); } 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 new file mode 100644 index 000000000..ba66c1229 --- /dev/null +++ b/backend/src/test/java/com/mapbefine/mapbefine/permission/application/PermissionQueryServiceTest.java @@ -0,0 +1,112 @@ +package com.mapbefine.mapbefine.permission.application; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.mapbefine.mapbefine.common.annotation.ServiceTest; +import com.mapbefine.mapbefine.member.MemberFixture; +import com.mapbefine.mapbefine.member.domain.Member; +import com.mapbefine.mapbefine.member.domain.MemberRepository; +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.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.topic.TopicFixture; +import com.mapbefine.mapbefine.topic.domain.Topic; +import com.mapbefine.mapbefine.topic.domain.TopicRepository; +import java.util.List; +import java.util.NoSuchElementException; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +@ServiceTest +class PermissionQueryServiceTest { + + @Autowired + private MemberRepository memberRepository; + @Autowired + private TopicRepository topicRepository; + @Autowired + private PermissionRepository permissionRepository; + @Autowired + private PermissionQueryService permissionQueryService; + + @Test + @DisplayName("Topic 에 권한이 있는자들을 모두 조회한다.") + // creator 는 권한이 있는자들을 조회할 때 조회되어야 할 것인가?? + void findAllWithPermission() { + // given + Member member1InTopic1 = memberRepository.save( + MemberFixture.create("member", "member@naver.com", Role.USER) + ); + Member member2InTopic1 = memberRepository.save( + MemberFixture.create("members", "members@naver.com", Role.USER) + ); + Member member3InTopic2 = memberRepository.save( + MemberFixture.create("memberss", "memberss@naver.com", Role.USER) + ); + Topic topic1 = topicRepository.save(TopicFixture.createByName("topic1", member3InTopic2)); + Topic topic2 = topicRepository.save(TopicFixture.createByName("topic2", member1InTopic1)); + permissionRepository.save( + Permission.createPermissionAssociatedWithTopicAndMember(topic1, member1InTopic1) + ); + permissionRepository.save( + Permission.createPermissionAssociatedWithTopicAndMember(topic1, member2InTopic1) + ); + permissionRepository.save( + Permission.createPermissionAssociatedWithTopicAndMember(topic2, member3InTopic2) + ); + + // when + List permissionRespons = permissionQueryService.findAllTopicPermissions(topic1.getId()); + MemberResponse memberResponse1 = MemberResponse.from(member1InTopic1); + MemberResponse memberResponse2 = MemberResponse.from(member2InTopic1); + + // then + assertThat(permissionRespons).hasSize(2) + .extracting(PermissionResponse::memberResponse) + .usingRecursiveComparison() + .isEqualTo(List.of(memberResponse1, memberResponse2)); + } + + @Test + @DisplayName("ID 를 통해서 토픽에 권한이 있는자를 조회한다.") + void findMemberTopicPermissionById() { + // given + Member creator = memberRepository.save( + MemberFixture.create("member", "member@naver.com", Role.USER) + ); + Member permissionUser = memberRepository.save( + MemberFixture.create("members", "members@naver.com", Role.USER) + ); + Topic topic = topicRepository.save(TopicFixture.createByName("topic", creator)); + Long savedId = permissionRepository.save( + Permission.createPermissionAssociatedWithTopicAndMember(topic, permissionUser) + ).getId(); + + // when + PermissionDetailResponse permissionDetailResponse = + permissionQueryService.findPermissionById(savedId); + MemberDetailResponse permissionUserResponse = MemberDetailResponse.from(permissionUser); + + // then + assertThat(permissionDetailResponse) + .extracting(PermissionDetailResponse::memberDetailResponse) + .usingRecursiveComparison() + .isEqualTo(permissionUserResponse); + } + + @Test + @DisplayName("ID 를 통해서 토픽에 권한이 있는자를 조회하려 할 때, 결과가 존재하지 않을 때 예외가 발생한다.") + void findMemberTopicPermissionById_whenNoneExistsPermission_thenFail() { + // given when then + assertThatThrownBy(() -> permissionQueryService.findPermissionById(Long.MAX_VALUE)) + .isInstanceOf(NoSuchElementException.class); + } + + +} diff --git a/backend/src/test/java/com/mapbefine/mapbefine/member/domain/MemberTopicPermissionTest.java b/backend/src/test/java/com/mapbefine/mapbefine/permission/domain/PermissionTest.java similarity index 65% rename from backend/src/test/java/com/mapbefine/mapbefine/member/domain/MemberTopicPermissionTest.java rename to backend/src/test/java/com/mapbefine/mapbefine/permission/domain/PermissionTest.java index ec058f00a..d2778835b 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/member/domain/MemberTopicPermissionTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/permission/domain/PermissionTest.java @@ -1,19 +1,21 @@ -package com.mapbefine.mapbefine.member.domain; +package com.mapbefine.mapbefine.permission.domain; import static org.assertj.core.api.Assertions.assertThat; import com.mapbefine.mapbefine.member.MemberFixture; +import com.mapbefine.mapbefine.member.domain.Member; +import com.mapbefine.mapbefine.member.domain.Role; import com.mapbefine.mapbefine.topic.TopicFixture; import com.mapbefine.mapbefine.topic.domain.Topic; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -class MemberTopicPermissionTest { +class PermissionTest { @Test @DisplayName("정상적인 값을 입력하면 객체가 생성된다.") - void createMemberTopicPermission() { + void createPermission() { // given Member member = MemberFixture.create( "member", @@ -23,14 +25,14 @@ void createMemberTopicPermission() { Topic topic = TopicFixture.createByName("topic", member); // when - MemberTopicPermission memberTopicPermission = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, member); + Permission permission = + Permission.createPermissionAssociatedWithTopicAndMember(topic, member); // then - assertThat(memberTopicPermission.getMember()).usingRecursiveComparison() + assertThat(permission.getMember()).usingRecursiveComparison() .ignoringFields("createdAt", "updatedAt") .isEqualTo(member); - assertThat(memberTopicPermission.getTopic()).usingRecursiveComparison() + assertThat(permission.getTopic()).usingRecursiveComparison() .ignoringFields("createdAt", "updatedAt") .isEqualTo(topic); } @@ -47,20 +49,20 @@ void createPermissionAssociatedWithTopicAndMember() { Topic topic = TopicFixture.createByName("topic", member); // when - MemberTopicPermission memberTopicPermission = - MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, member); + Permission permission = + Permission.createPermissionAssociatedWithTopicAndMember(topic, member); List topicsWithPermission = member.getTopicsWithPermissions(); - List memberTopicPermissions = topic.getMemberTopicPermissions(); + List permissions = topic.getPermissions(); // then assertThat(topicsWithPermission).hasSize(1); - assertThat(memberTopicPermissions).hasSize(1); + assertThat(permissions).hasSize(1); assertThat(topicsWithPermission.get(0)).usingRecursiveComparison() .ignoringFields("createdAt", "updatedAt") .isEqualTo(topic); - assertThat(memberTopicPermissions.get(0)).usingRecursiveComparison() + assertThat(permissions.get(0)).usingRecursiveComparison() .ignoringFields("createdAt", "updatedAt") - .isEqualTo(memberTopicPermission); + .isEqualTo(permission); } } 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 new file mode 100644 index 000000000..aa9b1db6c --- /dev/null +++ b/backend/src/test/java/com/mapbefine/mapbefine/permission/presentation/PermissionControllerTest.java @@ -0,0 +1,126 @@ +package com.mapbefine.mapbefine.permission.presentation; + +import static org.apache.http.HttpHeaders.AUTHORIZATION; +import static org.mockito.ArgumentMatchers.any; +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 java.time.LocalDateTime; +import java.util.List; +import org.apache.tomcat.util.codec.binary.Base64; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +class PermissionControllerTest extends RestDocsIntegration { + + @MockBean + private PermissionCommandService permissionCommandService; + @MockBean + private PermissionQueryService permissionQueryService; + + @Test + @DisplayName("권한 추가") + void addPermission() throws Exception { + Member member = MemberFixture.create("member", "member@naver.com", Role.ADMIN); + PermissionRequest request = new PermissionRequest(1L, 2L); + String authHeader = Base64.encodeBase64String( + ("Basic " + member.getMemberInfo().getEmail()).getBytes() + ); + + given(permissionCommandService.savePermission(any(), any())).willReturn(1L); + + mockMvc.perform( + MockMvcRequestBuilders.post("/permissions") + .header(AUTHORIZATION, authHeader) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ).andDo(restDocs.document()); + } + + @Test + @DisplayName("권한 삭제") + void deletePermission() throws Exception { + Member member = MemberFixture.create("member", "member@naver.com", Role.ADMIN); + String authHeader = Base64.encodeBase64String( + ("Basic " + member.getMemberInfo().getEmail()).getBytes() + ); + + mockMvc.perform( + MockMvcRequestBuilders.delete("/permissions/1") + .header(AUTHORIZATION, authHeader) + ).andDo(restDocs.document()); + } + + @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" + ) + ) + ); + String authHeader = Base64.encodeBase64String( + ("Basic " + permissionResponses.get(0).memberResponse().email()).getBytes() + ); + + given(permissionQueryService.findAllTopicPermissions(any())).willReturn(permissionResponses); + + mockMvc.perform( + MockMvcRequestBuilders.get("/permissions/topics/1") + .header(AUTHORIZATION, authHeader) + ).andDo(restDocs.document()); + } + + @Test + @DisplayName("권한이 있는 자들 모두 조회") + void findPermissionById() throws Exception { + PermissionDetailResponse permissionDetailResponse = new PermissionDetailResponse( + 1L, + LocalDateTime.now(), + new MemberDetailResponse( + 1L, + "member", + "member@naver.com", + "https://map-befine-official.github.io/favicon.png", + LocalDateTime.now() + ) + ); + String authHeader = Base64.encodeBase64String( + ("Basic " + permissionDetailResponse.memberDetailResponse().email()).getBytes() + ); + + given(permissionQueryService.findPermissionById(any())).willReturn(permissionDetailResponse); + + mockMvc.perform( + MockMvcRequestBuilders.get("/permissions/1") + .header(AUTHORIZATION, authHeader) + ).andDo(restDocs.document()); + } + +} diff --git a/backend/src/test/java/com/mapbefine/mapbefine/topic/TopicFixture.java b/backend/src/test/java/com/mapbefine/mapbefine/topic/TopicFixture.java index 5d8f0841c..818e81f3f 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/topic/TopicFixture.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/topic/TopicFixture.java @@ -2,7 +2,7 @@ import com.mapbefine.mapbefine.member.domain.Member; -import com.mapbefine.mapbefine.topic.domain.Permission; +import com.mapbefine.mapbefine.topic.domain.PermissionType; import com.mapbefine.mapbefine.topic.domain.Publicity; import com.mapbefine.mapbefine.topic.domain.Topic; import com.mapbefine.mapbefine.topic.dto.request.TopicCreateRequest; @@ -19,7 +19,7 @@ public static Topic createPrivateAndGroupOnlyTopic(Member member) { "토픽 멤버만 읽을 수 있습니다.", IMAGE_URL, Publicity.PRIVATE, - Permission.GROUP_ONLY, + PermissionType.GROUP_ONLY, member ); } @@ -30,7 +30,7 @@ public static Topic createPublicAndAllMembersTopic(Member member) { "아무나 읽을 수 있습니다.", IMAGE_URL, Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, member ); } @@ -41,7 +41,7 @@ public static Topic createByName(String name, Member member) { "설명", null, Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, member ); } @@ -52,7 +52,7 @@ public static Topic createPrivateByName(String name, Member member) { "설명", null, Publicity.PRIVATE, - Permission.GROUP_ONLY, + PermissionType.GROUP_ONLY, member ); } @@ -65,7 +65,7 @@ public static TopicCreateRequest createPublicAndAllMembersCreateRequestWithPins( IMAGE_URL, "아무나 읽을 수 있는 토픽입니다.", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, pinIds ); } @@ -78,7 +78,7 @@ public static TopicMergeRequest createPublicAndAllMembersMergeRequestWithTopics( IMAGE_URL, "아무나 읽을 수 있는 토픽입니다.", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, topicIds ); } 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 ea4083147..090dd9efa 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/topic/TopicIntegrationTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/topic/TopicIntegrationTest.java @@ -14,7 +14,7 @@ import com.mapbefine.mapbefine.pin.PinFixture; import com.mapbefine.mapbefine.pin.domain.Pin; import com.mapbefine.mapbefine.pin.domain.PinRepository; -import com.mapbefine.mapbefine.topic.domain.Permission; +import com.mapbefine.mapbefine.topic.domain.PermissionType; import com.mapbefine.mapbefine.topic.domain.Publicity; import com.mapbefine.mapbefine.topic.domain.Topic; import com.mapbefine.mapbefine.topic.domain.TopicRepository; @@ -70,7 +70,7 @@ void createNewTopicWithoutPins_Success() { "https://map-befine-official.github.io/favicon.png", "준팍이 2번 이상 간집 ", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, Collections.emptyList() ); @@ -109,7 +109,7 @@ void createNewTopicWithPins_Success() { "https://map-befine-official.github.io/favicon.png", "준팍이 2번 이상 간집 ", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, pinIds ); @@ -130,7 +130,7 @@ void createMergeTopic_Success() { "https://map-befine-official.github.io/favicon.png", "준팍이 2번 이상 간집 ", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, Collections.emptyList() ); TopicCreateRequest 준팍의_또안간집 = new TopicCreateRequest( @@ -138,7 +138,7 @@ void createMergeTopic_Success() { "https://map-befine-official.github.io/favicon.png", "준팍이 2번 이상 안간집 ", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, Collections.emptyList() ); createNewTopic(준팍의_또간집, authHeader); @@ -153,7 +153,7 @@ void createMergeTopic_Success() { "https://map-befine-official.github.io/favicon.png", "맛집과 카페 토픽 합치기", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, topicIds); // when @@ -180,7 +180,7 @@ void updateTopic_Success() { "https://map-befine-official.github.io/favicon.png", "준팍이 두번 간집", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, Collections.emptyList() ), authHeader @@ -193,7 +193,7 @@ void updateTopic_Success() { "https://map-befine-official.github.io/favicon.png", "수정한 토픽", Publicity.PUBLIC, - Permission.ALL_MEMBERS + PermissionType.ALL_MEMBERS ); ExtractableResponse response = RestAssured .given().log().all() @@ -217,7 +217,7 @@ void deleteTopic_Success() { "https://map-befine-official.github.io/favicon.png", "준팍이 두번 간집 ", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, Collections.emptyList() ), authHeader @@ -262,7 +262,7 @@ void findTopicDetail_Success() { "https://map-befine-official.github.io/favicon.png", "description", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, Collections.emptyList() ); ExtractableResponse createResponse = createNewTopic(request, authHeader); @@ -291,7 +291,7 @@ void findTopicDetailsByIds_Success() { "https://map-befine-official.github.io/favicon.png", "description", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, Collections.emptyList() ); ExtractableResponse createResponse1 = createNewTopic(request, authHeader); diff --git a/backend/src/test/java/com/mapbefine/mapbefine/topic/application/TopicCommandServiceTest.java b/backend/src/test/java/com/mapbefine/mapbefine/topic/application/TopicCommandServiceTest.java index f0bea115a..194de9c41 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/topic/application/TopicCommandServiceTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/topic/application/TopicCommandServiceTest.java @@ -17,7 +17,7 @@ import com.mapbefine.mapbefine.pin.PinFixture; import com.mapbefine.mapbefine.pin.domain.Pin; import com.mapbefine.mapbefine.topic.TopicFixture; -import com.mapbefine.mapbefine.topic.domain.Permission; +import com.mapbefine.mapbefine.topic.domain.PermissionType; import com.mapbefine.mapbefine.topic.domain.Publicity; import com.mapbefine.mapbefine.topic.domain.Topic; import com.mapbefine.mapbefine.topic.domain.TopicRepository; @@ -302,7 +302,7 @@ public void updateTopicInfo_Success() { "https://map-befine-official.github.io/favicon.png", "수정된 설명", Publicity.PRIVATE, - Permission.GROUP_ONLY + PermissionType.GROUP_ONLY ); topicCommandService.updateTopicInfo(user, topic.getId(), request); @@ -338,7 +338,7 @@ public void updateTopicInfo_Fail() { "https://map-befine-official.github.io/favicon.png", "수정된 설명", Publicity.PUBLIC, - Permission.ALL_MEMBERS + PermissionType.ALL_MEMBERS ); assertThatThrownBy(() -> topicCommandService.updateTopicInfo(user, topic.getId(), request)) diff --git a/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/PermissionTest.java b/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/PermissionTypeTest.java similarity index 82% rename from backend/src/test/java/com/mapbefine/mapbefine/topic/domain/PermissionTest.java rename to backend/src/test/java/com/mapbefine/mapbefine/topic/domain/PermissionTypeTest.java index 695d3bed3..c517ab851 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/PermissionTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/PermissionTypeTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -class PermissionTest { +class PermissionTypeTest { @Nested @DisplayName("isAllMembers 메서드를 호출했을 때 ALL_MEMBER가 ") @@ -16,7 +16,7 @@ class IsAllMembers { @DisplayName("아니면, false를 반환한다.") void fail() { //given - Permission groupOnly = Permission.GROUP_ONLY; + PermissionType groupOnly = PermissionType.GROUP_ONLY; //when //then @@ -27,7 +27,7 @@ void fail() { @DisplayName("맞으면 true를 반환한다.") void success() { //given - Permission allMembers = Permission.ALL_MEMBERS; + PermissionType allMembers = PermissionType.ALL_MEMBERS; //when //then @@ -44,7 +44,7 @@ class IsGroupOnly { @DisplayName("아니면, false를 반환한다.") void fail() { //given - Permission allMembers = Permission.ALL_MEMBERS; + PermissionType allMembers = PermissionType.ALL_MEMBERS; //when //then @@ -55,7 +55,7 @@ void fail() { @DisplayName("맞으면 true를 반환한다.") void success() { //given - Permission groupOnly = Permission.GROUP_ONLY; + PermissionType groupOnly = PermissionType.GROUP_ONLY; //when //then diff --git a/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicRepositoryTest.java b/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicRepositoryTest.java index 7f3876be1..3280df30b 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicRepositoryTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicRepositoryTest.java @@ -38,7 +38,7 @@ void deleteById_Success() { "토픽설명", "https://example.com/image.jpg", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, member ); @@ -54,4 +54,4 @@ void deleteById_Success() { assertThat(deletedTopic.isDeleted()).isTrue(); } -} \ No newline at end of file +} diff --git a/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicStatusTest.java b/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicStatusTest.java index 160c46003..f00682e16 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicStatusTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicStatusTest.java @@ -17,11 +17,11 @@ class Validate { void fail() { //given Publicity publicity = Publicity.PRIVATE; - Permission permission = Permission.ALL_MEMBERS; + PermissionType permissionType = PermissionType.ALL_MEMBERS; //when //then - assertThatThrownBy(() -> TopicStatus.of(publicity, permission)) + assertThatThrownBy(() -> TopicStatus.of(publicity, permissionType)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("공개 범위가 혼자 볼 지도인 경우, 권한 설정이 소속 회원이어야합니다."); } @@ -31,10 +31,10 @@ void fail() { void whenPrivateAndGroupOnly_thenSuccess() { //given Publicity publicity = Publicity.PRIVATE; - Permission permission = Permission.GROUP_ONLY; + PermissionType permissionType = PermissionType.GROUP_ONLY; //when - TopicStatus topicStatus = TopicStatus.of(publicity, permission); + TopicStatus topicStatus = TopicStatus.of(publicity, permissionType); //then assertThat(topicStatus).isNotNull(); @@ -47,10 +47,10 @@ void whenPrivateAndGroupOnly_thenSuccess() { void whenPublicAndGroupOnly_thenSuccess() { //given Publicity publicity = Publicity.PUBLIC; - Permission permission = Permission.GROUP_ONLY; + PermissionType permissionType = PermissionType.GROUP_ONLY; //when - TopicStatus topicStatus = TopicStatus.of(publicity, permission); + TopicStatus topicStatus = TopicStatus.of(publicity, permissionType); //then assertThat(topicStatus).isNotNull(); @@ -63,10 +63,10 @@ void whenPublicAndGroupOnly_thenSuccess() { void whenPublicAndAllMembers_thenSuccess() { //given Publicity publicity = Publicity.PUBLIC; - Permission permission = Permission.ALL_MEMBERS; + PermissionType permissionType = PermissionType.ALL_MEMBERS; //when - TopicStatus topicStatus = TopicStatus.of(publicity, permission); + TopicStatus topicStatus = TopicStatus.of(publicity, permissionType); //then assertThat(topicStatus).isNotNull(); @@ -79,10 +79,10 @@ void whenPublicAndAllMembers_thenSuccess() { public void whenPublicityIsNull_Fail() { //given Publicity publicity = null; - Permission permission = Permission.ALL_MEMBERS; + PermissionType permissionType = PermissionType.ALL_MEMBERS; //when //then - assertThatThrownBy(() -> TopicStatus.of(publicity, permission)) + assertThatThrownBy(() -> TopicStatus.of(publicity, permissionType)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("공개 범위는 null일 수 없습니다."); } @@ -92,10 +92,10 @@ public void whenPublicityIsNull_Fail() { public void whenPermissionIsNull_Fail() { //given Publicity publicity = Publicity.PUBLIC; - Permission permission = null; + PermissionType permissionType = null; //when //then - assertThatThrownBy(() -> TopicStatus.of(publicity, permission)) + assertThatThrownBy(() -> TopicStatus.of(publicity, permissionType)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("권한 설정은 null일 수 없습니다."); } @@ -109,11 +109,11 @@ class Update { @DisplayName("권한 범위가 모든 멤버이면, 공개 범위를 혼자 볼 지도로 설정할 때 예외가 발생한다") void whenAllMembersAndPrivate_thenFail() { //given - TopicStatus topicStatus = TopicStatus.of(Publicity.PUBLIC, Permission.ALL_MEMBERS); + TopicStatus topicStatus = TopicStatus.of(Publicity.PUBLIC, PermissionType.ALL_MEMBERS); //when //then - assertThatThrownBy(() -> topicStatus.update(Publicity.PRIVATE, Permission.ALL_MEMBERS)) + assertThatThrownBy(() -> topicStatus.update(Publicity.PRIVATE, PermissionType.ALL_MEMBERS)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("권한 범위가 모든 멤버인 경우, 공개 범위를 혼자 볼 지도로 설정할 수 없습니다."); } @@ -121,11 +121,11 @@ void whenAllMembersAndPrivate_thenFail() { @Test @DisplayName("권한 범위를 GroupOnly로 변경할 경우, 예외가 발생한다") void whenUpdateGroupOnly_thenFail() { - TopicStatus topicStatus = TopicStatus.of(Publicity.PUBLIC, Permission.ALL_MEMBERS); + TopicStatus topicStatus = TopicStatus.of(Publicity.PUBLIC, PermissionType.ALL_MEMBERS); //when //then - assertThatThrownBy(() -> topicStatus.update(Publicity.PUBLIC, Permission.GROUP_ONLY)) + assertThatThrownBy(() -> topicStatus.update(Publicity.PUBLIC, PermissionType.GROUP_ONLY)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("권한 범위는 줄어들 수 없습니다."); } @@ -133,10 +133,10 @@ void whenUpdateGroupOnly_thenFail() { @Test @DisplayName("권한 범위가 GroupOnly일 때 private을 public으로 변경 가능하다") void whenUpdatePublicityToPublic_thenSuccess() { - TopicStatus topicStatus = TopicStatus.of(Publicity.PRIVATE, Permission.GROUP_ONLY); + TopicStatus topicStatus = TopicStatus.of(Publicity.PRIVATE, PermissionType.GROUP_ONLY); //when - topicStatus.update(Publicity.PUBLIC, Permission.GROUP_ONLY); + topicStatus.update(Publicity.PUBLIC, PermissionType.GROUP_ONLY); //then assertThat(topicStatus).isNotNull(); @@ -147,10 +147,10 @@ void whenUpdatePublicityToPublic_thenSuccess() { @Test @DisplayName("권한 범위가 GroupOnly일 때 public을 private으로 변경 가능하다") void whenUpdatePublicityToPrivate_thenSuccess() { - TopicStatus topicStatus = TopicStatus.of(Publicity.PUBLIC, Permission.GROUP_ONLY); + TopicStatus topicStatus = TopicStatus.of(Publicity.PUBLIC, PermissionType.GROUP_ONLY); //when - topicStatus.update(Publicity.PRIVATE, Permission.GROUP_ONLY); + topicStatus.update(Publicity.PRIVATE, PermissionType.GROUP_ONLY); //then assertThat(topicStatus).isNotNull(); diff --git a/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicTest.java b/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicTest.java index 9d2cdaf7c..0d5b02a44 100644 --- a/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicTest.java +++ b/backend/src/test/java/com/mapbefine/mapbefine/topic/domain/TopicTest.java @@ -26,7 +26,7 @@ void setUp() { "매튜가 엄마 몰래 찾는 산스장", "https://example.com/image.jpg", Publicity.PUBLIC, - Permission.GROUP_ONLY, + PermissionType.GROUP_ONLY, member ); pin = PinFixture.create(LocationFixture.create(), topic, member); @@ -57,18 +57,18 @@ void updateTopicInfo() { void updateTopicStatus() { //given Publicity publicity = Publicity.PRIVATE; - Permission permission = Permission.GROUP_ONLY; + PermissionType permissionType = PermissionType.GROUP_ONLY; //when topic.updateTopicStatus( publicity, - permission + permissionType ); TopicStatus topicStatus = topic.getTopicStatus(); //then assertThat(topicStatus.getPublicity()).isEqualTo(publicity); - assertThat(topicStatus.getPermission()).isEqualTo(permission); + assertThat(topicStatus.getPermissionType()).isEqualTo(permissionType); } @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 03cc13d90..0af3b59a6 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 @@ -11,7 +11,7 @@ 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.Permission; +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.TopicMergeRequest; @@ -53,7 +53,7 @@ void create() throws Exception { "https://map-befine-official.github.io/favicon.png", "준팍이 두번 다시 안갈집", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, List.of(1L, 2L, 3L) ); @@ -77,7 +77,7 @@ void mergeAndCreate() throws Exception { "https://map-befine-official.github.io/favicon.png", "준팍이 두번 다시 안갈집", Publicity.PUBLIC, - Permission.ALL_MEMBERS, + PermissionType.ALL_MEMBERS, List.of(1L, 2L, 3L) ); @@ -100,7 +100,7 @@ void update() throws Exception { "https://map-befine-official.github.io/favicon.png", "준팍이 두번 다시 안갈집", Publicity.PUBLIC, - Permission.ALL_MEMBERS + PermissionType.ALL_MEMBERS ); mockMvc.perform(