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 @@ -44,8 +44,4 @@ public List<Mission> getValidMissionsWithStamp(List<Long> missionIds) {

return missions;
}

public long countCompletedMissionsByTripId(Long tripId) {
return missionQueryRepository.countCompletedMissionsByTripId(tripId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ public interface MissionQueryRepository {
long deleteAllByDeletedAtIsNotNull();

long deleteAllByDeletedStampOwner();

long countCompletedMissionsByTripId(Long tripId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.ject.studytrip.mission.domain.model.QMission;
import com.ject.studytrip.mission.domain.repository.MissionQueryRepository;
import com.ject.studytrip.stamp.domain.model.QStamp;
import com.ject.studytrip.trip.domain.model.QTrip;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
Expand All @@ -17,7 +16,6 @@ public class MissionQueryRepositoryAdapter implements MissionQueryRepository {
private final JPAQueryFactory queryFactory;
private final QMission mission = QMission.mission;
private final QStamp stamp = QStamp.stamp;
private final QTrip trip = QTrip.trip;

@Override
public List<Mission> findAllByIdsInFetchJoinStamp(List<Long> ids) {
Expand Down Expand Up @@ -60,50 +58,4 @@ public long deleteAllByDeletedStampOwner() {
.where(stamp.deletedAt.isNotNull())))
.execute();
}

@Override
public long countCompletedMissionsByTripId(Long tripId) {
Long count =
queryFactory
.select(mission.id.count())
.from(mission)
.join(mission.stamp, stamp)
.join(stamp.trip, trip)
.where(
trip.id.eq(tripId),
mission.completed.isTrue(),
mission.deletedAt.isNull(),
stamp.deletedAt.isNull(),
trip.deletedAt.isNull())
.fetchOne();

return count != null ? count : 0L;
}

// @Override
// public long countByStampIdAndDeletedAtIsNull(Long stampId) {
// Long count =
// queryFactory
// .select(mission.count())
// .from(mission)
// .where(mission.stamp.id.eq(stampId), mission.deletedAt.isNull())
// .fetchOne();
//
// return Optional.ofNullable(count).orElse(0L);
// }
//
// @Override
// public long countByStampIdAndCompletedIsTrueAndDeletedAtIsNull(Long stampId) {
// Long count =
// queryFactory
// .select(mission.count())
// .from(mission)
// .where(
// mission.stamp.id.eq(stampId),
// mission.completed.isTrue(),
// mission.deletedAt.isNull())
// .fetchOne();
//
// return Optional.ofNullable(count).orElse(0L);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public List<StudyLog> getValidStudyLogs(List<Long> studyLogIds) {
return studyLogs;
}

public long getStudyLogCountByTripId(Long tripId) {
return studyLogQueryRepository.countStudyLogsByTripId(tripId);
}

public Slice<StudyLog> getStudyLogsSliceByTripReportId(Long tripReportId, int page, int size) {
return studyLogQueryRepository.findSliceByTripReportIdOrderByCreatedAtDesc(
tripReportId, PageRequest.of(page, size));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface StudyLogQueryRepository {

long deleteAllByDeletedDailyGoalOwner();

long countStudyLogsByTripId(Long tripId);

Slice<StudyLog> findSliceByTripReportIdOrderByCreatedAtDesc(
Long tripReportId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ public long deleteAllByDeletedDailyGoalOwner() {
.execute();
}

@Override
public long countStudyLogsByTripId(Long tripId) {
Long count =
queryFactory
.select(studyLog.count())
.from(studyLog)
.join(studyLog.dailyGoal, dailyGoal)
.where(
dailyGoal.trip.id.eq(tripId),
studyLog.deletedAt.isNull(),
dailyGoal.deletedAt.isNull())
.fetchOne();

return count == null ? 0L : count;
}

@Override
public Slice<StudyLog> findSliceByTripReportIdOrderByCreatedAtDesc(
Long tripReportId, Pageable pageable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public record TripReportInfo(
String content,
String startDate,
String endDate,
long completedMissionCount,
long studyLogCount,
long totalFocusHours,
long studyDays,
String imageTitle,
Expand All @@ -24,7 +24,7 @@ public static TripReportInfo from(TripReport tripReport) {
tripReport.getContent(),
tripReport.getStartDate(),
tripReport.getEndDate(),
tripReport.getCompletedMissionCount(),
tripReport.getStudyLogCount(),
tripReport.getTotalFocusHours(),
tripReport.getStudyDays(),
tripReport.getImageTitle(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.ject.studytrip.trip.application.dto;

public record TripRetrospectSummary(
long completedMissionCount, // 완료 미션 수
long studyLogCount, // 학습 로그 개수
long totalFocusHours, // 총 집중 시간(시간 단위)
long studyDays // 학습한 일수(중복 날짜 제거)
) {
public static TripRetrospectSummary of(
long completedMissionCount, long totalFocusHours, long studyDays) {
return new TripRetrospectSummary(completedMissionCount, totalFocusHours, studyDays);
long studyLogCount, long totalFocusHours, long studyDays) {
return new TripRetrospectSummary(studyLogCount, totalFocusHours, studyDays);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.ject.studytrip.image.application.service.ImageService;
import com.ject.studytrip.member.application.service.MemberQueryService;
import com.ject.studytrip.member.domain.model.Member;
import com.ject.studytrip.mission.application.service.MissionQueryService;
import com.ject.studytrip.pomodoro.application.service.PomodoroQueryService;
import com.ject.studytrip.studylog.application.dto.StudyLogDetail;
import com.ject.studytrip.studylog.application.dto.StudyLogSliceInfo;
Expand Down Expand Up @@ -37,7 +36,6 @@ public class TripReportFacade {

private final MemberQueryService memberQueryService;
private final TripQueryService tripQueryService;
private final MissionQueryService missionQueryService;
private final StudyLogQueryService studyLogQueryService;
private final StudyLogDailyMissionQueryService studyLogDailyMissionQueryService;
private final PomodoroQueryService pomodoroQueryService;
Expand All @@ -55,8 +53,7 @@ public TripRetrospectDetail getTripRetrospect(Long memberId, Long tripId, int pa
Slice<StudyLog> studyLogSlice =
studyLogQueryService.getStudyLogsSliceByTripId(trip.getId(), page, size);

long completedMissionCount =
missionQueryService.countCompletedMissionsByTripId(trip.getId());
long studyLogCount = studyLogQueryService.getStudyLogCountByTripId(trip.getId());
long totalFocusHours = pomodoroQueryService.getTotalFocusHoursByTripId(trip.getId());
long studyDays =
trip.getEndDate() != null
Expand All @@ -66,7 +63,7 @@ public TripRetrospectDetail getTripRetrospect(Long memberId, Long tripId, int pa
: 0L;

TripRetrospectSummary summary =
TripRetrospectSummary.of(completedMissionCount, totalFocusHours, studyDays);
TripRetrospectSummary.of(studyLogCount, totalFocusHours, studyDays);
TripInfo tripInfo = TripInfo.from(trip, 0, 100);
StudyLogSliceInfo studyLogDetailSlice = buildStudyLogDetailsSlice(studyLogSlice);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TripReport createTripReport(Member member, CreateTripReportRequest reques
request.content(),
request.startDate(),
request.endDate(),
request.completedMissionCount(),
request.studyLogCount(),
request.totalFocusHours(),
request.studyDays(),
request.imageTitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static TripReport create(
String content,
String startDate,
String endDate,
long completedMissionCount,
long studyLogCount,
long totalFocusHours,
long studyDays,
String imageTitle) {
Expand All @@ -23,7 +23,7 @@ public static TripReport create(
content,
startDate,
endDate,
completedMissionCount,
studyLogCount,
totalFocusHours,
studyDays,
imageTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class TripReport extends BaseTimeEntity {
private String endDate;

@Column(nullable = false)
private long completedMissionCount;
private long studyLogCount;

@Column(nullable = false)
private long totalFocusHours;
Expand All @@ -51,7 +51,7 @@ public static TripReport of(
String content,
String startDate,
String endDate,
long completedMissionCount,
long studyLogCount,
long totalFocusHours,
long studyDays,
String imageTitle) {
Expand All @@ -60,7 +60,7 @@ public static TripReport of(
.content(content)
.startDate(startDate)
.endDate(endDate)
.completedMissionCount(completedMissionCount)
.studyLogCount(studyLogCount)
.totalFocusHours(totalFocusHours)
.studyDays(studyDays)
.imageTitle(imageTitle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public ResponseEntity<StandardResponse> presigned(
@RequestBody @Valid PresignTripReportImageRequest request) {
PresignedTripReportImageInfo info =
tripReportFacade.issuePresignedUrl(tripReportId, request);

return ResponseEntity.ok()
.body(
StandardResponse.success(
Expand Down Expand Up @@ -165,6 +166,7 @@ public ResponseEntity<StandardResponse> confirm(
@PathVariable @NotNull(message = "여행 리포트 ID는 필수 요청 파라미터입니다.") Long tripReportId,
@RequestBody @Valid ConfirmTripReportImageRequest request) {
tripReportFacade.confirmImage(tripReportId, request);

return ResponseEntity.ok().body(StandardResponse.success(HttpStatus.OK.value(), null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public record CreateTripReportRequest(
String content,
@Schema(description = "여행 시작일") @NotEmpty(message = "여행 시작일은 필수 요청 값입니다.") String startDate,
@Schema(description = "여행 종료일") String endDate,
@Schema(description = "완료된 미션 수 (세션 성공)") @NotNull(message = "완료된 미션 수는 필수 요청 값입니다.")
long completedMissionCount,
@Schema(description = "학습 로그 개수 (세션 성공)") @NotNull(message = "학습 로그 개수는 필수 요청 값입니다.")
long studyLogCount,
@Schema(description = "총 학습 시간") @NotNull(message = "총 학습 시간은 필수 요청 값입니다.")
long totalFocusHours,
@Schema(description = "연속 학습일") @NotNull(message = "연속 학습일은 필수 요청 값입니다.") long studyDays,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record LoadTripReportDetailResponse(
@Schema(description = "여행 시작일 (여행 회고)") String startDate,
@Schema(description = "여행 종료일 (여행 회고)") String endDate,
@Schema(description = "총 학습 시간") long totalFocusHours,
@Schema(description = "완료된 미션 수 (세션 성공)") long completedMissionCount,
@Schema(description = "학습 로그 개수 (세션 성공)") long studyLogCount,
@Schema(description = "연속 학습일") long studyDays,
@Schema(description = "여행 리포트 이미지 제목") String imageTitle,
@Schema(description = "여행 리포트 이미지 URL") String imageUrl,
Expand All @@ -26,7 +26,7 @@ public static LoadTripReportDetailResponse of(
tripReportInfo.startDate(),
tripReportInfo.endDate(),
tripReportInfo.totalFocusHours(),
tripReportInfo.completedMissionCount(),
tripReportInfo.studyLogCount(),
tripReportInfo.studyDays(),
tripReportInfo.imageTitle(),
tripReportInfo.imageUrl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record LoadTripRetrospectDetailResponse(
@Schema(description = "여행 시작일") String startDate,
@Schema(description = "여행 종료일") String endDate,
@Schema(description = "총 학습 시간") long totalFocusHours,
@Schema(description = "완료된 미션 수 (세션 성공)") long completedMissionCount,
@Schema(description = "학습 로그 개수 (세션 성공)") long studyLogCount,
@Schema(description = "연속 학습일") long studyDays,
@Schema(description = "학습 로그 히스토리") LoadStudyLogsSliceResponse history) {
public static LoadTripRetrospectDetailResponse of(
Expand All @@ -23,7 +23,7 @@ public static LoadTripRetrospectDetailResponse of(
tripInfo.startDate(),
tripInfo.endDate(),
tripRetrospectSummary.totalFocusHours(),
tripRetrospectSummary.completedMissionCount(),
tripRetrospectSummary.studyLogCount(),
tripRetrospectSummary.studyDays(),
LoadStudyLogsSliceResponse.of(
studyLogDetailSlice.studyLogDetails(), studyLogDetailSlice.hasNext()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE trip_report
CHANGE COLUMN completed_mission_count study_log_count BIGINT NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class MissionQueryServiceTest extends BaseUnitTest {
@Mock private MissionRepository missionRepository;
@Mock private MissionQueryRepository missionQueryRepository;

private Trip exploreTrip;
private Stamp courseStamp;
private Stamp exploreStamp;
private Mission courseMission;
Expand All @@ -45,7 +44,7 @@ class MissionQueryServiceTest extends BaseUnitTest {
void setUp() {
Member member = MemberFixture.createMemberFromKakao();
Trip courseTrip = TripFixture.createTripWithId(1L, member, TripCategory.COURSE);
exploreTrip = TripFixture.createTripWithId(2L, member, TripCategory.EXPLORE);
Trip exploreTrip = TripFixture.createTripWithId(2L, member, TripCategory.EXPLORE);
courseStamp = StampFixture.createStampWithId(1L, courseTrip, 1);
exploreStamp = StampFixture.createStampWithId(2L, exploreTrip, 0);
courseMission = MissionFixture.createMissionWithId(1L, courseStamp);
Expand Down Expand Up @@ -198,40 +197,4 @@ void shouldReturnValidMissions() {
assertThat(result).containsExactly(courseMission);
}
}

@Nested
@DisplayName("countCompletedMissionsByTripId 메서드는")
class CountCompletedMissionsByTripId {

@Test
@DisplayName("유효하지 않은 여행 ID가 들어오면 0을 반환한다.")
void shouldReturnZeroWhenTripIdIsInvalid() {
// given
Long invalidTripId = -1L;
given(missionQueryRepository.countCompletedMissionsByTripId(invalidTripId))
.willReturn(0L);

// when
long result = missionQueryService.countCompletedMissionsByTripId(invalidTripId);

// then
assertThat(result).isEqualTo(0L);
}

@Test
@DisplayName("유효한 여행 ID가 들어오면 완료된 미션들의 개수를 반환한다.")
void shouldReturnCompletedMissionCountWhenTripIdIsValid() {
// given
Long tripId = exploreTrip.getId();
exploreMission1.updateCompleted();
exploreMission2.updateCompleted();
given(missionQueryRepository.countCompletedMissionsByTripId(tripId)).willReturn(2L);

// when
long result = missionQueryService.countCompletedMissionsByTripId(tripId);

// then
assertThat(result).isEqualTo(2L);
}
}
}
Loading