Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
on 05-23-2022 04:02 PM
I have a problem about implementing CRUD operations through neo4j query in Spring Boot.
I also defined calculateDuration to shortestPath in terms of duration in Route
How can I connect with it with City? How can I fix it ? Here is my link :
I have an issue with both operations defined in both CityRepository and RouteRepository shown below.
Here is my project link : Project
How can I fix my issue?
Here are my entities as City and Route shown below.
City
public class City {
@Id
@GeneratedValue
private Long id;
private String name;
@Relationship(type = "ROUTES", direction = Relationship.Direction.OUTGOING)
private Set<Route> routes = new HashSet<>();
public City(String name) {
this.name = name;
}
}
Route
public class Route {
@Id
@GeneratedValue
private Long id;
private String destination;
private String departureTime;
private String arriveTime;
private Long duration;
}
Here is my CityRepository shown below.
public interface CityRepository extends Neo4jRepository<City,Long> {
@Query("MATCH (cities:City) RETURN cities")
List<City> listAll();
@Query("MATCH (city:City {id: $cityId}) RETURN city")
City getById(Long cityId);
@Query("MATCH (city:City {name: $cityName}) RETURN city")
City getByCityName(String cityName);
@Query("CREATE (city:City {name: $cityName}) RETURN city")
City saveCity(String cityName);
@Query("MATCH (city:City {name: $cityName}) SET city.id = $cityId RETURN city")
City updateCity(Long cityId, String cityName);
@Query("MATCH (city:City {id: $cityId}) DELETE city")
void deleteUser(Long cityId);
}
Here is my RouteRepository shown below.
public interface RouteRepository extends Neo4jRepository<Route,Long> {
@Query("MATCH (routes:Route) WHERE routes.id=$id RETURN routes")
List<Route> listAllByCityId(Long cityId);
@Query("MATCH (route:Route {id: $routeId}) RETURN route")
Route getById(Long routeId);
@Query("CREATE (city:City {id: $cityId})-[:ROUTES]->(route:Route {destination: $destination, departureTime: $departureTime," +
"arriveTime: $arriveTime, duration: $duration}) " +
"RETURN route")
Route saveRoute(Long cityId, String destination,String departureTime,
String arriveTime,Long duration);
@Query("MATCH (city:City {id: $cityId})-[:ROUTES]->(route:Route {id: $routeId}) " +
"SET route.destination = $destination,route.departureTime = $departureTime," +
"route.arriveTime = $arriveTime, route.duration = $duration RETURN route")
Route updateRoute(Long cityId, Long routeId, String destination,String departureTime,
String arriveTime,Long duration);
@Query("MATCH (city:City {id: $cityId})-[:ROUTES]->(route:Route {id: $routeId}) DELETE route")
void deleteRoute(Long cityId, Long routeId);
}