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 @@ -13,6 +13,7 @@
import org.runimo.runimo.records.controller.request.RecordSaveRequest;
import org.runimo.runimo.records.controller.request.RecordUpdateRequest;
import org.runimo.runimo.records.enums.RecordHttpResponse;
import org.runimo.runimo.records.service.dto.RecordSimpleViewResponse;
import org.runimo.runimo.records.service.dto.WeeklyRecordStatResponse;
import org.runimo.runimo.records.service.dto.WeeklyStatQuery;
import org.runimo.runimo.records.service.usecases.RecordCreateUsecase;
Expand Down Expand Up @@ -137,4 +138,21 @@ public ResponseEntity<SuccessResponse<MonthlyRecordStatResponse>> queryMonthlyRe
return ResponseEntity.ok(
SuccessResponse.of(UserHttpResponseCode.MY_PAGE_DATA_FETCHED, response));
}

@Operation(summary = "개인 기록 페이지네이션 전체 조회", description = "개인 기록 페이지네이션 조회")
@ApiResponse(responseCode = "200", description = "기록 조회 성공",
content = @Content(schema = @Schema(implementation = RecordSimpleViewResponse.class)))
@GetMapping("/me")
public ResponseEntity<SuccessResponse<RecordSimpleViewResponse>> getMyRecordList(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
@UserId Long userId
) {
return ResponseEntity.ok(
SuccessResponse.of(
RecordHttpResponse.RECORD_FETCHED,
recordQueryUsecase.getUserRecordSimpleView(userId, page, size)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ Slice<RunningRecord> findFirstRunOfWeek(
List<DailyStat> findDailyDistanceByUserIdAndThisWeek(Long userId, LocalDateTime startOfWeek,
LocalDateTime now);

List<RunningRecord> findRecordByUserIdOrderByStartedAtDesc(Long id, Pageable pageable);
}
12 changes: 12 additions & 0 deletions src/main/java/org/runimo/runimo/records/service/RecordFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import org.runimo.runimo.records.domain.RunningRecord;
import org.runimo.runimo.records.repository.RecordRepository;
import org.runimo.runimo.records.service.dto.DailyStat;
import org.runimo.runimo.records.service.dto.RecordSimpleView;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -54,4 +56,14 @@ public List<DailyStat> findDailyStatByUserIdBetween(Long id, LocalDateTime from,
LocalDateTime to) {
return recordRepository.findDailyDistanceByUserIdAndThisWeek(id, from, to);
}

@Transactional(readOnly = true)
public List<RecordSimpleView> findRecordSimpleViewByUserId(Long id, int page, int size) {
Pageable pageable = PageRequest.of(page, size);
return recordRepository
.findRecordByUserIdOrderByStartedAtDesc(id, pageable)
.stream()
.map(RecordSimpleView::from)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.runimo.runimo.records.service.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.runimo.runimo.records.domain.RunningRecord;

@Schema(description = "기록 요약 정보")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RecordSimpleView {
@Schema(description = "기록 ID", example = "UUID-String")
private String id;
private String title;
private LocalDateTime startDateTime;
private Long distanceInMeters;
private Long durationInSeconds;
private Long averagePaceInMiliseconds;

@Builder
private RecordSimpleView(String id, String title, LocalDateTime startDateTime,
Long distanceInMeters,
Long durationInSeconds, Long averagePaceInMiliseconds) {
this.id = id;
this.title = title;
this.startDateTime = startDateTime;
this.distanceInMeters = distanceInMeters;
this.durationInSeconds = durationInSeconds;
this.averagePaceInMiliseconds = averagePaceInMiliseconds;
}

public static RecordSimpleView from(RunningRecord runningRecord) {
return RecordSimpleView.builder()
.id(runningRecord.getRecordPublicId())
.title(runningRecord.getTitle())
.startDateTime(runningRecord.getStartedAt())
.distanceInMeters(runningRecord.getTotalDistance().getAmount())
.durationInSeconds(runningRecord.getRunningTime().getSeconds())
.averagePaceInMiliseconds(runningRecord.getAveragePace().getPaceInMilliSeconds())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.runimo.runimo.records.service.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;

@Schema(description = "기록 요약 정보 응답 DTO")
public record RecordSimpleViewResponse(List<RecordSimpleView> recordList) {

}
Comment thread
ekgns33 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.runimo.runimo.records.service.usecases;

import org.runimo.runimo.records.service.dto.RecordSimpleViewResponse;
import org.runimo.runimo.records.service.dto.WeeklyRecordStatResponse;
import org.runimo.runimo.records.service.dto.WeeklyStatQuery;
import org.runimo.runimo.records.service.usecases.dtos.MonthlyRecordStatResponse;
Expand All @@ -13,4 +14,6 @@ public interface RecordQueryUsecase {
WeeklyRecordStatResponse getUserWeeklyRecordStat(WeeklyStatQuery query);

MonthlyRecordStatResponse getUserMonthlyRecordStat(MonthlyStatQuery query);

RecordSimpleViewResponse getUserRecordSimpleView(Long id, int page, int size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.runimo.runimo.records.domain.RunningRecord;
import org.runimo.runimo.records.service.RecordFinder;
import org.runimo.runimo.records.service.dto.DailyStat;
import org.runimo.runimo.records.service.dto.RecordSimpleView;
import org.runimo.runimo.records.service.dto.RecordSimpleViewResponse;
import org.runimo.runimo.records.service.dto.WeeklyRecordStatResponse;
import org.runimo.runimo.records.service.dto.WeeklyStatQuery;
import org.runimo.runimo.records.service.usecases.dtos.MonthlyRecordStatResponse;
Expand Down Expand Up @@ -50,4 +52,11 @@ public MonthlyRecordStatResponse getUserMonthlyRecordStat(MonthlyStatQuery query
);
return new MonthlyRecordStatResponse(dailyDistances);
}

@Override
public RecordSimpleViewResponse getUserRecordSimpleView(Long id, int page, int size) {
List<RecordSimpleView> recordSimpleViews = recordFinder.findRecordSimpleViewByUserId(id,
page, size);
return new RecordSimpleViewResponse(recordSimpleViews);
}
Comment thread
ekgns33 marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
Expand Down Expand Up @@ -261,5 +262,24 @@ void tearDown() {
.log().all()
.statusCode(401);
}

@Test
@Sql(scripts = "/sql/weekly_record_data.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
void 사용자_기록_페이지네이션_조회() {

String token = AUTH_HEADER_PREFIX + jwtTokenFactory.generateAccessToken(USER_UUID);

given()
.contentType(ContentType.JSON)
.header("Authorization", token)
.param("page", 0)
.param("size", 5)
.when()
.get("/api/v1/records/me")
.then()
.log().all()
.statusCode(HttpStatus.OK.value())
.body("payload.record_list.size()", equalTo(5));
}
}