Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] refactor/#279 permission 패키지 분리 #280

Merged
merged 43 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8646b1a
[Docs] GitHub Issue 및 PR Template 설정 (#37)
junpakPark Jul 18, 2023
5b153cc
[Docs] GitHub Issue Template 파일명 오류 수정 (#39)
junpakPark Jul 18, 2023
c54a142
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-m…
kpeel5839 Jul 25, 2023
1397964
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-m…
kpeel5839 Jul 25, 2023
4efef6e
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-m…
kpeel5839 Jul 26, 2023
c1fe514
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-m…
kpeel5839 Aug 1, 2023
4d7b389
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-m…
kpeel5839 Aug 9, 2023
1a596ca
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-m…
kpeel5839 Aug 10, 2023
595bbb6
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-m…
kpeel5839 Aug 13, 2023
46f453b
feat : Oauth 작업중
kpeel5839 Aug 10, 2023
819bd46
feat: 소셜 로그인 및 회원가입 기능 구현
yoondgu Aug 10, 2023
7a1869f
feat: 사용자 인가를 위한 JWT 토큰 적용
yoondgu Aug 11, 2023
3ba21e4
refactor : 소셜로그인 플랫폼 확장에 유연하도록 구조 리팩토링
kpeel5839 Aug 11, 2023
c7a6b03
fix: Location 테스트 간 상수 공유로 인한 격리 문제 해결
yoondgu Aug 11, 2023
10084aa
test: 소셜 로그인 적용, 인가 방식 변경으로 인한 테스트 코드 수정
yoondgu Aug 11, 2023
e6f39b0
chore: 구성 파일에 인증 인가 관련 환경변수 작성
yoondgu Aug 12, 2023
39f38c2
refactor: 소셜 회원가입 시 닉네임 랜덤 생성하도록 변경, 관련 추상화
yoondgu Aug 12, 2023
0f2baaa
rename: 클래스명 오기 수정
yoondgu Aug 12, 2023
5cba4ba
rename: oauth 패키지 클래스 정리
yoondgu Aug 12, 2023
b127e47
rename: kakao oauth 관련 속성값 클래스명 변경
yoondgu Aug 12, 2023
5a0936e
rename: 테스트 전용 authHeader 생성 클래스명 변경
yoondgu Aug 12, 2023
fe8d2eb
refactor: 테스트 전용 jwt secret key 환경변수 처리
yoondgu Aug 12, 2023
ae3cd44
chore : cherry pick 으로 반여잉 되지 않는 사항들을 반영
kpeel5839 Aug 10, 2023
a197be9
test : Kakao Redirect Url 반환을 테스트
kpeel5839 Aug 13, 2023
0bef02c
test : OauthService 의 Login 을 테스트
kpeel5839 Aug 13, 2023
bb0a613
docs : /oauth/{oauthServerType} API 명세서 작성
kpeel5839 Aug 13, 2023
59402b3
docs : /oauth/login/{oauthServerType} API 명세서 작성
kpeel5839 Aug 13, 2023
e747f95
test : 회원가입이 중복으로 일어나지 않음을 테스트
kpeel5839 Aug 13, 2023
9d8107b
chore : 패키지 분리
kpeel5839 Aug 13, 2023
9a83e11
docs : oauth.adoc 작성 및 다른 adoc 파일 경로 수정
kpeel5839 Aug 13, 2023
d8c4ee5
refactor : 재 로그인 테스트 보완 및 필요없는 검증 제거
kpeel5839 Aug 13, 2023
45bab9c
refactor: 불필요한 메서드 분리 제거
yoondgu Aug 13, 2023
63a9208
refactor: stream 사용으로 인덴트 수정
yoondgu Aug 13, 2023
0bca035
refactor: null 여부 확인 메서드 통일
yoondgu Aug 13, 2023
bad465f
refactor: BearerAuthorizationExtractor 메서드 분리
yoondgu Aug 13, 2023
df7123c
refactor: Permission Enum 네이밍 변경(PermissionType)
junpakPark Aug 14, 2023
cef6353
refactor: MemberTopicPermission 네이밍 변경(Permission) 및 패키지 분리
junpakPark Aug 14, 2023
af1416b
refactor: Service 및 Controller 분리
junpakPark Aug 14, 2023
d77c3a5
test: 테스트 오류 수정
junpakPark Aug 14, 2023
05b0ea6
refactor: 메서드 네임 수정
junpakPark Aug 14, 2023
38d78e1
docs: restDocs 추가
junpakPark Aug 14, 2023
fc04359
chore: git conflict 해결
junpakPark Aug 14, 2023
eee9ff5
refactor: 메서드 네이밍 변경
junpakPark Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ toc::[]
include::topic.adoc[]
include::pin.adoc[]
include::member.adoc[]
include::permission.adoc[]
include::oauth.adoc[]
16 changes: 0 additions & 16 deletions backend/src/docs/asciidoc/member.adoc
Original file line number Diff line number Diff line change
@@ -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']
Expand Down
17 changes: 17 additions & 0 deletions backend/src/docs/asciidoc/permission.adoc
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']
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -49,13 +42,15 @@ public MemberDetailResponse findById(Long id) {
return MemberDetailResponse.from(member);
}

// TODO: 2023/08/14 해당 메서드는 ADMIN만 접근 가능하게 리팩터링 하기
public List<MemberResponse> findAll() {
return memberRepository.findAll()
.stream()
.map(MemberResponse::from)
.toList();
}

// TODO: 2023/08/14 해당 메서드는 TopicQueryService로 옮기기
public List<TopicResponse> findTopicsByMember(AuthMember authMember) {
validateNonExistsMember(authMember.getMemberId());
List<Topic> topicsByCreator = topicRepository.findByCreatorId(authMember.getMemberId());
Expand All @@ -65,6 +60,7 @@ public List<TopicResponse> findTopicsByMember(AuthMember authMember) {
.toList();
}

// TODO: 2023/08/14 해당 메서드는 PinQueryService로 옮기기
public List<PinResponse> findPinsByMember(AuthMember authMember) {
validateNonExistsMember(authMember.getMemberId());
List<Pin> pinsByCreator = pinRepository.findByCreatorId(authMember.getMemberId());
Expand All @@ -73,28 +69,11 @@ public List<PinResponse> 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<MemberTopicPermissionResponse> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,7 +43,7 @@ public class Member extends BaseTimeEntity {
private List<Pin> createdPins = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<MemberTopicPermission> topicsWithPermissions = new ArrayList<>();
private List<Permission> topicsWithPermissions = new ArrayList<>();

private Member(MemberInfo memberInfo, OauthId oauthId) {
this.memberInfo = memberInfo;
Expand Down Expand Up @@ -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() {
Expand All @@ -122,7 +123,7 @@ public boolean isUser() {

public List<Topic> getTopicsWithPermissions() {
return topicsWithPermissions.stream()
.map(MemberTopicPermission::getTopic)
.map(Permission::getTopic)
.toList();
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading