Skip to content

Commit

Permalink
Merge pull request #12 from Sam3Star/gayeong
Browse files Browse the repository at this point in the history
fix: modify query
  • Loading branch information
GayeongKimm authored Jun 25, 2024
2 parents 240fc6f + 05e2eb3 commit 8fcbe4f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
import kr.hs.dgsw.clock_server.global.common.enums.ColorEnum;
import kr.hs.dgsw.clock_server.global.common.enums.ImportanceEnum;

import java.time.LocalDate;

public record RoutineLoadRes(
Long id,
String name,
ImportanceEnum importanceEnum,
ColorEnum colorEnum
ColorEnum colorEnum,
LocalDate startAt,
LocalDate endAt
) {
public static RoutineLoadRes of(Long id,
String name,
ImportanceEnum importanceEnum,
ColorEnum colorEnum){
return new RoutineLoadRes(id, name, importanceEnum, colorEnum);
ColorEnum colorEnum,
LocalDate startAt,
LocalDate endAt){
return new RoutineLoadRes(id, name, importanceEnum, colorEnum, startAt, endAt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@

@Repository
public interface RoutineRepository extends JpaRepository<RoutineEntity, Long> {
List<RoutineEntity> findByEndAtGreaterThanEqual(LocalDate endAt);
@Query("select o from RoutineEntity o where :date between o.startAt and o.endAt")
List<RoutineEntity> findByDate(@Param("date") LocalDate date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ public void delete(Long id) {

@Override
public List<RoutineLoadRes> loadRoutine() {
List<RoutineEntity> routineEntity = routineRepository.findByEndAtGreaterThanEqual(LocalDate.now());
List<RoutineEntity> routineEntity = routineRepository.findByDate(LocalDate.now());

List<RoutineLoadRes> routineLoadResList = new ArrayList<>();
for (RoutineEntity routine : routineEntity){
routineLoadResList.add(RoutineLoadRes.of(routine.getRoutineId(),
routine.getName(),
routine.getImportanceEnum(),
routine.getColorEnum()));
routine.getColorEnum(),
routine.getStartAt(),
routine.getEndAt())
);
}
return routineLoadResList;
}
Expand Down

0 comments on commit 8fcbe4f

Please sign in to comment.