-
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 all 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 |
---|---|---|
@@ -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,13 +20,19 @@ | |
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.event.PinUpdateEvent; | ||
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; | ||
|
@@ -45,29 +55,32 @@ public class PinCommandService { | |
private static final double DUPLICATE_LOCATION_DISTANCE_METERS = 10.0; | ||
|
||
private final ApplicationEventPublisher eventPublisher; | ||
private final ImageService imageService; | ||
private final PinRepository pinRepository; | ||
private final LocationRepository locationRepository; | ||
private final TopicRepository topicRepository; | ||
private final MemberRepository memberRepository; | ||
private final PinImageRepository pinImageRepository; | ||
private final ImageService imageService; | ||
private final PinCommentRepository pinCommentRepository; | ||
|
||
public PinCommandService( | ||
ApplicationEventPublisher eventPublisher, | ||
ImageService imageService, | ||
PinRepository pinRepository, | ||
LocationRepository locationRepository, | ||
TopicRepository topicRepository, | ||
MemberRepository memberRepository, | ||
PinImageRepository pinImageRepository, | ||
ImageService imageService | ||
PinCommentRepository pinCommentRepository | ||
) { | ||
this.imageService = imageService; | ||
this.eventPublisher = eventPublisher; | ||
this.pinRepository = pinRepository; | ||
this.locationRepository = locationRepository; | ||
this.topicRepository = topicRepository; | ||
this.memberRepository = memberRepository; | ||
this.pinImageRepository = pinImageRepository; | ||
this.imageService = imageService; | ||
this.pinCommentRepository = pinCommentRepository; | ||
} | ||
|
||
public long save( | ||
|
@@ -202,4 +215,90 @@ 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 pinComment = createPinComment( | ||
pin, | ||
member, | ||
request.parentPinCommentId(), | ||
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 createPinComment( | ||
Pin pin, | ||
Member member, | ||
Long parentPinCommentId, | ||
String content | ||
) { | ||
if (Objects.isNull(parentPinCommentId)) { | ||
return PinComment.ofParentPinComment(pin, member, content); | ||
} | ||
|
||
PinComment parentPinComment = findPinComment(parentPinCommentId); | ||
|
||
return PinComment.ofChildPinComment(pin, parentPinComment, member, content); | ||
} | ||
|
||
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); | ||
} | ||
|
||
} |
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.
P3. 필드 순서, 생성자 파라미터 순서에서 Service와 Repository를 분류하면 어떨까요?
Repository가 다음에 추가될 확률이 더 높으니 ImageService를 첫번째 파라미터, 필드로 올려도 좋을 것 같아요.
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.
반영하겠습니다~!