Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion src/docs/asciidoc/api/pick-commnet/pick-comment-modify.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
== 픽픽픽 댓글/답글 수정 API(PATCH: /devdevdev/api/v1/picks/{pickId}/comments/{pickCommentId})

* 픽픽픽 댓글/답글을 수정한다.
* 회원 본인이 작성한 픽픽픽 댓글/답글을 수정 할 수 있다.
** 회원인 경우 토큰을 `Authorization` 헤더에 포함시켜야 한다.
** 익명 회원인 경우 `Anonymous-Member-Id` 헤더에 익명 회원 아이디를 포함시켜야 한다.
* 회원 또는 익명회원 본인이 작성한 픽픽픽 댓글/답글 만 수정 할 수 있다.
* 픽픽픽 공개 여부는 수정 할 수 없다.
* 삭제된 댓글/답글을 수정 할 수 없다.

Expand Down Expand Up @@ -41,5 +43,6 @@ include::{snippets}/modify-pick-comment/response-fields.adoc[]
* `승인 상태가 아닌 픽픽픽에는 댓글을 수정할 수 없습니다.`: 픽픽픽이 승인 상태가 아닌 경우
* `익명 회원은 사용할 수 없는 기능 입니다.`: 익명 회원인 경우
* `회원을 찾을 수 없습니다.`: 회원이 존재하지 않는 경우
* `익명 사용자가 아닙니다. 잘못된 메소드 호출 입니다.`: 회원이 익명 회원 메소드를 호출한 경우

include::{snippets}/modify-pick-comment-bind-exception/response-body.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public interface PickCommentRepository extends JpaRepository<PickComment, Long>,
Optional<PickComment> findWithPickByIdAndPickIdAndCreatedByIdAndDeletedAtIsNull(Long id, Long pickId,
Long createdById);

@EntityGraph(attributePaths = {"pick"})
Optional<PickComment> findWithPickByIdAndPickIdAndCreatedAnonymousByIdAndDeletedAtIsNull(Long id, Long pickId,
Long createdAnonymousById);

Optional<PickComment> findByIdAndPickIdAndDeletedAtIsNull(Long id, Long pickId);

@EntityGraph(attributePaths = {"pick"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import com.dreamypatisiel.devdevdev.domain.repository.pick.PickCommentSort;
import com.dreamypatisiel.devdevdev.domain.repository.pick.PickRepository;
import com.dreamypatisiel.devdevdev.domain.service.pick.dto.PickCommentDto;
import com.dreamypatisiel.devdevdev.global.common.TimeProvider;
import com.dreamypatisiel.devdevdev.global.utils.AuthenticationMemberUtils;
import com.dreamypatisiel.devdevdev.openai.embeddings.EmbeddingsService;
import com.dreamypatisiel.devdevdev.web.dto.SliceCustom;
import com.dreamypatisiel.devdevdev.web.dto.request.pick.ModifyPickCommentRequest;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentRecommendResponse;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentResponse;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentsResponse;
Expand All @@ -32,12 +32,13 @@ public class GuestPickCommentService extends PickCommonService implements PickCo

public GuestPickCommentService(EmbeddingsService embeddingsService,
PickBestCommentsPolicy pickBestCommentsPolicy,
TimeProvider timeProvider,
PickRepository pickRepository,
PickPopularScorePolicy pickPopularScorePolicy,
PickCommentRepository pickCommentRepository,
PickCommentRecommendRepository pickCommentRecommendRepository) {
super(embeddingsService, pickBestCommentsPolicy, pickPopularScorePolicy, pickRepository, pickCommentRepository,
pickCommentRecommendRepository);
super(embeddingsService, pickBestCommentsPolicy, pickPopularScorePolicy, timeProvider, pickRepository,
pickCommentRepository, pickCommentRecommendRepository);
}

@Override
Expand All @@ -56,7 +57,7 @@ public PickCommentResponse registerPickRepliedComment(Long pickParentCommentId,

@Override
public PickCommentResponse modifyPickComment(Long pickCommentId, Long pickId,
ModifyPickCommentRequest modifyPickCommentRequest,
PickCommentDto pickModifyCommentDto,
Authentication authentication) {

throw new AccessDeniedException(INVALID_ANONYMOUS_CAN_NOT_USE_THIS_FUNCTION_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.dreamypatisiel.devdevdev.domain.exception.GuestExceptionMessage.INVALID_ANONYMOUS_CAN_NOT_USE_THIS_FUNCTION_MESSAGE;
import static com.dreamypatisiel.devdevdev.domain.exception.PickExceptionMessage.INVALID_NOT_APPROVAL_STATUS_PICK_COMMENT_MESSAGE;
import static com.dreamypatisiel.devdevdev.domain.exception.PickExceptionMessage.INVALID_NOT_FOUND_PICK_COMMENT_MESSAGE;
import static com.dreamypatisiel.devdevdev.domain.exception.PickExceptionMessage.INVALID_NOT_FOUND_PICK_MESSAGE;
import static com.dreamypatisiel.devdevdev.domain.exception.PickExceptionMessage.INVALID_NOT_FOUND_PICK_VOTE_MESSAGE;

Expand All @@ -21,10 +22,10 @@
import com.dreamypatisiel.devdevdev.domain.service.member.AnonymousMemberService;
import com.dreamypatisiel.devdevdev.domain.service.pick.dto.PickCommentDto;
import com.dreamypatisiel.devdevdev.exception.NotFoundException;
import com.dreamypatisiel.devdevdev.global.common.TimeProvider;
import com.dreamypatisiel.devdevdev.global.utils.AuthenticationMemberUtils;
import com.dreamypatisiel.devdevdev.openai.embeddings.EmbeddingsService;
import com.dreamypatisiel.devdevdev.web.dto.SliceCustom;
import com.dreamypatisiel.devdevdev.web.dto.request.pick.ModifyPickCommentRequest;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentRecommendResponse;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentResponse;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentsResponse;
Expand All @@ -46,13 +47,14 @@ public class GuestPickCommentServiceV2 extends PickCommonService implements Pick

public GuestPickCommentServiceV2(EmbeddingsService embeddingsService,
PickBestCommentsPolicy pickBestCommentsPolicy,
TimeProvider timeProvider,
PickRepository pickRepository,
PickCommentRepository pickCommentRepository,
PickCommentRecommendRepository pickCommentRecommendRepository,
AnonymousMemberService anonymousMemberService,
PickPopularScorePolicy pickPopularScorePolicy,
PickVoteRepository pickVoteRepository) {
super(embeddingsService, pickBestCommentsPolicy, pickPopularScorePolicy, pickRepository,
super(embeddingsService, pickBestCommentsPolicy, pickPopularScorePolicy, timeProvider, pickRepository,
pickCommentRepository, pickCommentRecommendRepository);
this.anonymousMemberService = anonymousMemberService;
this.pickVoteRepository = pickVoteRepository;
Expand Down Expand Up @@ -109,14 +111,14 @@ public PickCommentResponse registerPickComment(Long pickId, PickCommentDto pickC
@Override
@Transactional
public PickCommentResponse registerPickRepliedComment(Long pickParentCommentId, Long pickCommentOriginParentId,
Long pickId, PickCommentDto pickCommentDto,
Long pickId, PickCommentDto pickRegisterRepliedCommentDto,
Authentication authentication) {

// 익명 회원인지 검증
AuthenticationMemberUtils.validateAnonymousMethodCall(authentication);

String contents = pickCommentDto.getContents();
String anonymousMemberId = pickCommentDto.getAnonymousMemberId();
String contents = pickRegisterRepliedCommentDto.getContents();
String anonymousMemberId = pickRegisterRepliedCommentDto.getAnonymousMemberId();

// 익명 회원 추출
AnonymousMember anonymousMember = anonymousMemberService.findOrCreateAnonymousMember(anonymousMemberId);
Expand All @@ -137,11 +139,31 @@ public PickCommentResponse registerPickRepliedComment(Long pickParentCommentId,
}

@Override
public PickCommentResponse modifyPickComment(Long pickCommentId, Long pickId,
ModifyPickCommentRequest modifyPickCommentRequest,
public PickCommentResponse modifyPickComment(Long pickCommentId, Long pickId, PickCommentDto pickCommentDto,
Authentication authentication) {

throw new AccessDeniedException(INVALID_ANONYMOUS_CAN_NOT_USE_THIS_FUNCTION_MESSAGE);
// 익명 회원인지 검증
AuthenticationMemberUtils.validateAnonymousMethodCall(authentication);

String contents = pickCommentDto.getContents();
String anonymousMemberId = pickCommentDto.getAnonymousMemberId();

// 익명 회원 추출
AnonymousMember anonymousMember = anonymousMemberService.findOrCreateAnonymousMember(anonymousMemberId);

// 픽픽픽 댓글 조회(익명 회원 본인이 댓글 작성, 삭제되지 않은 댓글)
PickComment findPickComment = pickCommentRepository.findWithPickByIdAndPickIdAndCreatedAnonymousByIdAndDeletedAtIsNull(
pickCommentId, pickId, anonymousMember.getId())
.orElseThrow(() -> new NotFoundException(INVALID_NOT_FOUND_PICK_COMMENT_MESSAGE));

// 픽픽픽 게시글의 승인 상태 검증
validateIsApprovalPickContentStatus(findPickComment.getPick(), INVALID_NOT_APPROVAL_STATUS_PICK_COMMENT_MESSAGE,
MODIFY);

// 댓글 수정
findPickComment.modifyCommentContents(new CommentContents(contents), timeProvider.getLocalDateTimeNow());

return new PickCommentResponse(findPickComment.getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class GuestPickService extends PickCommonService implements PickService {
public static final String INVALID_ANONYMOUS_CAN_NOT_USE_THIS_FUNCTION_MESSAGE = "비회원은 현재 해당 기능을 이용할 수 없습니다.";

private final PickVoteRepository pickVoteRepository;
private final TimeProvider timeProvider;
private final AnonymousMemberService anonymousMemberService;

public GuestPickService(PickRepository pickRepository, EmbeddingsService embeddingsService,
Expand All @@ -66,11 +65,10 @@ public GuestPickService(PickRepository pickRepository, EmbeddingsService embeddi
PickPopularScorePolicy pickPopularScorePolicy,
PickVoteRepository pickVoteRepository,
TimeProvider timeProvider, AnonymousMemberService anonymousMemberService) {
super(embeddingsService, pickBestCommentsPolicy, pickPopularScorePolicy, pickRepository, pickCommentRepository,
pickCommentRecommendRepository);
super(embeddingsService, pickBestCommentsPolicy, pickPopularScorePolicy, timeProvider, pickRepository,
pickCommentRepository, pickCommentRecommendRepository);
this.pickVoteRepository = pickVoteRepository;
this.anonymousMemberService = anonymousMemberService;
this.timeProvider = timeProvider;
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.dreamypatisiel.devdevdev.global.common.TimeProvider;
import com.dreamypatisiel.devdevdev.openai.embeddings.EmbeddingsService;
import com.dreamypatisiel.devdevdev.web.dto.SliceCommentCustom;
import com.dreamypatisiel.devdevdev.web.dto.request.pick.ModifyPickCommentRequest;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentRecommendResponse;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentResponse;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentsResponse;
Expand All @@ -42,7 +41,6 @@
@Transactional(readOnly = true)
public class MemberPickCommentService extends PickCommonService implements PickCommentService {

private final TimeProvider timeProvider;
private final MemberProvider memberProvider;

private final PickRepository pickRepository;
Expand All @@ -55,9 +53,8 @@ public MemberPickCommentService(TimeProvider timeProvider, MemberProvider member
PickRepository pickRepository, PickVoteRepository pickVoteRepository,
PickCommentRepository pickCommentRepository,
PickCommentRecommendRepository pickCommentRecommendRepository) {
super(embeddingsService, pickBestCommentsPolicy, pickPopularScorePolicy, pickRepository, pickCommentRepository,
pickCommentRecommendRepository);
this.timeProvider = timeProvider;
super(embeddingsService, pickBestCommentsPolicy, pickPopularScorePolicy, timeProvider, pickRepository,
pickCommentRepository, pickCommentRecommendRepository);
this.memberProvider = memberProvider;
this.pickRepository = pickRepository;
this.pickVoteRepository = pickVoteRepository;
Expand Down Expand Up @@ -151,10 +148,10 @@ public PickCommentResponse registerPickRepliedComment(Long pickParentCommentId,
*/
@Transactional
public PickCommentResponse modifyPickComment(Long pickCommentId, Long pickId,
ModifyPickCommentRequest modifyPickCommentRequest,
PickCommentDto pickModifyCommentDto,
Authentication authentication) {

String contents = modifyPickCommentRequest.getContents();
String contents = pickModifyCommentDto.getContents();

// 회원 조회
Member findMember = memberProvider.getMemberByAuthentication(authentication);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ public class MemberPickService extends PickCommonService implements PickService
private final PickOptionImageRepository pickOptionImageRepository;
private final PickVoteRepository pickVoteRepository;

private final TimeProvider timeProvider;

public MemberPickService(EmbeddingsService embeddingsService, PickRepository pickRepository,
AwsS3Properties awsS3Properties, AwsS3Uploader awsS3Uploader,
MemberProvider memberProvider, PickOptionRepository pickOptionRepository,
Expand All @@ -96,15 +94,15 @@ public MemberPickService(EmbeddingsService embeddingsService, PickRepository pic
PickCommentRecommendRepository pickCommentRecommendRepository,
PickPopularScorePolicy pickPopularScorePolicy,
PickBestCommentsPolicy pickBestCommentsPolicy, TimeProvider timeProvider) {
super(embeddingsService, pickBestCommentsPolicy, pickPopularScorePolicy, pickRepository, pickCommentRepository,
super(embeddingsService, pickBestCommentsPolicy, pickPopularScorePolicy, timeProvider, pickRepository,
pickCommentRepository,
pickCommentRecommendRepository);
this.awsS3Properties = awsS3Properties;
this.awsS3Uploader = awsS3Uploader;
this.memberProvider = memberProvider;
this.pickOptionRepository = pickOptionRepository;
this.pickOptionImageRepository = pickOptionImageRepository;
this.pickVoteRepository = pickVoteRepository;
this.timeProvider = timeProvider;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.dreamypatisiel.devdevdev.domain.repository.pick.PickCommentSort;
import com.dreamypatisiel.devdevdev.domain.service.pick.dto.PickCommentDto;
import com.dreamypatisiel.devdevdev.web.dto.SliceCustom;
import com.dreamypatisiel.devdevdev.web.dto.request.pick.ModifyPickCommentRequest;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentRecommendResponse;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentResponse;
import com.dreamypatisiel.devdevdev.web.dto.response.pick.PickCommentsResponse;
Expand All @@ -19,28 +18,22 @@ public interface PickCommentService {
String DELETE = "삭제";
String RECOMMEND = "추천";

PickCommentResponse registerPickComment(Long pickId,
PickCommentDto pickRegisterCommentDto,
Authentication authentication);
PickCommentResponse registerPickComment(Long pickId, PickCommentDto pickRegisterCommentDto, Authentication authentication);

PickCommentResponse registerPickRepliedComment(Long pickParentCommentId,
Long pickCommentOriginParentId,
Long pickId, PickCommentDto pickCommentDto,
PickCommentResponse registerPickRepliedComment(Long pickParentCommentId, Long pickCommentOriginParentId,
Long pickId, PickCommentDto pickRegisterRepliedCommentDto,
Authentication authentication);

PickCommentResponse modifyPickComment(Long pickCommentId, Long pickId,
ModifyPickCommentRequest modifyPickCommentRequest,
PickCommentResponse modifyPickComment(Long pickCommentId, Long pickId, PickCommentDto pickModifyCommentDto,
Authentication authentication);

PickCommentResponse deletePickComment(Long pickCommentId, Long pickId, Authentication authentication);

SliceCustom<PickCommentsResponse> findPickComments(Pageable pageable, Long pickId,
Long pickCommentId, PickCommentSort pickCommentSort,
EnumSet<PickOptionType> pickOptionTypes,
SliceCustom<PickCommentsResponse> findPickComments(Pageable pageable, Long pickId, Long pickCommentId,
PickCommentSort pickCommentSort, EnumSet<PickOptionType> pickOptionTypes,
Authentication authentication);

PickCommentRecommendResponse recommendPickComment(Long pickId, Long pickCommendId,
Authentication authentication);
PickCommentRecommendResponse recommendPickComment(Long pickId, Long pickCommendId, Authentication authentication);

List<PickCommentsResponse> findPickBestComments(int size, Long pickId, Authentication authentication);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.dreamypatisiel.devdevdev.domain.repository.pick.PickRepository;
import com.dreamypatisiel.devdevdev.exception.InternalServerException;
import com.dreamypatisiel.devdevdev.exception.NotFoundException;
import com.dreamypatisiel.devdevdev.global.common.TimeProvider;
import com.dreamypatisiel.devdevdev.openai.data.response.PickWithSimilarityDto;
import com.dreamypatisiel.devdevdev.openai.embeddings.EmbeddingsService;
import com.dreamypatisiel.devdevdev.web.dto.SliceCommentCustom;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class PickCommonService {
private final PickBestCommentsPolicy pickBestCommentsPolicy;
protected final PickPopularScorePolicy pickPopularScorePolicy;

protected final TimeProvider timeProvider;
protected final PickRepository pickRepository;
protected final PickCommentRepository pickCommentRepository;
protected final PickCommentRecommendRepository pickCommentRecommendRepository;
Expand Down
Loading