Skip to content

Commit

Permalink
[FEATURE] 유저의 데일리 질문을 월별로 조회할 수 있도록 변경 (#110)
Browse files Browse the repository at this point in the history
* feat : 유저가 남긴 데일리 답변의 개수를 모든 카테고리별로 조회하도록 변경 #107

* spotless Apply #107

* feat : 유저가 남긴 데일리 답변을 월별로 조회하도록 변경 #107

* edit : 어노테이션 삭제 #107

* spotless Apply #107
  • Loading branch information
bongsh0112 authored Nov 24, 2023
1 parent e3fcd0c commit 476d587
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 43 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ out/

Domain/src/main/generated/**/*.java

.DS_Store
.DS_Store

AuthKey_N47B75FLFP.p8
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,12 @@ public Long getMyDailyQuestionCountList(
return retrieveMyDailyAnswerUseCase.countByCategory(userId, dailyQuestionCategory);
}

@Operation(summary = "유저가 답변한 데일리 질문에 대한 답변을 카테고리별로 조회합니다.")
@Operation(summary = "유저가 답변한 데일리 질문에 대한 답변을 월별로 카테고리를 이용해 조회합니다.")
@GetMapping("/daily-answer/{userId}")
public SliceResponse<MyDailyQuestionAnswerVo> getMyDailyAnswerList(
@PathVariable Long userId,
@RequestParam DailyQuestionCategory dailyQuestionCategory,
@ParameterObject @PageableDefault Pageable pageable) {
public List<List<MyDailyQuestionAnswerVo>> getMyDailyAnswerList(
@PathVariable Long userId, @RequestParam DailyQuestionCategory dailyQuestionCategory) {

return SliceResponse.of(
retrieveMyDailyAnswerUseCase.execute(userId, dailyQuestionCategory, pageable));
return retrieveMyDailyAnswerUseCase.execute(userId, dailyQuestionCategory);
}

@Operation(summary = "새로운 친구 목록을 조회합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
@Builder
public class MyDailyQuestionAnswerVo {

@Schema(description = "답변한 날짜입니다.", example = "20000101")
@Schema(description = "답변한 월입니다.", example = "1")
private final int month;

@Schema(description = "답변한 날짜입니다.", example = "2023-08-22T01:46:30.000+00:00")
private final Timestamp answerTime;

@Schema(description = "질문의 id(pk)값입니다.", example = "1")
Expand All @@ -28,7 +31,8 @@ public class MyDailyQuestionAnswerVo {

public static MyDailyQuestionAnswerVo from(DailyQuestionAnswerVo dailyQuestionAnswerVo) {
return MyDailyQuestionAnswerVo.builder()
.answerTime(dailyQuestionAnswerVo.getDailyQuestion().getCreatedAt())
.month(dailyQuestionAnswerVo.getMonth())
.answerTime(dailyQuestionAnswerVo.getAnswer().getCreatedAt())
.questionId(dailyQuestionAnswerVo.getDailyQuestion().getId())
.question(dailyQuestionAnswerVo.getDailyQuestion().getContent())
.answerId(dailyQuestionAnswerVo.getAnswer().getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.util.Arrays;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import tify.server.api.user.model.dto.vo.MyDailyQuestionAnswerVo;
import tify.server.api.user.model.dto.vo.UserDailyQuestionAnswerVo;
import tify.server.core.annotation.UseCase;
Expand All @@ -18,11 +16,11 @@ public class RetrieveMyDailyAnswerUseCase {

private final AnswerAdaptor answerAdaptor;

public Slice<MyDailyQuestionAnswerVo> execute(
Long userId, DailyQuestionCategory dailyQuestionCategory, Pageable pageable) {
return answerAdaptor
.searchMyAnswer(userId, dailyQuestionCategory, pageable)
.map(MyDailyQuestionAnswerVo::from);
public List<List<MyDailyQuestionAnswerVo>> execute(
Long userId, DailyQuestionCategory dailyQuestionCategory) {
return answerAdaptor.searchMyAnswer(userId, dailyQuestionCategory).stream()
.map(list -> list.stream().map(MyDailyQuestionAnswerVo::from).toList())
.toList();
}

public List<UserDailyQuestionAnswerVo> countByAllCategory(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package tify.server.domain.domains.question.adaptor;


import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import tify.server.core.annotation.Adaptor;
import tify.server.domain.domains.question.domain.Answer;
Expand Down Expand Up @@ -46,9 +46,13 @@ public Slice<AnswerVo> searchAnswer(Long userId, AnswerCondition answerCondition
return answerRepository.searchToPage(userId, answerCondition);
}

public Slice<DailyQuestionAnswerVo> searchMyAnswer(
Long userId, DailyQuestionCategory dailyQuestionCategory, Pageable pageable) {
return answerRepository.searchMyAnswerToPage(userId, dailyQuestionCategory, pageable);
public List<List<DailyQuestionAnswerVo>> searchMyAnswer(
Long userId, DailyQuestionCategory dailyQuestionCategory) {
List<List<DailyQuestionAnswerVo>> list = new ArrayList<>();
for (int i = 1; i <= 12; i++) {
list.add(answerRepository.searchMyAnswerToPage(userId, dailyQuestionCategory, i));
}
return list;
}

public Long queryUserAnswerCountByDailyQuestionCategory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
@AllArgsConstructor
public class DailyQuestionAnswerVo {

private int month;

private DailyQuestion dailyQuestion;

private Answer answer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import tify.server.domain.domains.question.domain.DailyQuestionCategory;
import tify.server.domain.domains.question.dto.condition.AnswerCondition;
Expand All @@ -17,6 +16,6 @@ public interface AnswerCustomRepository {

Long countMyAnswerByDailyQuestionCategory(Long userId, List<Long> dailyQuestionIdList);

Slice<DailyQuestionAnswerVo> searchMyAnswerToPage(
Long userId, DailyQuestionCategory dailyQuestionCategory, Pageable pageable);
List<DailyQuestionAnswerVo> searchMyAnswerToPage(
Long userId, DailyQuestionCategory dailyQuestionCategory, int month);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import tify.server.domain.common.util.SliceUtil;
import tify.server.domain.domains.question.domain.DailyQuestionCategory;
Expand Down Expand Up @@ -67,24 +66,24 @@ public Long countMyAnswerByDailyQuestionCategory(Long userId, List<Long> dailyQu
}

@Override
public Slice<DailyQuestionAnswerVo> searchMyAnswerToPage(
Long userId, DailyQuestionCategory dailyQuestionCategory, Pageable pageable) {
public List<DailyQuestionAnswerVo> searchMyAnswerToPage(
Long userId, DailyQuestionCategory dailyQuestionCategory, int month) {

List<DailyQuestionAnswerVo> dailyQuestionAnswerVoList =
queryFactory
.select(
Projections.constructor(
DailyQuestionAnswerVo.class, dailyQuestion, answer))
.from(answer)
.join(dailyQuestion)
.on(answer.questionId.eq(dailyQuestion.id))
.where(
answer.userId.eq(userId),
dailyQuestion.category.eq(dailyQuestionCategory))
.offset(pageable.getOffset())
.limit(pageable.getPageSize() + 1)
.fetch();

return SliceUtil.valueOf(dailyQuestionAnswerVoList, pageable);
return queryFactory
.select(
Projections.constructor(
DailyQuestionAnswerVo.class,
answer.createdAt.month(),
dailyQuestion,
answer))
.from(answer)
.join(dailyQuestion)
.on(answer.questionId.eq(dailyQuestion.id))
.where(
answer.userId.eq(userId),
dailyQuestion.category.eq(dailyQuestionCategory),
answer.createdAt.month().eq(month))
.orderBy(answer.createdAt.desc())
.fetch();
}
}

0 comments on commit 476d587

Please sign in to comment.