-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: Permission Enum 네이밍 변경(PermissionType) * refactor: MemberTopicPermission 네이밍 변경(Permission) 및 패키지 분리 * refactor: Service 및 Controller 분리 * test: 테스트 오류 수정 * refactor: 메서드 네임 수정 * docs: restDocs 추가 * refactor: 메서드 네이밍 변경
- Loading branch information
1 parent
e32bc89
commit 83200a1
Showing
43 changed files
with
870 additions
and
707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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'] |
90 changes: 0 additions & 90 deletions
90
backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,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); | ||
} | ||
|
||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
.../src/main/java/com/mapbefine/mapbefine/member/domain/MemberTopicPermissionRepository.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...n/java/com/mapbefine/mapbefine/member/dto/request/MemberTopicPermissionCreateRequest.java
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
...java/com/mapbefine/mapbefine/member/dto/response/MemberTopicPermissionDetailResponse.java
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
.../main/java/com/mapbefine/mapbefine/member/dto/response/MemberTopicPermissionResponse.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.