Skip to content

Commit

Permalink
[SAMBAD-175] meeting_question_id 기반 질문 정보 조회 API 추가 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkjsw17 authored Jul 29, 2024
1 parent e2d72dc commit 0406fa1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public ResponseEntity<MyMeetingAnswerListResponse> findMyList(
@ApiResponse(responseCode = "403", description = "USER_NOT_MEMBER_OF_MEETING"),
@ApiResponse(responseCode = "404", description = "NOT_FOUND_MEETING_QUESTION")
})
@GetMapping("/meetings/{meetingId}/questions/{questionId}/answers/most-selected")
@GetMapping("/meetings/{meetingId}/questions/{meetingQuestionId}/answers/most-selected")
public ResponseEntity<SelectedAnswerResponse> getMostSelectedMeetingAnswer(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable(name = "meetingId") Long meetingId,
@Parameter(description = "모임 질문 ID", example = "1", required = true) @PathVariable(name = "questionId") Long meetingQuestionId
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable Long meetingId,
@Parameter(description = "모임 질문 ID", example = "1", required = true) @PathVariable Long meetingQuestionId
) {
SelectedAnswerResponse response = meetingAnswerResultService.getMostSelectedAnswer(
userId, meetingId, meetingQuestionId);
Expand All @@ -92,11 +92,11 @@ public ResponseEntity<SelectedAnswerResponse> getMostSelectedMeetingAnswer(
@ApiResponse(responseCode = "403", description = "USER_NOT_MEMBER_OF_MEETING"),
@ApiResponse(responseCode = "404", description = "MEETING_MEMBER_NOT_FOUND")
})
@GetMapping("/meetings/{meetingId}/questions/{questionId}/answers/selected-same")
@GetMapping("/meetings/{meetingId}/questions/{meetingQuestionId}/answers/selected-same")
public ResponseEntity<SelectedAnswerResponse> getSelectedSameMeetingAnswers(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable(name = "meetingId") Long meetingId,
@Parameter(description = "모임 질문 ID", example = "1", required = true) @PathVariable(name = "questionId") Long meetingQuestionId
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable Long meetingId,
@Parameter(description = "모임 질문 ID", example = "1", required = true) @PathVariable Long meetingQuestionId
) {
SelectedAnswerResponse response = meetingAnswerResultService.getSelectedSameAnswer(
userId, meetingId, meetingQuestionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public record SelectedAnswerResponse(
@Schema(description = "선택한 멤버들", requiredMode = REQUIRED)
List<MeetingMemberListResponseDetail> selectedMembers
) {
public static SelectedAnswerResponse from(List<MeetingMember> members,
List<MeetingAnswer> answers) {
public static SelectedAnswerResponse from(List<MeetingMember> members, List<MeetingAnswer> answers) {
return new SelectedAnswerResponse(
answers.stream()
.map(MeetingAnswer::getAnswerContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.depromeet.sambad.moring.meeting.question.presentation.response.MostInactiveMeetingQuestionListResponse;
import org.depromeet.sambad.moring.question.application.QuestionService;
import org.depromeet.sambad.moring.question.domain.Question;
import org.depromeet.sambad.moring.question.presentation.response.QuestionResponse;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -104,6 +105,14 @@ public MeetingQuestion getById(Long meetingId, Long meetingQuestionId) {
.orElseThrow(NotFoundMeetingQuestion::new);
}

/*
* 질문 정보의 경우 Public한 데이터이므로, 따로 권한 체크를 하지 않는다.
*/
public QuestionResponse getQuestionResponseById(Long meetingId, Long meetingQuestionId) {
MeetingQuestion meetingQuestion = getById(meetingId, meetingQuestionId);
return QuestionResponse.from(meetingQuestion.getQuestion());
}

private Optional<MeetingQuestion> findActiveMeetingQuestion(Long meetingId) {
return meetingQuestionRepository.findActiveOneByMeeting(meetingId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.depromeet.sambad.moring.meeting.question.presentation.response.FullInactiveMeetingQuestionListResponse;
import org.depromeet.sambad.moring.meeting.question.presentation.response.MeetingQuestionAndAnswerListResponse;
import org.depromeet.sambad.moring.meeting.question.presentation.response.MostInactiveMeetingQuestionListResponse;
import org.depromeet.sambad.moring.question.presentation.response.QuestionResponse;
import org.depromeet.sambad.moring.user.presentation.resolver.UserId;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.HttpStatus;
Expand All @@ -31,7 +32,7 @@
@Tag(name = "모임의 릴레이 질문", description = "모임원이 선택한 릴레이 질문 관련 api / 담당자: 김나현")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1")
@RequestMapping("/v1/meetings/{meetingId}/questions")
public class MeetingQuestionController {

private final MeetingQuestionService meetingQuestionService;
Expand All @@ -42,7 +43,7 @@ public class MeetingQuestionController {
@ApiResponse(responseCode = "404", description = "NOT_FOUND_QUESTION"),
@ApiResponse(responseCode = "409", description = "DUPLICATE_MEETING_QUESTION / INVALID_MEETING_MEMBER_TARGET")
})
@PostMapping("/meetings/{meetingId}/questions")
@PostMapping
public ResponseEntity<ActiveMeetingQuestionResponse> save(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable("meetingId") Long meetingId,
Expand All @@ -52,6 +53,21 @@ public ResponseEntity<ActiveMeetingQuestionResponse> save(
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}

@Operation(summary = "모임 질문 상세 조회", description = "모임 질문 상세 정보를 반환합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "404", description = "NOT_FOUND_MEETING_QUESTION"),
})
@GetMapping("/{meetingQuestionId}")
public ResponseEntity<QuestionResponse> getById(
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable Long meetingId,
@Parameter(description = "질문 ID", example = "1", required = true) @PathVariable Long meetingQuestionId
) {
QuestionResponse response = meetingQuestionService.getQuestionResponseById(meetingId, meetingQuestionId);

return ResponseEntity.ok().body(response);
}

@Operation(summary = "현재 진행 중인 릴레이 질문 조회", description = "모임원 참여율과 질문인에 대한 정보들을 함께 반환합니다.")
@ApiResponses(value = {
@ApiResponse(
Expand All @@ -64,7 +80,7 @@ public ResponseEntity<ActiveMeetingQuestionResponse> save(
content = @Content(schema = @Schema(implementation = Object.class))
)
})
@GetMapping("/meetings/{meetingId}/questions/active")
@GetMapping("/active")
public ResponseEntity<ActiveMeetingQuestionResponse> findActiveOne(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable("meetingId") Long meetingId
Expand All @@ -76,30 +92,15 @@ public ResponseEntity<ActiveMeetingQuestionResponse> findActiveOne(
return ResponseEntity.ok(activeOne);
}

@Operation(summary = "홈 화면 내 종료된 릴레이 질문 2건 조회", description = "- 참여율 순으로 내림차순 정렬한 후 2건 반환합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "403", description = "USER_NOT_MEMBER_OF_MEETING")
})
@GetMapping("/meetings/{meetingId}/questions/inactive/top")
public ResponseEntity<MostInactiveMeetingQuestionListResponse> findMostInactiveList(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable("meetingId") Long meetingId
) {
MostInactiveMeetingQuestionListResponse inactiveList = meetingQuestionService.findMostInactiveList(userId,
meetingId);
return ResponseEntity.ok(inactiveList);
}

@Operation(summary = "진행 중인 모임의 릴레이 질문과 답안 옵션 조회", description = "- 질문과 질문의 답변 목록을 함께 반환합니다.\n"
+ "- 등록된 모임 질문에 모임원이 답변을 할 때 사용하는 API 입니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "403", description = "USER_NOT_MEMBER_OF_MEETING"),
@ApiResponse(responseCode = "404", description = "NOT_FOUND_MEETING_QUESTION")
})
@GetMapping("/meetings/{meetingId}/questions/active/answers")
public ResponseEntity<MeetingQuestionAndAnswerListResponse> findMeeingQuestionAndAnswerList(
@GetMapping("/active/answers")
public ResponseEntity<MeetingQuestionAndAnswerListResponse> findMeetingQuestionAndAnswerList(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable("meetingId") Long meetingId
) {
Expand All @@ -114,7 +115,7 @@ public ResponseEntity<MeetingQuestionAndAnswerListResponse> findMeeingQuestionAn
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "403", description = "USER_NOT_MEMBER_OF_MEETING")
})
@GetMapping("/meetings/{meetingId}/questions/inactive")
@GetMapping("/inactive")
public ResponseEntity<FullInactiveMeetingQuestionListResponse> findFullInactiveList(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable("meetingId") Long meetingId,
Expand All @@ -126,4 +127,19 @@ public ResponseEntity<FullInactiveMeetingQuestionListResponse> findFullInactiveL
PageRequest.of(page, size));
return ResponseEntity.ok(inactiveList);
}

@Operation(summary = "홈 화면 내 종료된 릴레이 질문 2건 조회", description = "- 참여율 순으로 내림차순 정렬한 후 2건 반환합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "403", description = "USER_NOT_MEMBER_OF_MEETING")
})
@GetMapping("/inactive/top")
public ResponseEntity<MostInactiveMeetingQuestionListResponse> findMostInactiveList(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable("meetingId") Long meetingId
) {
MostInactiveMeetingQuestionListResponse inactiveList = meetingQuestionService.findMostInactiveList(userId,
meetingId);
return ResponseEntity.ok(inactiveList);
}
}

0 comments on commit 0406fa1

Please sign in to comment.