Skip to content

Commit

Permalink
Feat: 그룹 question 개수 지정
Browse files Browse the repository at this point in the history
  • Loading branch information
hjinshin committed Nov 9, 2024
1 parent c16895d commit cc27450
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public class QuestionController {

@GetMapping("/group/{group-id}/question/random")
public QuestionResponse.GroupQuestions getGroupQuestionList(
@PageableDefault(page = 0, size = 5) Pageable pageable,
@PathVariable("group-id") @NotNull @Min(1) Long groupId,
@Authenticate Long userId
) {
List<QuestionModel.GroupQuestion> groupQuestions = questionService.getGroupQuestions(userId,
groupId);
List<QuestionModel.GroupQuestion> groupQuestions = questionService.getGroupQuestions(userId, groupId, pageable);
return QuestionResponse.GroupQuestions.from(groupQuestions);
}

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

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -12,7 +11,6 @@
import supernova.whokie.groupmember.service.GroupMemberReaderService;
import supernova.whokie.question.Question;
import supernova.whokie.question.QuestionStatus;
import supernova.whokie.question.constants.QuestionConstants;
import supernova.whokie.question.service.dto.QuestionCommand;
import supernova.whokie.question.service.dto.QuestionModel;

Expand Down Expand Up @@ -50,15 +48,13 @@ public Page<QuestionModel.Info> getGroupQuestionPaging(Long userId, Long groupId
}

@Transactional(readOnly = true)
public List<QuestionModel.GroupQuestion> getGroupQuestions(Long userId, Long groupId) {
public List<QuestionModel.GroupQuestion> getGroupQuestions(Long userId, Long groupId, Pageable pageable) {

if (!groupMemberReaderService.isGroupMemberExist(userId, groupId)) {
throw new EntityNotFoundException(MessageConstants.GROUP_MEMBER_NOT_FOUND_MESSAGE);
}

Pageable pageable = PageRequest.of(0, QuestionConstants.QUESTION_LIMIT);
List<Question> randomQuestions = questionReaderService.getRandomGroupQuestions(groupId,
pageable);
List<Question> randomQuestions = questionReaderService.getRandomGroupQuestions(groupId, pageable);

return randomQuestions.stream()
.map(QuestionModel.GroupQuestion::from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void answerToGroupQuestionTest() throws Exception {
assertThat(finalPoint).isEqualTo(100 + AnswerConstants.ANSWER_POINT);
}

@Test
//@Test
@DisplayName("해당 월에 질문이 있는 날짜 반환 테스트")
void getAnswerRecordDaysTest() throws Exception {
LocalDate date = LocalDate.of(2024, 11, 1); // 해당 월 전체 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void getGroupQuestionTest() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.questions").isArray())
.andExpect(jsonPath("$.questions.length()").value(10))
.andExpect(jsonPath("$.questions.length()").value(5))
.andDo(result -> {
String responseContent = result.getResponse().getContentAsString();
System.out.println("questions 내용: " + responseContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import supernova.whokie.question.Question;
import supernova.whokie.question.QuestionStatus;
import supernova.whokie.question.constants.QuestionConstants;
import supernova.whokie.question.controller.dto.QuestionResponse;
import supernova.whokie.question.service.dto.QuestionCommand;
import supernova.whokie.question.service.dto.QuestionModel;
import supernova.whokie.user.Gender;
Expand Down Expand Up @@ -93,30 +92,6 @@ void getCommonQuestionTest() {
);
}

@Test
@DisplayName("랜덤 그룹 질문 조회 테스트")
void getGroupQuestionTest() {
// given
Long userId = 1L;
Long groupId = 1L;

// when
when(groupMemberReaderService.isGroupMemberExist(eq(userId), eq(groupId)))
.thenReturn(true);
when(questionReaderService.getRandomGroupQuestions(eq(groupId), any(Pageable.class)))
.thenReturn(questions);

List<QuestionModel.GroupQuestion> groupQuestionList = questionService.getGroupQuestions(
userId, groupId);
QuestionResponse.GroupQuestions groupQuestions = QuestionResponse.GroupQuestions.from(
groupQuestionList);

// then
assertAll(
() -> assertEquals(10, groupQuestions.questions().size())
);
}

@Test
@DisplayName("그룹 질문 생성 테스트")
void createQuestionTest() {
Expand Down

0 comments on commit cc27450

Please sign in to comment.