Skip to content

Commit

Permalink
Merge pull request #77 from Team-baebae/feature/answer/#39
Browse files Browse the repository at this point in the history
fix: 반응시 클릭했는지 본인확인 여부 추가
  • Loading branch information
jihyo-j authored May 15, 2024
2 parents c1198f5 + 1377ee4 commit ec297ce
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,4 @@ public ResponseEntity<Void> deleteAnswer(@PathVariable Long answerId) {
}


@GetMapping("/{answerId}/reacted")
public ResponseEntity<Boolean> hasReacted(@PathVariable Long answerId,
@RequestParam Long memberId,
@RequestParam ReactionValue reactionValue) {
boolean hasReacted = answerService.hasReacted(answerId, memberId, reactionValue);
return ResponseEntity.ok(hasReacted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,4 @@ ResponseEntity<AnswerDetailResponse> updateAnswer(
ResponseEntity<Void> 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<Boolean> hasReacted(
@PathVariable Long answerId,
@RequestParam Long memberId,
@RequestParam ReactionValue reactionValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
Expand Down Expand Up @@ -51,6 +53,7 @@ public AnswerDetailResponse toDomain(Answer answer) {
Question question = answer.getQuestion();
List<String> 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(),
Expand All @@ -68,7 +71,8 @@ public AnswerDetailResponse toDomain(Answer answer) {
answer.getCreatedDate(),
answer.getHeartCount(),
answer.getCuriousCount(),
answer.getSadCount()
answer.getSadCount(),
isClicked
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

public interface MemberAnswerReactionRepository extends JpaRepository<MemberAnswerReaction, Long> {
Optional<MemberAnswerReaction> findByMemberAndAnswerAndReaction(Member member, Answer answer, ReactionValue reaction);
Optional<MemberAnswerReaction> findByMemberIdAndAnswerId(Long memberId, Long answerId);
}

0 comments on commit ec297ce

Please sign in to comment.