Skip to content

Commit

Permalink
[SAMBAD-261]-feat: 다음 질문인 정보 조회 (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeHanEum authored Aug 20, 2024
1 parent f0dce0e commit a83bc48
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.depromeet.sambad.moring.meeting.answer.domain.MeetingAnswer;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMember;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberListResponse;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberListResponseDetail;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberSummaryResponse;

import io.swagger.v3.oas.annotations.media.Schema;

Expand All @@ -19,7 +19,7 @@ public record SelectedAnswerResponse(
int count,

@Schema(description = "선택한 모임원 목록", requiredMode = REQUIRED)
List<MeetingMemberListResponseDetail> selectedMembers
List<MeetingMemberSummaryResponse> selectedMembers
) {
public static SelectedAnswerResponse from(List<MeetingMember> members, List<MeetingAnswer> meetingAnswers) {
return new SelectedAnswerResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import org.depromeet.sambad.moring.meeting.comment.domain.comment.MeetingQuestionComment;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMember;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberListResponseDetail;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberSummaryResponse;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand All @@ -20,15 +20,15 @@ public record MeetingCommentListResponseDetail(
String content,

@Schema(description = "코멘트 작성자", requiredMode = REQUIRED)
MeetingMemberListResponseDetail writer
MeetingMemberSummaryResponse writer
) {
public static MeetingCommentListResponseDetail from(MeetingQuestionComment meetingQuestionComment) {
MeetingMember writer = meetingQuestionComment.getMeetingMember();

return MeetingCommentListResponseDetail.builder()
.meetingQuestionCommentId(meetingQuestionComment.getId())
.content(meetingQuestionComment.getContent())
.writer(MeetingMemberListResponseDetail.from(writer))
.writer(MeetingMemberSummaryResponse.from(writer))
.build();
}

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

import org.depromeet.sambad.moring.meeting.comment.domain.reply.MeetingQuestionCommentReply;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMember;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberListResponseDetail;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberSummaryResponse;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand All @@ -18,14 +18,14 @@ public record MeetingQuestionCommentReplyResponse(
String content,

@Schema(description = "릴레이질문 코멘트 답글 작성자", example = "{\"meetingMemberId\":1,\"name\":\"이한음\",\"profileImageFileUrl\":\"https://example.com\",\"role\":\"OWNER\"}", requiredMode = REQUIRED)
MeetingMemberListResponseDetail writer
MeetingMemberSummaryResponse writer
) {
public static MeetingQuestionCommentReplyResponse from(MeetingQuestionCommentReply commentReply) {
MeetingMember writer = commentReply.getMeetingMember();
MeetingQuestionCommentReplyResponseBuilder builder = MeetingQuestionCommentReplyResponse.builder()
.meetingQuestionCommentReplyId(commentReply.getId())
.content(commentReply.getContent())
.writer(MeetingMemberListResponseDetail.from(writer));
.writer(MeetingMemberSummaryResponse.from(writer));
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import org.depromeet.sambad.moring.meeting.member.presentation.exception.NoMeetingMemberInConditionException;
import org.depromeet.sambad.moring.meeting.member.presentation.request.MeetingMemberPersistRequest;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberListResponse;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberListResponseDetail;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberPersistResponse;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberResponse;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberSummaryResponse;
import org.depromeet.sambad.moring.meeting.question.application.MeetingQuestionRepository;
import org.depromeet.sambad.moring.meeting.question.domain.MeetingQuestion;
import org.depromeet.sambad.moring.user.domain.User;
Expand Down Expand Up @@ -91,7 +91,7 @@ public MeetingMemberResponse getMyMeetingMember(Long userId, Long meetingId) {
return MeetingMemberResponse.from(getByUserIdAndMeetingId(userId, meetingId));
}

public MeetingMemberListResponseDetail getRandomMeetingMember(Long userId, Long meetingId,
public MeetingMemberSummaryResponse getRandomMeetingMember(Long userId, Long meetingId,
List<Long> excludeMemberIds) {
meetingMemberValidator.validateUserIsMemberOfMeeting(userId, meetingId);

Expand All @@ -103,7 +103,7 @@ public MeetingMemberListResponseDetail getRandomMeetingMember(Long userId, Long
}

MeetingMember randomMember = meetingMemberRandomGenerator.generate(nextTargetMembers);
return MeetingMemberListResponseDetail.from(randomMember);
return MeetingMemberSummaryResponse.from(randomMember);
}

public boolean isNotEnterAnyMeeting(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.depromeet.sambad.moring.meeting.member.presentation;

import static org.springframework.http.HttpStatus.*;
import static org.springframework.http.HttpStatus.CREATED;

import java.util.List;

import org.depromeet.sambad.moring.meeting.member.application.MeetingMemberService;
import org.depromeet.sambad.moring.meeting.member.presentation.request.MeetingMemberPersistRequest;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberListResponse;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberListResponseDetail;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberPersistResponse;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberResponse;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberSummaryResponse;
import org.depromeet.sambad.moring.user.presentation.resolver.UserId;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -105,12 +105,12 @@ public ResponseEntity<MeetingMemberPersistResponse> createMeetingMember(
@ApiResponse(responseCode = "404", description = "NO_MEETING_MEMBER_IN_CONDITION")
})
@GetMapping("/{meetingId}/members/questions/target")
public ResponseEntity<MeetingMemberListResponseDetail> getRandomQuestionMember(
public ResponseEntity<MeetingMemberSummaryResponse> getRandomQuestionMember(
@UserId Long userId,
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable("meetingId") Long meetingId,
@Parameter(description = "랜덤 대상자 제외할 모임원 ID 리스트", example = "2") @RequestParam(value = "excludeMemberIds", required = false) List<Long> excludeMemberIds
) {
MeetingMemberListResponseDetail response = meetingMemberService.getRandomMeetingMember(userId, meetingId,
MeetingMemberSummaryResponse response = meetingMemberService.getRandomMeetingMember(userId, meetingId,
excludeMemberIds);
return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public record MeetingMemberListResponse(
example = "[{\"meetingMemberId\":1,\"name\":\"이한음\",\"profileImageFileUrl\":\"https://example.com\",\"role\":\"OWNER\"}]",
requiredMode = REQUIRED
)
List<MeetingMemberListResponseDetail> contents
List<MeetingMemberSummaryResponse> contents
) {

public static MeetingMemberListResponse from(List<MeetingMember> members) {
List<MeetingMemberListResponseDetail> memberResponses = members.stream()
List<MeetingMemberSummaryResponse> memberResponses = members.stream()
.sorted()
.map(MeetingMemberListResponseDetail::from)
.map(MeetingMemberSummaryResponse::from)
.toList();

return new MeetingMemberListResponse(memberResponses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import io.swagger.v3.oas.annotations.media.Schema;

public record MeetingMemberListResponseDetail(
public record MeetingMemberSummaryResponse(
@Schema(description = "모임원 ID", example = "1", requiredMode = REQUIRED)
Long meetingMemberId,

Expand All @@ -22,8 +22,8 @@ public record MeetingMemberListResponseDetail(
@Schema(description = "모임원 역할", example = "OWNER", requiredMode = REQUIRED)
MeetingMemberRole role
) {
public static MeetingMemberListResponseDetail from(MeetingMember member) {
return new MeetingMemberListResponseDetail(
public static MeetingMemberSummaryResponse from(MeetingMember member) {
return new MeetingMemberSummaryResponse(
member.getId(),
member.getName(),
member.getProfileImageUrl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public interface MeetingQuestionRepository {

Optional<MeetingQuestion> findByMeetingIdAndMeetingQuestionId(Long meetingId, Long meetingQuestionId);

Optional<MeetingQuestion> findFirstByStatusAndStartTimeAfterOrderByStartTime(MeetingQuestionStatus status, LocalDateTime now);

List<MeetingQuestionStatisticsDetail> findStatistics(Long meetingQuestionId);

List<MeetingMember> findMeetingMembersByMeetingQuestionId(Long meetingQuestionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public CurrentMeetingQuestionResponse save(Long userId, Long meetingId, MeetingQ
meeting, nextTargetMember, currentMeetingQuestion.getNextStartTime(), meeting.getTotalMemberCount());
meetingQuestionRepository.save(nextMeetingQuestion);

return CurrentMeetingQuestionResponse.questionRegisteredOf(currentMeetingQuestion, false);
return CurrentMeetingQuestionResponse.questionRegisteredOf(currentMeetingQuestion, nextTargetMember, false);
}

@Transactional
Expand All @@ -103,13 +103,8 @@ public Optional<CurrentMeetingQuestionResponse> findCurrentOne(Long userId, Long

if (activeMeetingQuestionOpt.isPresent()) {
MeetingQuestion activeMeetingQuestion = activeMeetingQuestionOpt.get();

return activeMeetingQuestion.getQuestion() == null
? Optional.of(CurrentMeetingQuestionResponse.questionNotRegisteredOf(activeMeetingQuestion))
: Optional.of(CurrentMeetingQuestionResponse.questionRegisteredOf(activeMeetingQuestion,
meetingQuestionRepository.isAnswered(activeMeetingQuestion.getId(), meetingMember.getId())));
return Optional.of(getCurrentMeetingQuestionResponse(activeMeetingQuestion, meetingMember));
}

return Optional.empty();
}

Expand Down Expand Up @@ -158,6 +153,23 @@ public MeetingMemberListResponse getMeetingMembersByMeetingQuestionId(
return MeetingMemberListResponse.from(members);
}

private CurrentMeetingQuestionResponse getCurrentMeetingQuestionResponse(
MeetingQuestion activeMeetingQuestion, MeetingMember meetingMember) {
if (activeMeetingQuestion.getQuestion() == null) {
return CurrentMeetingQuestionResponse.questionNotRegisteredOf(activeMeetingQuestion);
} else {
MeetingMember nextTargetMember = meetingQuestionRepository.findFirstByStatusAndStartTimeAfterOrderByStartTime(
NOT_STARTED,
LocalDateTime.now())
.map(MeetingQuestion::getTargetMember)
.orElse(null);

return CurrentMeetingQuestionResponse.questionRegisteredOf(activeMeetingQuestion,
nextTargetMember,
meetingQuestionRepository.isAnswered(activeMeetingQuestion.getId(), meetingMember.getId()));
}
}

private void validateNonDuplicateQuestion(Long meetingId, Long questionId) {
boolean isDuplicateQuestion = meetingQuestionRepository.existsByQuestion(meetingId, questionId);
if (isDuplicateQuestion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface MeetingQuestionJpaRepository extends JpaRepository<MeetingQuest
Optional<MeetingQuestion> findFirstByMeetingIdAndStatusOrderByStartTime(Long meetingId,
MeetingQuestionStatus status);

Optional<MeetingQuestion> findFirstByStatusAndStartTimeAfterOrderByStartTime(MeetingQuestionStatus status, LocalDateTime now);

Optional<MeetingQuestion> findFirstByMeetingIdAndStatusAndQuestionIsNotNullOrderByStartTime(Long meetingId,
MeetingQuestionStatus status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public Optional<MeetingQuestion> findByMeetingIdAndMeetingQuestionId(Long meetin
return meetingQuestionJpaRepository.findByMeetingIdAndId(meetingId, meetingQuestionId);
}

@Override
public Optional<MeetingQuestion> findFirstByStatusAndStartTimeAfterOrderByStartTime(MeetingQuestionStatus status,
LocalDateTime now) {
return meetingQuestionJpaRepository.findFirstByStatusAndStartTimeAfterOrderByStartTime(status, now);
}

@Override
public List<MeetingQuestionStatisticsDetail> findStatistics(Long meetingQuestionId) {
return meetingQuestionQueryRepository.findStatistics(meetingQuestionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import org.depromeet.sambad.moring.file.presentation.annotation.FullFileUrl;
import org.depromeet.sambad.moring.meeting.meeting.domain.Meeting;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberListResponseDetail;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMember;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberSummaryResponse;
import org.depromeet.sambad.moring.meeting.question.domain.MeetingQuestion;

import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -45,7 +46,10 @@ public record CurrentMeetingQuestionResponse(
Boolean isQuestionRegistered,

@Schema(description = "질문인에 대한 정보", requiredMode = REQUIRED)
MeetingMemberListResponseDetail targetMember
MeetingMemberSummaryResponse targetMember,

@Schema(description = "다음 질문인에 대한 정보", requiredMode = NOT_REQUIRED)
MeetingMemberSummaryResponse nextTargetMember
) {

public static CurrentMeetingQuestionResponse questionNotRegisteredOf(MeetingQuestion meetingQuestion) {
Expand All @@ -60,12 +64,12 @@ public static CurrentMeetingQuestionResponse questionNotRegisteredOf(MeetingQues
.startTime(meetingQuestion.getEpochMilliStartTime())
.isAnswered(false)
.isQuestionRegistered(false)
.targetMember(MeetingMemberListResponseDetail.from(meetingQuestion.getTargetMember()))
.targetMember(MeetingMemberSummaryResponse.from(meetingQuestion.getTargetMember()))
.build();
}

public static CurrentMeetingQuestionResponse questionRegisteredOf(MeetingQuestion meetingQuestion,
Boolean isAnswered) {
MeetingMember nextTargetMember, Boolean isAnswered) {
Meeting meeting = meetingQuestion.getMeeting();

return CurrentMeetingQuestionResponse.builder()
Expand All @@ -79,7 +83,8 @@ public static CurrentMeetingQuestionResponse questionRegisteredOf(MeetingQuestio
.startTime(meetingQuestion.getEpochMilliStartTime())
.isAnswered(isAnswered)
.isQuestionRegistered(true)
.targetMember(MeetingMemberListResponseDetail.from(meetingQuestion.getTargetMember()))
.targetMember(MeetingMemberSummaryResponse.from(meetingQuestion.getTargetMember()))
.nextTargetMember(MeetingMemberSummaryResponse.from(nextTargetMember))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import org.depromeet.sambad.moring.file.presentation.annotation.FullFileUrl;
import org.depromeet.sambad.moring.meeting.meeting.domain.Meeting;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberListResponseDetail;
import org.depromeet.sambad.moring.meeting.member.presentation.response.MeetingMemberSummaryResponse;
import org.depromeet.sambad.moring.meeting.question.domain.MeetingQuestion;

import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -32,7 +32,7 @@ public record FullInactiveMeetingQuestionListResponseDetail(
Long startTime,

@Schema(description = "질문 대상자에 대한 정보", requiredMode = REQUIRED)
MeetingMemberListResponseDetail targetMember
MeetingMemberSummaryResponse targetMember
) {

public static FullInactiveMeetingQuestionListResponseDetail from(MeetingQuestion meetingQuestion) {
Expand All @@ -45,7 +45,7 @@ public static FullInactiveMeetingQuestionListResponseDetail from(MeetingQuestion
.title(meetingQuestion.getTitle())
.questionNumber(questionNumber)
.startTime(meetingQuestion.getEpochMilliStartTime())
.targetMember(MeetingMemberListResponseDetail.from(meetingQuestion.getTargetMember()))
.targetMember(MeetingMemberSummaryResponse.from(meetingQuestion.getTargetMember()))
.build();
}

Expand Down

0 comments on commit a83bc48

Please sign in to comment.