From 1377ee44dd48bbdb92dec65f39bdb3156e4734b0 Mon Sep 17 00:00:00 2001 From: jihyo Date: Thu, 16 May 2024 00:09:11 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=B0=98=EC=9D=91=EC=8B=9C=20=ED=81=B4?= =?UTF-8?q?=EB=A6=AD=ED=96=88=EB=8A=94=EC=A7=80=20=EB=B3=B8=EC=9D=B8?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=EC=97=AC=EB=B6=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../answer/controller/AnswerController.java | 7 ------- .../domain/answer/controller/api/AnswerApi.java | 17 ----------------- .../domain/answer/dto/AnswerDetailResponse.java | 8 +++++--- .../domain/answer/repository/AnswerMapper.java | 6 +++++- .../domain/answer/service/AnswerService.java | 13 +------------ .../MemberAnswerReactionRepository.java | 1 + 6 files changed, 12 insertions(+), 40 deletions(-) diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/controller/AnswerController.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/controller/AnswerController.java index 73540ac5..d96546ff 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/controller/AnswerController.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/controller/AnswerController.java @@ -69,11 +69,4 @@ public ResponseEntity deleteAnswer(@PathVariable Long answerId) { } - @GetMapping("/{answerId}/reacted") - public ResponseEntity hasReacted(@PathVariable Long answerId, - @RequestParam Long memberId, - @RequestParam ReactionValue reactionValue) { - boolean hasReacted = answerService.hasReacted(answerId, memberId, reactionValue); - return ResponseEntity.ok(hasReacted); - } } diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/controller/api/AnswerApi.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/controller/api/AnswerApi.java index 6a8efc40..2e891bb4 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/controller/api/AnswerApi.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/controller/api/AnswerApi.java @@ -112,21 +112,4 @@ ResponseEntity updateAnswer( ResponseEntity deleteAnswer( @PathVariable Long answerId); - - @Operation( - summary = "특정 답변에 대한 사용자의 반응 여부 확인", - description = "특정 답변에 대해 사용자가 이미 반응(좋아요, 궁금해요, 슬퍼요)을 남겼는지 여부를 확인합니다.", - security = @SecurityRequirement(name = "bearerAuth") - ) - @Parameter( - in = ParameterIn.HEADER, - name = "Authorization", required = true, - schema = @Schema(type = "string"), - description = "Bearer [Access 토큰]") - @ApiResponse(responseCode = "200", description = "반응 여부 확인 성공") - @GetMapping("/{answerId}/reacted") - ResponseEntity hasReacted( - @PathVariable Long answerId, - @RequestParam Long memberId, - @RequestParam ReactionValue reactionValue); } diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/dto/AnswerDetailResponse.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/dto/AnswerDetailResponse.java index 9be975da..bd6de801 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/dto/AnswerDetailResponse.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/dto/AnswerDetailResponse.java @@ -26,12 +26,13 @@ public class AnswerDetailResponse { private Integer heartCount; private Integer curiousCount; private Integer sadCount; + private Boolean isClicked; public AnswerDetailResponse(Long answerId, Long questionId, String questionContent, Long memberId, String content, String memberNickname, String nickname, Boolean profileOnOff, String linkAttachments, String musicName, String musicSinger, String musicAudioUrl, String imageUrl, LocalDateTime createdDate, - Integer heartCount, Integer curiousCount, Integer sadCount) { + Integer heartCount, Integer curiousCount, Integer sadCount, Boolean isClicked) { this.answerId = answerId; this.questionId = questionId; this.questionContent = questionContent; @@ -49,16 +50,17 @@ public AnswerDetailResponse(Long answerId, Long questionId, String questionConte this.heartCount = heartCount; this.curiousCount = curiousCount; this.sadCount = sadCount; + this.isClicked = isClicked; } public static AnswerDetailResponse of(Long answerId, Long questionId, String questionContent, Long memberId, String content, String memberNickname, String nickname, Boolean profileOnOff, String linkAttachments, String musicName, String musicSinger, String musicAudioUrl, String imageUrl, LocalDateTime createdDate, - Integer heartCount, Integer curiousCount, Integer sadCount) { + Integer heartCount, Integer curiousCount, Integer sadCount, Boolean isClicked) { return new AnswerDetailResponse(answerId, questionId, questionContent, memberId, content, memberNickname, nickname, profileOnOff, linkAttachments, musicName, musicSinger, musicAudioUrl, imageUrl, createdDate, - heartCount, curiousCount, sadCount); + heartCount, curiousCount, sadCount, isClicked); } } diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/repository/AnswerMapper.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/repository/AnswerMapper.java index 749c9886..ec6be895 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/repository/AnswerMapper.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/repository/AnswerMapper.java @@ -7,6 +7,7 @@ import com.web.baebaeBE.domain.question.entity.Question; import com.web.baebaeBE.domain.answer.dto.AnswerCreateRequest; import com.web.baebaeBE.domain.answer.dto.AnswerDetailResponse; +import com.web.baebaeBE.domain.reaction.repository.MemberAnswerReactionRepository; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; @@ -16,6 +17,7 @@ @Component @AllArgsConstructor public class AnswerMapper { + private final MemberAnswerReactionRepository memberAnswerReactionRepository; public Answer toEntity(AnswerCreateRequest request, Question question, Member member) { // Music 엔티티 생성 Music music = Music.builder() @@ -51,6 +53,7 @@ public AnswerDetailResponse toDomain(Answer answer) { Question question = answer.getQuestion(); List imageFiles = answer.getImageFiles(); String imageUrl = (imageFiles != null && !imageFiles.isEmpty()) ? imageFiles.get(0) : null; + boolean isClicked = memberAnswerReactionRepository.findByMemberIdAndAnswerId(member.getId(), answer.getId()).isPresent(); return AnswerDetailResponse.of( answer.getId(), question.getId(), @@ -68,7 +71,8 @@ public AnswerDetailResponse toDomain(Answer answer) { answer.getCreatedDate(), answer.getHeartCount(), answer.getCuriousCount(), - answer.getSadCount() + answer.getSadCount(), + isClicked ); } diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/service/AnswerService.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/service/AnswerService.java index 6f005d66..0dad14f2 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/service/AnswerService.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/answer/service/AnswerService.java @@ -6,15 +6,12 @@ import com.web.baebaeBE.domain.answer.repository.AnswerMapper; import com.web.baebaeBE.domain.categorized.answer.entity.CategorizedAnswer; import com.web.baebaeBE.domain.categorized.answer.repository.CategorizedAnswerRepository; -import com.web.baebaeBE.domain.category.entity.Category; import com.web.baebaeBE.domain.login.exception.LoginException; import com.web.baebaeBE.domain.member.entity.Member; import com.web.baebaeBE.domain.member.repository.MemberRepository; import com.web.baebaeBE.domain.notification.dto.NotificationRequest; import com.web.baebaeBE.domain.notification.service.NotificationService; import com.web.baebaeBE.domain.question.repository.QuestionRepository; -import com.web.baebaeBE.domain.reaction.entity.ReactionValue; -import com.web.baebaeBE.domain.reaction.repository.MemberAnswerReactionRepository; import com.web.baebaeBE.global.error.exception.BusinessException; import com.web.baebaeBE.global.image.s3.S3ImageStorageService; import com.web.baebaeBE.domain.answer.entity.Answer; @@ -30,7 +27,6 @@ import java.io.IOException; import java.io.InputStream; -import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; @@ -41,7 +37,6 @@ public class AnswerService { private final MemberRepository memberRepository; private final QuestionRepository questionRepository; private final CategorizedAnswerRepository categorizedAnswerRepository; - private final MemberAnswerReactionRepository memberAnswerReactionRepository; private final NotificationService notificationService; private final S3ImageStorageService s3ImageStorageService; private final AnswerMapper answerMapper; @@ -156,11 +151,5 @@ public void updateReactionCounts(Long answerId, int heartCount, int curiousCount ); notificationService.createNotification(notificationDto); } - public boolean hasReacted(Long answerId, Long memberId, ReactionValue reactionValue) { - Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new BusinessException(LoginException.NOT_EXIST_MEMBER)); - Answer answer = answerRepository.findByAnswerId(answerId) - .orElseThrow(() -> new BusinessException(AnswerError.NO_EXIST_ANSWER)); - return memberAnswerReactionRepository.findByMemberAndAnswerAndReaction(member, answer, reactionValue).isPresent(); - } + } diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/reaction/repository/MemberAnswerReactionRepository.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/reaction/repository/MemberAnswerReactionRepository.java index b036115b..3f8197a1 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/reaction/repository/MemberAnswerReactionRepository.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/reaction/repository/MemberAnswerReactionRepository.java @@ -10,4 +10,5 @@ public interface MemberAnswerReactionRepository extends JpaRepository { Optional findByMemberAndAnswerAndReaction(Member member, Answer answer, ReactionValue reaction); + Optional findByMemberIdAndAnswerId(Long memberId, Long answerId); }