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 @@ -14,20 +14,33 @@
@Setter
public class MyRecordPageRequest {

@Parameter(description = "페이지 번호", example = "0")
@Min(0)
private Integer page = 0;
@Parameter(description = "페이지 당 크기", example = "10")
@Min(1)
@Max(20)
private Integer size = 10;
@Parameter(description = "시작 날짜(기본값 : 요청 시점)", example = "2024-04-04")
private LocalDate startDate = LocalDate.now();
@Parameter(description = "종료 날짜(기본값 : 요청 시점)", example = "2024-04-04")
private LocalDate endDate = LocalDate.now();
@Parameter(description = "페이지 번호", example = "0")
@Min(0)
private Integer page = 0;
@Parameter(description = "페이지 당 크기", example = "10")
@Min(1)
@Max(20)
private Integer size = 10;
@Parameter(description = "시작 날짜(기본값 : 요청 시점)", example = "2024-04-04")
private LocalDate startDate = LocalDate.now();
@Parameter(description = "종료 날짜(기본값 : 요청 시점)", example = "2024-04-04")
private LocalDate endDate = LocalDate.now();
@Parameter(description = "정렬 기준", example = "createdAt")
@Schema(allowableValues = {"startedAt", "createdAt"})
private String sortBy = "startedAt";
@Parameter(description = "정렬 방향", example = "asc")
@Schema(allowableValues = {"asc", "desc"})
private String sortDirection = "desc";

public static RecordQuery toQuery(MyRecordPageRequest request, Long userId) {
return new RecordQuery(userId, request.getPage(), request.getSize(), request.getStartDate(),
request.getEndDate());
}
public static RecordQuery toQuery(MyRecordPageRequest request, Long userId) {
return RecordQuery.builder()
.userId(userId)
.page(request.getPage())
.startDate(request.getStartDate())
.endDate(request.getEndDate())
.size(request.getSize())
.sortBy(request.getSortBy())
.sortDirection(request.getSortDirection())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,42 @@
@Repository
public interface RecordRepository extends JpaRepository<RunningRecord, Long> {

Optional<RunningRecord> findByRecordPublicId(String id);

@Query("SELECT r FROM RunningRecord r " +
"WHERE r.userId = :userId " +
"AND r.startedAt BETWEEN :startOfWeek AND :now")
Slice<RunningRecord> findFirstRunOfWeek(
@Param("userId") Long userId,
@Param("startOfWeek") LocalDateTime startOfWeek,
@Param("now") LocalDateTime now,
Pageable pageable
);

@Query("SELECT COUNT(r.id) FROM RunningRecord r WHERE r.userId = :id")
Long countByUserId(Long id);

@Query("select r from RunningRecord r where r.userId = :userId")
Slice<RunningRecord> findLatestByUserId(Long userId, Pageable pageRequest);

@Query("select new org.runimo.runimo.records.service.dto.RecordStatDto(" +
"r.startedAt, " +
"r.endAt, " +
"r.totalDistance.amount) " +
"from RunningRecord r " +
"where r.userId = :userId " +
"and r.startedAt between :startOfWeek and :now " +
"order by r.startedAt asc")
List<RecordStatDto> findRecordStatByUserIdAndBetween(Long userId, LocalDateTime startOfWeek,
LocalDateTime now);

Page<RunningRecord> findRecordByUserIdOrderByStartedAtDesc(Long id, Pageable pageable);


@Query("select r " +
"from RunningRecord r " +
"where r.userId = :userId " +
"and r.startedAt between :from and :to " +
"order by r.startedAt asc")
Page<RunningRecord> findRecordByUserIdAndBetween(Long userId, LocalDateTime from,
LocalDateTime to, Pageable pageRequest);
Optional<RunningRecord> findByRecordPublicId(String id);

@Query("SELECT r FROM RunningRecord r " +
"WHERE r.userId = :userId " +
"AND r.startedAt BETWEEN :startOfWeek AND :now")
Slice<RunningRecord> findFirstRunOfWeek(
@Param("userId") Long userId,
@Param("startOfWeek") LocalDateTime startOfWeek,
@Param("now") LocalDateTime now,
Pageable pageable
);

@Query("SELECT COUNT(r.id) FROM RunningRecord r WHERE r.userId = :id")
Long countByUserId(Long id);

@Query("select r from RunningRecord r where r.userId = :userId")
Slice<RunningRecord> findLatestByUserId(Long userId, Pageable pageRequest);

@Query("select new org.runimo.runimo.records.service.dto.RecordStatDto(" +
"r.startedAt, " +
"r.endAt, " +
"r.totalDistance.amount) " +
"from RunningRecord r " +
"where r.userId = :userId " +
"and r.startedAt between :startOfWeek and :now " +
"order by r.startedAt asc")
List<RecordStatDto> findRecordStatByUserIdAndBetween(Long userId, LocalDateTime startOfWeek,
LocalDateTime now);

Page<RunningRecord> findRecordByUserIdOrderByStartedAtDesc(Long id, Pageable pageable);


@Query("select r " +
"from RunningRecord r " +
"where r.userId = :userId " +
"and r.startedAt between :from and :to")
Page<RunningRecord> findRecordByUserIdAndBetween(Long userId, LocalDateTime from,
LocalDateTime to, Pageable pageRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

@Builder
@Getter
@AllArgsConstructor
public class RecordQuery {

private final Long userId;
private final Integer page;
private final Integer size;
private final LocalDate startDate;
private final LocalDate endDate;
private final Long userId;
private final Integer page;
private final Integer size;
private final LocalDate startDate;
private final LocalDate endDate;
private final String sortBy;
private final String sortDirection;

public Pageable toPageable() {
return PageRequest.of(page, size);
}
public Pageable toPageable() {
Sort sort = Sort.by(Sort.Direction.fromString(sortDirection), sortBy);
return PageRequest.of(page, size, sort);
}
}