Skip to content

Commit

Permalink
Merge pull request #75 from Team-baebae/feature/answer/#39
Browse files Browse the repository at this point in the history
fix: imageUrl, 답변되지 않은 질문개수 조회 추가
  • Loading branch information
jihyo-j authored May 15, 2024
2 parents 783fd05 + 0749684 commit c1198f5
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ public ResponseEntity<Void> deleteAnswer(@PathVariable Long answerId) {
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
}

@PatchMapping("/{answerId}/react")
public ResponseEntity<Void> updateAnswerReactions(@PathVariable Long answerId,
@RequestParam int heartCount,
@RequestParam int curiousCount,
@RequestParam int sadCount) {
answerService.updateReactionCounts(answerId, heartCount, curiousCount, sadCount);
return ResponseEntity.ok().build();
}

@GetMapping("/{answerId}/reacted")
public ResponseEntity<Boolean> hasReacted(@PathVariable Long answerId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface AnswerApi {

@Operation(
summary = "답변 생성",
description = "새로운 답변을 생성합니다. 이미지 파일과 오디오 파일을 포함할 수 있습니다.",
description = "새로운 답변을 생성합니다. 이미지 파일을 포함합니다.",
security = @SecurityRequirement(name = "bearerAuth")
)
@Parameter(
Expand Down Expand Up @@ -62,8 +62,8 @@ ResponseEntity<List<AnswerResponse>> getAnswersByMemberId(
@PathVariable Long memberId);
@Operation(
summary = "모든 답변 조회",
description = "모든 답변을 페이지네이션으로 조회합니다.",
security = @SecurityRequirement(name = "bearerAuth")
description = "모든 답변을 페이지네이션으로 조회합니다."

)
@Parameter(
in = ParameterIn.HEADER,
Expand Down Expand Up @@ -112,23 +112,6 @@ 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 = "반응 업데이트 성공")
@PatchMapping("/{answerId}/react")
ResponseEntity<Void> updateAnswerReactions(
@PathVariable Long answerId,
@RequestParam int heartCount,
@RequestParam int curiousCount,
@RequestParam int sadCount);

@Operation(
summary = "특정 답변에 대한 사용자의 반응 여부 확인",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public class AnswerCreateRequest {
private String musicName;
private String musicSinger;
private String musicAudioUrl;
private String imageUrl;

public AnswerCreateRequest(Long questionId, String content,String nickname,
Boolean profileOnOff, String linkAttachments,
String musicName, String musicSinger, String musicAudioUrl) {
String musicName, String musicSinger, String musicAudioUrl, String imageUrl) {
this.questionId = questionId;
this.content = content;
this.nickname = nickname;
Expand All @@ -28,12 +29,13 @@ public AnswerCreateRequest(Long questionId, String content,String nickname,
this.musicName = musicName;
this.musicSinger = musicSinger;
this.musicAudioUrl = musicAudioUrl;
this.imageUrl = imageUrl;
}

public static AnswerCreateRequest of(Long questionId, String content, String nickname,
Boolean profileOnOff, String linkAttachments,
String musicName, String musicSinger, String musicAudioUrl) {
String musicName, String musicSinger, String musicAudioUrl, String imageUrl) {
return new AnswerCreateRequest(questionId, content, nickname, profileOnOff, linkAttachments,
musicName, musicSinger, musicAudioUrl);
musicName, musicSinger, musicAudioUrl, imageUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class AnswerDetailResponse {
private String musicName;
private String musicSinger;
private String musicAudioUrl;
private String imageUrl;
private LocalDateTime createdDate;
private Integer heartCount;
private Integer curiousCount;
Expand All @@ -29,7 +30,7 @@ public class AnswerDetailResponse {
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,
LocalDateTime createdDate,
String imageUrl, LocalDateTime createdDate,
Integer heartCount, Integer curiousCount, Integer sadCount) {
this.answerId = answerId;
this.questionId = questionId;
Expand All @@ -43,6 +44,7 @@ public AnswerDetailResponse(Long answerId, Long questionId, String questionConte
this.musicName = musicName;
this.musicSinger = musicSinger;
this.musicAudioUrl = musicAudioUrl;
this.imageUrl = imageUrl;
this.createdDate = createdDate;
this.heartCount = heartCount;
this.curiousCount = curiousCount;
Expand All @@ -52,10 +54,10 @@ public AnswerDetailResponse(Long answerId, Long questionId, String questionConte
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,
LocalDateTime createdDate,
String imageUrl, LocalDateTime createdDate,
Integer heartCount, Integer curiousCount, Integer sadCount) {
return new AnswerDetailResponse(answerId, questionId, questionContent, memberId, content, memberNickname,
nickname, profileOnOff, linkAttachments, musicName, musicSinger, musicAudioUrl, createdDate,
nickname, profileOnOff, linkAttachments, musicName, musicSinger, musicAudioUrl, imageUrl, createdDate,
heartCount, curiousCount, sadCount);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public class Answer {
@Column(name = "link_attachment")
private String linkAttachments;

@Column(name = "image_url")
private String imageUrl;

@Column(name = "heart_count", nullable = false)
private int heartCount;

Expand All @@ -78,11 +81,11 @@ public class Answer {
private boolean profileOnOff;

public static Answer of(Long id, Question question, Category category, Member member, String nickname,String content,
List<String> imageFiles, Music music, String linkAttachments, int heartCount,
List<String> imageFiles, Music music, String linkAttachments, String imageUrl, int heartCount,
int curiousCount, int sadCount, LocalDateTime createdDate, boolean profileOnOff) {

return new Answer(id, question, category, member, nickname, imageFiles, content, music, linkAttachments, heartCount,
curiousCount, sadCount, createdDate,null, profileOnOff);
return new Answer(id, question, category, member, nickname, imageFiles, content, music, linkAttachments,imageUrl, heartCount,
curiousCount, sadCount, createdDate,null, profileOnOff);
}

public void increaseReactionCount(ReactionValue reaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
@AllArgsConstructor
Expand Down Expand Up @@ -48,6 +49,8 @@ public AnswerDetailResponse toDomain(Answer answer) {
Music music = answer.getMusic();
Member member = answer.getMember();
Question question = answer.getQuestion();
List<String> imageFiles = answer.getImageFiles();
String imageUrl = (imageFiles != null && !imageFiles.isEmpty()) ? imageFiles.get(0) : null;
return AnswerDetailResponse.of(
answer.getId(),
question.getId(),
Expand All @@ -61,6 +64,7 @@ public AnswerDetailResponse toDomain(Answer answer) {
music != null ? music.getMusicName() : null,
music != null ? music.getMusicSinger() : null,
music != null ? music.getMusicAudioUrl() : null,
imageUrl,
answer.getCreatedDate(),
answer.getHeartCount(),
answer.getCuriousCount(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ ResponseEntity<CategoryResponse.CategoryInformationResponse> createCategory(


@Operation(summary = "멤버의 모든 카테고리 조회",
description = "멤버 ID를 받아 해당 멤버의 모든 카테고리를 조회합니다.",
security = @SecurityRequirement(name = "bearerAuth")
description = "멤버 ID를 받아 해당 멤버의 모든 카테고리를 조회합니다."

)
@Parameter(
in = ParameterIn.HEADER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public ResponseEntity<Void> deleteQuestion(@PathVariable Long questionId) {
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
}

@GetMapping("/count/{memberId}")
public ResponseEntity<Long> countQuestionsByMemberId(@PathVariable Long memberId) {
long count = questionService.countQuestionsByMemberId(memberId);
@GetMapping("/unanswered/count/{memberId}")
public ResponseEntity<Long> getUnansweredQuestionCount(@PathVariable Long memberId) {
long count = questionService.getUnansweredQuestionCount(memberId);
return ResponseEntity.ok(count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ ResponseEntity<Void> updateQuestion(
@ApiResponse(responseCode = "204", description = "질문 삭제 성공")
@DeleteMapping("/{questionId}")
ResponseEntity<Void> deleteQuestion(@PathVariable Long questionId);

@Operation(
summary = "질문 개수 조회",
description = "특정 회원이 받은 모든 질문의 개수를 조회합니다.",
summary = "답변되지 않은 질문 개수 조회",
description = "특정 회원의 답변되지 않은 질문의 개수를 조회합니다.",
security = @SecurityRequirement(name = "bearerAuth")
)
@ApiResponse(responseCode = "200", description = "질문 개수 조회 성공",
@ApiResponse(responseCode = "200", description = "답변되지 않은 질문 개수 조회 성공",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Long.class)))
@GetMapping("/count/{memberId}")
ResponseEntity<Long> countQuestionsByMemberId(@PathVariable Long memberId);
@GetMapping("/unanswered/count/{memberId}")
ResponseEntity<Long> getUnansweredQuestionCount(@PathVariable Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ public interface QuestionJpaRepository extends JpaRepository<Question, Long> {
Page<Question> findAllByMemberId(Long memberId, Pageable pageable);
Page<Question> findAllByMemberIdAndIsAnsweredTrue(Long memberId, Pageable pageable);
Page<Question> findAllByMemberIdAndIsAnsweredFalse(Long memberId, Pageable pageable);
Long countByMemberId(Long memberId);

long countByMemberIdAndIsAnsweredFalse(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ public interface QuestionRepository{
Page<Question> findAllByMemberIdAndIsAnsweredTrue(Long memberId, Pageable pageable);
Page<Question> findAllByMemberIdAndIsAnsweredFalse(Long memberId, Pageable pageable);
void delete(Question questionEntity);
Long countByMemberId(Long memberId);

long countByMemberIdAndIsAnsweredFalse(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public void delete(Question questionEntity) {
}

@Override
public Long countByMemberId(Long memberId) {
return questionJpaRepository.countByMemberId(memberId);
public long countByMemberIdAndIsAnsweredFalse(Long memberId) {
return questionJpaRepository.countByMemberIdAndIsAnsweredFalse(memberId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public Page<QuestionDetailResponse> getUnansweredQuestions(Long memberId, Pageab
}

@Transactional(readOnly = true)
public long countQuestionsByMemberId(Long memberId) {
return questionRepository.countByMemberId(memberId);
public long getUnansweredQuestionCount(Long memberId) {
return questionRepository.countByMemberIdAndIsAnsweredFalse(memberId);
}

}

0 comments on commit c1198f5

Please sign in to comment.