-
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] Feat/#587 핀 댓글 기능 추가 구현 #601
Changes from 24 commits
110e964
f5685c0
6fe015d
cc717f0
c39f04a
4a7424d
843e577
efa640d
04fb540
20dd07a
dd701c0
7741412
d160dd2
48b5c4b
8b98dfa
d6a5816
4d6cff1
efc2d0e
f4e6416
8a96d6e
7b6cf26
c66802a
166b875
807d15d
26bead6
909ebf4
d2d2fa5
4245228
38e35fd
c179ae0
97f5ea7
b30b387
cd75da7
937a63d
1232bf7
fb43e32
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 |
---|---|---|
|
@@ -36,4 +36,24 @@ public boolean canPinCreateOrUpdate(Topic topic) { | |
return false; | ||
} | ||
|
||
} | ||
@Override | ||
public boolean canPinCommentCreate(Topic topic) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isAdmin() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isUser() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isGuest() { | ||
return true; | ||
} | ||
|
||
} | ||
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. POSIX! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.mapbefine.mapbefine.auth.domain.member; | ||
|
||
import com.mapbefine.mapbefine.auth.domain.AuthMember; | ||
import com.mapbefine.mapbefine.topic.domain.Publicity; | ||
import com.mapbefine.mapbefine.topic.domain.Topic; | ||
import com.mapbefine.mapbefine.topic.domain.TopicStatus; | ||
import java.util.List; | ||
|
@@ -42,6 +43,28 @@ public boolean canPinCreateOrUpdate(Topic topic) { | |
return topicStatus.isAllMembers() || hasPermission(topic.getId()); | ||
} | ||
|
||
@Override | ||
public boolean canPinCommentCreate(Topic topic) { | ||
Publicity publicity = topic.getPublicity(); | ||
|
||
return publicity == Publicity.PUBLIC || isGroup(topic.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. P4. 이건 이번 PR 해당하는 내용만은 아닌데 제가 코드 다시 보니까 이해가 안가서 질문드립니당.. 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. 코드 다시 보니까 그렇네요 허허허허허
도이가 말씀해주신 부분들 수정해서 올리도록 할게요! 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. isGroup -> hasPermission 일괄적으로 적용했습니다. |
||
} | ||
|
||
@Override | ||
public boolean isAdmin() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isUser() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isGuest() { | ||
return false; | ||
} | ||
|
||
private boolean isCreator(Long topicId) { | ||
return createdTopic.contains(topicId); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package com.mapbefine.mapbefine.pin.application; | ||
|
||
import static com.mapbefine.mapbefine.image.exception.ImageErrorCode.IMAGE_FILE_IS_NULL; | ||
import static com.mapbefine.mapbefine.pin.exception.PinCommentErrorCode.FORBIDDEN_PIN_COMMENT_CREATE; | ||
import static com.mapbefine.mapbefine.pin.exception.PinCommentErrorCode.FORBIDDEN_PIN_COMMENT_DELETE; | ||
import static com.mapbefine.mapbefine.pin.exception.PinCommentErrorCode.FORBIDDEN_PIN_COMMENT_UPDATE; | ||
import static com.mapbefine.mapbefine.pin.exception.PinCommentErrorCode.PIN_COMMENT_NOT_FOUND; | ||
import static com.mapbefine.mapbefine.pin.exception.PinErrorCode.FORBIDDEN_PIN_CREATE_OR_UPDATE; | ||
import static com.mapbefine.mapbefine.pin.exception.PinErrorCode.ILLEGAL_PIN_ID; | ||
import static com.mapbefine.mapbefine.pin.exception.PinErrorCode.ILLEGAL_PIN_IMAGE_ID; | ||
|
@@ -16,12 +20,18 @@ | |
import com.mapbefine.mapbefine.member.domain.Member; | ||
import com.mapbefine.mapbefine.member.domain.MemberRepository; | ||
import com.mapbefine.mapbefine.pin.domain.Pin; | ||
import com.mapbefine.mapbefine.pin.domain.PinComment; | ||
import com.mapbefine.mapbefine.pin.domain.PinCommentRepository; | ||
import com.mapbefine.mapbefine.pin.domain.PinImage; | ||
import com.mapbefine.mapbefine.pin.domain.PinImageRepository; | ||
import com.mapbefine.mapbefine.pin.domain.PinRepository; | ||
import com.mapbefine.mapbefine.pin.dto.request.PinCommentCreateRequest; | ||
import com.mapbefine.mapbefine.pin.dto.request.PinCommentUpdateRequest; | ||
import com.mapbefine.mapbefine.pin.dto.request.PinCreateRequest; | ||
import com.mapbefine.mapbefine.pin.dto.request.PinImageCreateRequest; | ||
import com.mapbefine.mapbefine.pin.dto.request.PinUpdateRequest; | ||
import com.mapbefine.mapbefine.pin.exception.PinCommentException.PinCommentForbiddenException; | ||
import com.mapbefine.mapbefine.pin.exception.PinCommentException.PinCommentNotFoundException; | ||
import com.mapbefine.mapbefine.pin.exception.PinException.PinBadRequestException; | ||
import com.mapbefine.mapbefine.pin.exception.PinException.PinForbiddenException; | ||
import com.mapbefine.mapbefine.topic.domain.Topic; | ||
|
@@ -46,21 +56,24 @@ public class PinCommandService { | |
private final MemberRepository memberRepository; | ||
private final PinImageRepository pinImageRepository; | ||
private final ImageService imageService; | ||
private final PinCommentRepository pinCommentRepository; | ||
|
||
public PinCommandService( | ||
PinRepository pinRepository, | ||
LocationRepository locationRepository, | ||
TopicRepository topicRepository, | ||
MemberRepository memberRepository, | ||
PinImageRepository pinImageRepository, | ||
ImageService imageService | ||
ImageService imageService, | ||
PinCommentRepository pinCommentRepository | ||
) { | ||
this.pinRepository = pinRepository; | ||
this.locationRepository = locationRepository; | ||
this.topicRepository = topicRepository; | ||
this.memberRepository = memberRepository; | ||
this.pinImageRepository = pinImageRepository; | ||
this.imageService = imageService; | ||
this.pinCommentRepository = pinCommentRepository; | ||
} | ||
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. P3. 필드 순서, 생성자 파라미터 순서에서 Service와 Repository를 분류하면 어떨까요? 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. 반영하겠습니다~! |
||
|
||
public long save( | ||
|
@@ -193,4 +206,81 @@ private void validatePinCreateOrUpdate(AuthMember authMember, Topic topic) { | |
|
||
throw new PinForbiddenException(FORBIDDEN_PIN_CREATE_OR_UPDATE); | ||
} | ||
|
||
public Long savePinComment(AuthMember authMember, PinCommentCreateRequest request) { | ||
Pin pin = findPin(request.pinId()); | ||
validatePinCommentCreate(authMember, pin); | ||
Member member = findMember(authMember.getMemberId()); | ||
PinComment parentPinComment = findParentPinComment(request.parentPinCommentId()); | ||
|
||
PinComment pinComment = PinComment.of(pin, parentPinComment, member, request.content()); | ||
pinCommentRepository.save(pinComment); | ||
|
||
return pinComment.getId(); | ||
} | ||
|
||
private void validatePinCommentCreate(AuthMember authMember, Pin pin) { | ||
if (authMember.canPinCommentCreate(pin.getTopic())) { | ||
return; | ||
} | ||
|
||
throw new PinCommentForbiddenException(FORBIDDEN_PIN_COMMENT_CREATE); | ||
} | ||
|
||
private PinComment findParentPinComment(Long parentPinComment) { | ||
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. Id !! 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. 허걱 이런 실수를 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. 반영 완! |
||
if (Objects.isNull(parentPinComment)) { | ||
return null; | ||
} | ||
|
||
return pinCommentRepository.findById(parentPinComment) | ||
.orElseThrow(() -> new PinCommentNotFoundException(PIN_COMMENT_NOT_FOUND, parentPinComment)); | ||
} | ||
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. Null값을 그대로 넘겨주기보단, 상황에 따라 다르게 초기화된 pinComment를 넘겨주는건 어떤가요 ? 생성자에 null넣기 좀 그러면, 정팩메로 분리해도 되구요 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. 반영해보겠슴둥~~ 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. 반영을 완료하긴 했지만 쥬니가 말씀하신 방법이 이게 맞는지는 모르겠어요! 한번 확인 부탁드려용! |
||
|
||
public void updatePinComment( | ||
AuthMember member, | ||
Long pinCommentId, | ||
PinCommentUpdateRequest request | ||
) { | ||
PinComment pinComment = findPinComment(pinCommentId); | ||
|
||
validatePinCommentUpdate(member, pinComment); | ||
|
||
pinComment.updateContent(request.content()); | ||
} | ||
|
||
private void validatePinCommentUpdate(AuthMember authMember, PinComment pinComment) { | ||
if (isPinCommentCreatorOrAdmin(authMember, pinComment)) { | ||
return; | ||
} | ||
|
||
throw new PinCommentForbiddenException(FORBIDDEN_PIN_COMMENT_UPDATE); | ||
} | ||
|
||
private boolean isPinCommentCreatorOrAdmin(AuthMember authMember, PinComment pinComment) { | ||
Long creatorId = pinComment.getCreator().getId(); | ||
|
||
return authMember.isSameMember(creatorId) || authMember.isAdmin(); | ||
} | ||
|
||
private PinComment findPinComment(Long pinCommentId) { | ||
return pinCommentRepository.findById(pinCommentId) | ||
.orElseThrow(() -> new PinCommentNotFoundException(PIN_COMMENT_NOT_FOUND, pinCommentId)); | ||
} | ||
|
||
public void deletePinComment(AuthMember member, Long pinCommentId) { | ||
PinComment pinComment = findPinComment(pinCommentId); | ||
|
||
validatePinCommentDelete(member, pinComment); | ||
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. ValidatePinCommentUpdate를 재사용하면 안 되는건가요 ? 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. 예외 내에 들어가는 Error Code가 달라서 이렇게 하긴 했어요! Error Code를 받아서 처리하는 방식으로 할까요? 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. 근데 이거와 별개로 생각해보니까 canPinCommentCreate 를 기존 코드의 canRead 로 바꿀 수 있더라고요 허허허 이것도 같이 바꿀게용 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. 아니네 허허허 canRead 로 하면 Guest 를 못거르네 허허허 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. 아니네 거르네 허허허 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. 아니네 안거르네 |
||
|
||
pinCommentRepository.delete(pinComment); | ||
} | ||
|
||
private void validatePinCommentDelete(AuthMember authMember, PinComment pinComment) { | ||
if (isPinCommentCreatorOrAdmin(authMember, pinComment)) { | ||
return; | ||
} | ||
|
||
throw new PinCommentForbiddenException(FORBIDDEN_PIN_COMMENT_DELETE); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,17 @@ | |
|
||
import com.mapbefine.mapbefine.auth.domain.AuthMember; | ||
import com.mapbefine.mapbefine.pin.domain.Pin; | ||
import com.mapbefine.mapbefine.pin.domain.PinComment; | ||
import com.mapbefine.mapbefine.pin.domain.PinCommentRepository; | ||
import com.mapbefine.mapbefine.pin.domain.PinRepository; | ||
import com.mapbefine.mapbefine.pin.dto.response.PinCommentResponse; | ||
import com.mapbefine.mapbefine.pin.dto.response.PinDetailResponse; | ||
import com.mapbefine.mapbefine.pin.dto.response.PinResponse; | ||
import com.mapbefine.mapbefine.pin.exception.PinException.PinForbiddenException; | ||
import com.mapbefine.mapbefine.pin.exception.PinException.PinNotFoundException; | ||
import com.mapbefine.mapbefine.topic.domain.Topic; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
|
@@ -20,8 +24,10 @@ | |
public class PinQueryService { | ||
|
||
private final PinRepository pinRepository; | ||
private final PinCommentRepository pinCommentRepository; | ||
|
||
public PinQueryService(PinRepository pinRepository) { | ||
public PinQueryService(PinRepository pinRepository, PinCommentRepository pinCommentRepository) { | ||
this.pinCommentRepository = pinCommentRepository; | ||
this.pinRepository = pinRepository; | ||
} | ||
|
||
|
@@ -56,4 +62,35 @@ public List<PinResponse> findAllPinsByMemberId(AuthMember authMember, Long membe | |
.map(PinResponse::from) | ||
.toList(); | ||
} | ||
|
||
public List<PinCommentResponse> findAllPinCommentByPinId(AuthMember member, Long pinId) { | ||
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. findAllPinComment's' 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. 껄껄껄껄 |
||
Pin pin = findPin(pinId); | ||
validateReadAuth(member, pin.getTopic()); | ||
|
||
List<PinComment> pinComments = pinCommentRepository.findAllByPinId(pinId); | ||
|
||
return pinComments.stream() | ||
.map(pinComment -> pinCommentToResponse(member, pinComment)) | ||
.toList(); | ||
} | ||
|
||
private Pin findPin(Long pinId) { | ||
return pinRepository.findById(pinId) | ||
.orElseThrow(() -> new PinNotFoundException(PIN_NOT_FOUND, pinId)); | ||
} | ||
|
||
private PinCommentResponse pinCommentToResponse(AuthMember member, PinComment pinComment) { | ||
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. 이거 좀 별론데 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. ㅋㅋㅋㅋㅋ 어떻게 할 수 있을까요?? |
||
Long creatorId = pinComment.getCreator().getId(); | ||
|
||
boolean canChange = (Objects.nonNull(member.getMemberId()) | ||
&& member.isSameMember(creatorId)) | ||
|| member.isAdmin(); | ||
|
||
if (pinComment.isParentComment()) { | ||
return PinCommentResponse.ofParentComment(pinComment, canChange); | ||
} | ||
|
||
return PinCommentResponse.ofChildComment(pinComment, canChange); | ||
} | ||
|
||
} |
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.
POSIX!
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.
오 덕분에 용어 알아갑니다