Skip to content
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 @@ -20,6 +20,6 @@ public interface CustomStudyRepository {

List<ProblemInfoDto> searchSolvedProblemInfo(LocalDate date, String memberId);

List<RecentActivityInfoDto> searchTodayActivityInfo(String studyId);
List<RecentActivityInfoDto> searchActivityInfo(String studyId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.sql.Date;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.List;

Expand Down Expand Up @@ -149,12 +150,39 @@ public List<ProblemInfoDto> searchSolvedProblemInfo(LocalDate date, String membe
)
.fetch();
}

@Override
public List<RecentActivityInfoDto> searchTodayActivityInfo(String studyId) {
Timestamp startOfToday = Timestamp.valueOf(LocalDate.now().atStartOfDay());
public List<RecentActivityInfoDto> searchActivityInfo(String studyId) {
LocalDateTime todayMidnight = LocalDate.now().atStartOfDay();

return query
//1. 최근 활동 20개 조회 (금일 활동인지 여부 상관없이)
List<RecentActivityInfoDto> recentActivities = query
.select(new QRecentActivityInfoDto(
memberEntity.memberId,
memberEntity.name,
problemEntity.problemId,
problemEntity.problemTitle,
codeEntity.codeSolvedDate
))
.from(codeEntity)
.join(codeEntity.problemEntity, problemEntity)
.join(codeEntity.memberEntity, memberEntity)
.where(
memberEntity.studyEntity.studyId.eq(studyId),
codeEntity.codeStatus.isTrue()
)
.orderBy(codeEntity.codeSolvedDate.desc())
.limit(20)
.fetch();

//2. 조회한 값 중 마지막 활동이 금일 자정 전에 이뤄졌다면 그대로 반환
RecentActivityInfoDto oldestActivity = recentActivities.get(recentActivities.size() - 1);
if (oldestActivity.getSolvedAt().isBefore(todayMidnight)) {
return recentActivities;
}

//3. 아니라면 추가 쿼리 실행 (금일 활동이 더 있을 수 있으므로)
List<RecentActivityInfoDto> additionalActivities = query
.select(new QRecentActivityInfoDto(
memberEntity.memberId,
memberEntity.name,
Expand All @@ -168,10 +196,14 @@ public List<RecentActivityInfoDto> searchTodayActivityInfo(String studyId) {
.where(
memberEntity.studyEntity.studyId.eq(studyId),
codeEntity.codeStatus.isTrue(),
codeEntity.codeSolvedDate.goe(startOfToday)
codeEntity.codeSolvedDate.goe(Timestamp.valueOf(todayMidnight))
)
.orderBy(codeEntity.codeSolvedDate.desc())
.offset(recentActivities.size())
.fetch();

recentActivities.addAll(additionalActivities);
return recentActivities;
}

private BooleanExpression solvedAt(YearMonth yearMonth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,14 @@ public LogResDto getLog(String memberId, String studyId) {
checkValidMemberAndStudy(memberId, studyId);

//2. 해당 스터디의 최근 활동 정보 조회
List<RecentActivityInfoDto> repoDto = studyRepository.searchTodayActivityInfo(studyId);
return LogResDto.fromRepoDto(repoDto, LocalDateTime.now());
List<RecentActivityInfoDto> repoDto = studyRepository.searchActivityInfo(studyId);
for (RecentActivityInfoDto aDto : repoDto) {
log.info("{}-{}: solved at={}", aDto.getMemberName(), aDto.getProblemTitle(), aDto.getSolvedAt());
}

LocalDateTime now = LocalDateTime.now();
log.info("now={}");
return LogResDto.fromRepoDto(repoDto, now);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static java.time.temporal.ChronoUnit.HOURS;
import static java.time.temporal.ChronoUnit.MINUTES;
import static java.time.temporal.ChronoUnit.MONTHS;
import static java.time.temporal.ChronoUnit.SECONDS;
import static java.time.temporal.ChronoUnit.YEARS;

public class DashBoardUtils {
Expand Down Expand Up @@ -37,7 +38,7 @@ public static String getSolvedBefore(LocalDateTime solvedAt, LocalDateTime now)
if ((duration = MINUTES.between(solvedAt, now)) != 0L) {
return duration + MINUTE_SUFFIX;
}
return duration + SECOND_SUFFIX;
return SECONDS.between(solvedAt, now) + SECOND_SUFFIX;
}

public static Integer getLevel(String levelString) {
Expand Down