-
Notifications
You must be signed in to change notification settings - Fork 6
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] Member 관련 기능 개발 #237
[BE] Member 관련 기능 개발 #237
Changes from all commits
8646b1a
5b153cc
c54a142
1397964
4efef6e
29997b1
82233e0
70f351f
b98ce02
bd32df0
69268ee
f6faad0
960b9b3
68838dc
5bda12f
83f79ff
27a0738
41ee4ef
b0850af
9ffcefd
471a826
5075d4b
30a97f7
470fcb5
9b58830
80d7e9f
939964c
12e83b4
8c869a1
7bdea8a
5cf4318
cc4c0c4
b45f3b1
0dec766
c451958
2433935
4383f25
209a4e2
d6e4e7a
712a289
846490a
cd57810
6626b7e
02979b3
be59142
1d81886
2dccd5f
975fffd
6cc09a4
dc90aa5
a78a348
426ad35
1a825b5
f8370c3
1520467
2f48f41
9e97c05
b9a18fc
d6188c4
8ffb1f3
9a8a019
fa6d7fe
0dad751
bb84223
71e970a
d5128c6
c5423ad
37a79a8
36ac58e
342f35e
864b851
3fa28bc
6b3696f
9192536
522708f
0815ff7
7fcc517
2ea4a21
e521b2c
e2bb58e
9d04afb
96d3512
019f330
ec9060c
fd70f24
459248e
8e192c2
6424bde
a17a621
a560db6
e6846a4
f623a60
0b32101
50888d3
67ba9d9
6ba447f
f97ac2d
9a0b57f
4da72dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ toc::[] | |
|
||
include::topic.adoc[] | ||
include::pin.adoc[] | ||
include::member.adoc[] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
== 유저 | ||
|
||
=== 유저 권한 부여 | ||
|
||
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/add[snippets='http-request,http-response'] | ||
|
||
=== 유저 목록 조회 | ||
|
||
operation::member-controller-test/find-all-member[snippets='http-request,http-response'] | ||
|
||
=== 유저 단일 조회 | ||
|
||
operation::member-controller-test/find-member-by-id[snippets='http-request,http-response'] | ||
|
||
=== 유저가 만든 핀 조회 | ||
|
||
operation::member-controller-test/find-pins-by-member[snippets='http-request,http-response'] | ||
|
||
=== 유저가 만든 토픽 조회 | ||
|
||
operation::member-controller-test/find-topics-by-member[snippets='http-request,http-response'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
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.MemberCreateRequest; | ||
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; | ||
|
||
|
@@ -9,8 +18,101 @@ | |
public class MemberCommandService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final TopicRepository topicRepository; | ||
private final MemberTopicPermissionRepository memberTopicPermissionRepository; | ||
|
||
public MemberCommandService(MemberRepository memberRepository) { | ||
public MemberCommandService( | ||
MemberRepository memberRepository, | ||
TopicRepository topicRepository, | ||
MemberTopicPermissionRepository memberTopicPermissionRepository | ||
) { | ||
this.memberRepository = memberRepository; | ||
this.topicRepository = topicRepository; | ||
this.memberTopicPermissionRepository = memberTopicPermissionRepository; | ||
} | ||
|
||
public Long save(MemberCreateRequest request) { | ||
validateUniqueNickName(request.nickName()); | ||
validateUniqueEmail(request.email()); | ||
|
||
Member member = Member.of( | ||
request.nickName(), | ||
request.email(), | ||
request.imageUrl(), | ||
request.role() | ||
); | ||
|
||
return memberRepository.save(member) | ||
.getId(); | ||
} | ||
|
||
private void validateUniqueNickName(String nickName) { | ||
if (memberRepository.existsByMemberInfoNickName(nickName)) { | ||
throw new IllegalArgumentException("이미 존재하는 닉네임입니다."); | ||
} | ||
} | ||
|
||
private void validateUniqueEmail(String email) { | ||
if (memberRepository.existsByMemberInfoEmail(email)) { | ||
throw new IllegalArgumentException("이미 존재하는 이메일입니다."); | ||
} | ||
} | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 짧더라도 컨벤션이니 개행해주시면 더 좋을 것 같습니다! |
||
|
||
MemberTopicPermission memberTopicPermission = | ||
MemberTopicPermission.createPermissionAssociatedWithTopicAndMember(topic, member); | ||
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
그렇다면, 해당 테이블의 데이터를 직접 save 해주기 보다는 cascade와 orphanRemoval 설정을 활용해보는 편이 어떨까요 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음.. 이 부분은 저도 처음에 쥬니 말씀처럼 하려다가 애매해서 MemberTopicPermission 을 저장하도록 했는데요. 이유는 2가지가 정도가 있었습니다.
위와 같은 2가지 이유로 쥬니가 말씀하신 사안을 선택하지 않았는데요! 이에 대한 쥬니의 의견도 말씀해주시면 반영해보도록 할게요! 쥬니짜응짜응 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member 소유로 가지고 있는 Topic이기 때문에 Member를 이용하면 될 것 같아요.
멤버에게 토픽 권한이 추가되었다는 것은 멤버의 정보가 업데이트 된 것이겠죠 ? 의견 부탁드립니다 ! |
||
|
||
return memberTopicPermissionRepository.save(memberTopicPermission).getId(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개행 ! |
||
} | ||
|
||
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 |
---|---|---|
@@ -1,6 +1,23 @@ | ||
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.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; | ||
import com.mapbefine.mapbefine.topic.domain.Topic; | ||
import com.mapbefine.mapbefine.topic.domain.TopicRepository; | ||
import com.mapbefine.mapbefine.topic.dto.response.TopicResponse; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import java.util.Objects; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
|
@@ -9,8 +26,75 @@ | |
public class MemberQueryService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final TopicRepository topicRepository; | ||
private final PinRepository pinRepository; | ||
private final MemberTopicPermissionRepository memberTopicPermissionRepository; | ||
|
||
public MemberQueryService(MemberRepository memberRepository) { | ||
public MemberQueryService( | ||
MemberRepository memberRepository, | ||
TopicRepository topicRepository, | ||
PinRepository pinRepository, | ||
MemberTopicPermissionRepository memberTopicPermissionRepository | ||
) { | ||
this.memberRepository = memberRepository; | ||
this.topicRepository = topicRepository; | ||
this.pinRepository = pinRepository; | ||
this.memberTopicPermissionRepository = memberTopicPermissionRepository; | ||
} | ||
|
||
public MemberDetailResponse findById(Long id) { | ||
Member member = memberRepository.findById(id) | ||
.orElseThrow(NoSuchElementException::new); | ||
|
||
return MemberDetailResponse.from(member); | ||
} | ||
|
||
public List<MemberResponse> findAll() { | ||
return memberRepository.findAll() | ||
.stream() | ||
.map(MemberResponse::from) | ||
.toList(); | ||
} | ||
Comment on lines
+52
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .stream 정도야 한 줄에 써도 되겠지 했었는데, 제가 컨벤션을 잘못 알고 있었네요 ㅎㅎ |
||
|
||
public List<TopicResponse> findTopicsByMember(AuthMember authMember) { | ||
validateNonExistsMember(authMember.getMemberId()); | ||
List<Topic> topicsByCreator = topicRepository.findByCreatorId(authMember.getMemberId()); | ||
|
||
return topicsByCreator.stream() | ||
.map(TopicResponse::from) | ||
.toList(); | ||
} | ||
|
||
public List<PinResponse> findPinsByMember(AuthMember authMember) { | ||
validateNonExistsMember(authMember.getMemberId()); | ||
List<Pin> pinsByCreator = pinRepository.findByCreatorId(authMember.getMemberId()); | ||
|
||
return pinsByCreator.stream() | ||
.map(PinResponse::from) | ||
.toList(); | ||
} | ||
|
||
public 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); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기준이 애매하긴 한데, 이 정도는 한 줄에 써도 괜찮지 않을까요 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저 부분 할 때 강박이 도져서..