Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SAMBAD-242] 질문 답변 활성화 및 비활성화 플로우 이슈 픽스 #94

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -164,7 +164,7 @@ 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() {
Expand All @@ -175,11 +175,7 @@ private BooleanExpression activeCond() {
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());
.or(meetingQuestion.meetingQuestionStatus.eq(INACTIVE));
}

public List<MeetingQuestionStatisticsDetail> findStatistics(Long meetingQuestionId) {
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
Loading