From e4089b2e514d4307b38c4fee46330e17c44dcd4e Mon Sep 17 00:00:00 2001 From: xmarek14 <xmarek14@fi.muni.cz> Date: Sun, 16 Apr 2023 22:56:56 +0200 Subject: [PATCH] Car queries --- .../pa165/car/data/repository/CarRepository.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/car/src/main/java/cz/muni/pa165/car/data/repository/CarRepository.java b/car/src/main/java/cz/muni/pa165/car/data/repository/CarRepository.java index 0a6e95ea..5e19a041 100644 --- a/car/src/main/java/cz/muni/pa165/car/data/repository/CarRepository.java +++ b/car/src/main/java/cz/muni/pa165/car/data/repository/CarRepository.java @@ -2,11 +2,25 @@ package cz.muni.pa165.car.data.repository; import cz.muni.pa165.car.data.model.Car; +import cz.muni.pa165.component.data.model.CarComponent; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; + /** * Car Repository for Driver Manager. */ @Repository -public interface CarRepository extends JpaRepository<Car, Long> {} +public interface CarRepository extends JpaRepository<Car, Long> { + + @Query("SELECT c FROM Car c WHERE c.id = :id") + Optional<Car> findById(@Param("id") Long id); + + @Query("SELECT c FROM Car c") + List<Car> findAll(); + +} -- GitLab