Skip to content

Commit

Permalink
[SAMBAD-242] 질문 답변 활성화 및 비활성화 플로우 이슈 픽스
Browse files Browse the repository at this point in the history
  • Loading branch information
kkjsw17 committed Aug 12, 2024
1 parent a407525 commit 1154e88
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ public String upload(String fileUrl) throws ObjectStorageServerException {
try {
String filePath = generateUploadPath(fileUrl);
HttpURLConnection conn = getHttpURLConnection(fileUrl);
String contentType = conn.getHeaderField(CONTENT_TYPE);

try (InputStream in = conn.getInputStream()) {
amazonS3.putObject(bucketName, filePath, in, setObjectMetaData(in, contentType));
amazonS3.putObject(bucketName, filePath, in, setObjectMetaData(conn));
}

return filePath;
Expand Down Expand Up @@ -120,10 +119,13 @@ private HttpURLConnection getHttpURLConnection(String fileUrl) throws IOExceptio
return conn;
}

private ObjectMetadata setObjectMetaData(InputStream in, String contentType) throws IOException {
private ObjectMetadata setObjectMetaData(HttpURLConnection conn) throws IOException {
ObjectMetadata objectMetadata = new ObjectMetadata();

objectMetadata.setContentLength(in.available());
String contentType = conn.getHeaderField(CONTENT_TYPE);
long contentLength = Long.parseLong(conn.getHeaderField(CONTENT_LENGTH));

objectMetadata.setContentLength(contentLength);
objectMetadata.setContentType(contentType);
return objectMetadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ public class MeetingAnswerQueryRepository {
private final JPAQueryFactory queryFactory;

public boolean isAllAnsweredByMeetingIdAndMeetingQuestionId(Long meetingId, Long meetingQuestionId) {
return queryFactory.select(meetingAnswer.count())
Long answeredMeetingMemberCount = queryFactory.select(meetingAnswer.meetingMember.countDistinct())
.from(meetingAnswer)
.where(meetingAnswer.meetingQuestion.id.eq(meetingQuestionId))
.fetchOne()
.equals(queryFactory.select(meetingMember.count())
.from(meetingMember)
.where(meetingMember.meeting.id.eq(meetingId))
.fetchOne());
.groupBy(meetingAnswer.meetingQuestion.id)
.fetchOne();

Long allMemberCount = queryFactory.select(meetingMember.count())
.from(meetingMember)
.where(meetingMember.meeting.id.eq(meetingId))
.fetchOne();

return Objects.equals(answeredMeetingMemberCount, allMemberCount);
}

// TODO: 가장 많이 선택된 답변이 여러개일 수 있으나, 현재 로직은 하나만 반환. 추후 기획에 따라 수정 필요.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record MeetingQuestionCommentRequest(

@Schema(description = "릴레이 질문 코멘트 내용", example = "코멘트 예시")
@NotBlank
@Size(max = 10)
@Size(max = 20)
String content
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDateTime;
import java.util.List;

import org.depromeet.sambad.moring.event.application.EventService;
import org.depromeet.sambad.moring.meeting.meeting.application.MeetingRepository;
import org.depromeet.sambad.moring.meeting.meeting.domain.Meeting;
import org.depromeet.sambad.moring.meeting.meeting.domain.MeetingCode;
Expand All @@ -27,6 +28,9 @@

import lombok.RequiredArgsConstructor;

import static org.depromeet.sambad.moring.event.domain.EventType.QUESTION_REGISTERED;
import static org.depromeet.sambad.moring.event.domain.EventType.TARGET_MEMBER;

@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
Expand All @@ -40,6 +44,7 @@ public class MeetingMemberService {
private final HobbyRepository hobbyRepository;
private final MeetingQuestionRepository meetingQuestionRepository;
private final MeetingMemberHobbyRepository meetingMemberHobbyRepository;
private final EventService eventService;

public MeetingMemberListResponse getMeetingMembers(Long userId, Long meetingId) {
meetingMemberValidator.validateUserIsMemberOfMeeting(userId, meetingId);
Expand Down Expand Up @@ -92,11 +97,14 @@ public MeetingMemberPersistResponse registerMeetingMember(
}

private void createMeetingQuestionIfFirstMeetingMember(Meeting meeting, MeetingMember meetingMember) {
if (meetingMemberRepository.isCountOfMembersIsOne(meeting.getId())) {
Long meetingId = meeting.getId();

if (meetingMemberRepository.isCountOfMembersIsOne(meetingId)) {
MeetingQuestion activeMeetingQuestion = MeetingQuestion.createActiveMeetingQuestion(
meeting, meetingMember, null, LocalDateTime.now());

meetingQuestionRepository.save(activeMeetingQuestion);
eventService.publish(meetingMember.getUser().getId(), meetingId, TARGET_MEMBER);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ public void updateStatusToActive(LocalDateTime now) {
}

public int getResponseCount() {
return this.memberAnswers.size();
return this.memberAnswers.stream()
.map(MeetingAnswer::getMeetingMember)
.map(MeetingMember::getId)
.distinct()
.toList().size();
}

public String getQuestionImageUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public MostInactiveMeetingQuestionListResponse findMostInactiveList(Long meeting
.where(
meetingQuestion.meeting.id.eq(meetingId),
meetingQuestion.question.isNotNull(),
inactiveCond()
meetingQuestion.meetingQuestionStatus.eq(INACTIVE)
)
.orderBy(orderDescByMeetingAnswerCount(), meetingQuestion.startTime.desc())
.limit(2)
Expand All @@ -113,7 +113,7 @@ public FullInactiveMeetingQuestionListResponse findFullInactiveList(Long meeting
.where(
meetingQuestion.meeting.id.eq(meetingId),
meetingQuestion.question.isNotNull(),
inactiveCond()
meetingQuestion.meetingQuestionStatus.eq(INACTIVE)
)
.orderBy(orderDescByMeetingAnswerCount(), meetingQuestion.startTime.desc())
.offset(pageable.getOffset())
Expand Down Expand Up @@ -164,24 +164,14 @@ private BooleanExpression registeredCond() {
LocalDateTime now = LocalDateTime.now();
return meetingQuestion.startTime.loe(now)
.and(meetingQuestion.startTime.goe(now.minusHours(RESPONSE_TIME_LIMIT_HOURS)))
.and(isAnsweredByAllCond().not());
.and(meetingQuestion.meetingQuestionStatus.eq(ACTIVE));
}

private BooleanExpression activeCond() {
return registeredCond()
.and(meetingQuestion.question.isNotNull());
}

private BooleanExpression inactiveCond() {
LocalDateTime now = LocalDateTime.now();
return meetingQuestion.startTime.lt(now.minusHours(RESPONSE_TIME_LIMIT_HOURS))
.or(isAnsweredByAllCond());
}

private BooleanExpression isAnsweredByAllCond() {
return meetingQuestion.memberAnswers.size().eq(meetingQuestion.meeting.meetingMembers.size());
}

public List<MeetingQuestionStatisticsDetail> findStatistics(Long meetingQuestionId) {
// Get total count for the percentage calculation
Optional<Long> optionalTotalCount = Optional.ofNullable(queryFactory
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spring:
application:
name: moring-api
datasource:
url: jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:moring}?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
url: jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:moring}?useSSL=false&allowPublicKeyRetrieval=true
username: ${DB_USERNAME:root}
password: ${DB_PASSWORD:root}
driver-class-name: com.mysql.cj.jdbc.Driver
Expand Down

0 comments on commit 1154e88

Please sign in to comment.