Skip to content
Snippets Groups Projects
Commit 4f08eda2 authored by Karsch Lukas's avatar Karsch Lukas
Browse files

#3

fix typo, add additional ordering to custom queries in garden repository
parent 9513bd91
No related branches found
No related tags found
1 merge request!12#3 merge fully implemented garden branch into main
......@@ -17,7 +17,8 @@ public interface GardenRepository extends JpaRepository<GardenEntry, Long> {
WHEN :week >= ge.plant.harvestWeekStart
THEN ABS(:week - ge.plant.harvestWeekStart)
ELSE ABS(52 + :week - ge.plant.harvestWeekStart)
END
END,
ge.plant.name
ASC
""")
List<GardenEntry> findNearestHarvestWeek(@Param("week") int currentWeek);
......@@ -29,7 +30,8 @@ public interface GardenRepository extends JpaRepository<GardenEntry, Long> {
WHEN :week >= ge.plant.plantWeekStart
THEN ABS(:week - ge.plant.plantWeekStart)
ELSE ABS(52 + :week - ge.plant.plantWeekStart)
END
END,
ge.plant.name
ASC
""")
List<GardenEntry> findNearestPlantingWeek(@Param("week") int currentWeek);
......
......@@ -23,8 +23,8 @@ public class GardenService {
if (sort == null) return getAllPlantsOrderedByName();
return switch (sort) {
case "createdAt" -> getAllPlantsOrderedByCreatedDate();
case "plantDate" -> getALlPlantsOrderedByNextPossiblePlantDate();
case "harvestDate" -> getALlPlantsOrderedByNextPossibleHarvest();
case "plantDate" -> getAllPlantsOrderedByNextPossiblePlantDate();
case "harvestDate" -> getAllPlantsOrderedByNextPossibleHarvest();
default -> getAllPlantsOrderedByName();
};
}
......@@ -61,13 +61,13 @@ public class GardenService {
);
}
private List<Plant> getALlPlantsOrderedByNextPossiblePlantDate() {
private List<Plant> getAllPlantsOrderedByNextPossiblePlantDate() {
return mapGardenEntriesToPlants(
gardenRepository.findNearestPlantingWeek(DateTimeUtils.getCurrentWeekForToday())
);
}
private List<Plant> getALlPlantsOrderedByNextPossibleHarvest() {
private List<Plant> getAllPlantsOrderedByNextPossibleHarvest() {
return mapGardenEntriesToPlants(
gardenRepository.findNearestHarvestWeek(DateTimeUtils.getCurrentWeekForToday())
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment