fixed getAllWaypointsByLocation by changing db field name
This commit is contained in:
@@ -21,6 +21,7 @@ public class WaypointController {
|
||||
|
||||
@GetMapping("/{location}")
|
||||
public ResponseEntity<List<WaypointsEntity>> getAllWaypoints(@PathVariable("location") String location) {
|
||||
System.out.println(waypointService.getAllWaypointsByLocation(location));
|
||||
List<WaypointsEntity> waypoint = waypointService.getAllWaypointsByLocation(location);
|
||||
return new ResponseEntity<>(waypoint, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class WaypointsEntity {
|
||||
@Column(name = "img")
|
||||
private String img;
|
||||
@Basic
|
||||
@Column(name = "locationName")
|
||||
@Column(name = "location_name")
|
||||
private String locationName;
|
||||
|
||||
public WaypointsEntity(String name, double lat, double lon, String description, String img, String locationName) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package ch.progetto152.repository;
|
||||
|
||||
import ch.progetto152.entity.WaypointsEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -10,6 +11,6 @@ public interface WaypointRepository extends JpaRepository<WaypointsEntity, Long>
|
||||
|
||||
Optional<WaypointsEntity> findWaypointByName(String name);
|
||||
|
||||
List<WaypointsEntity> findAllByLocationName(String locationName);
|
||||
Optional<List<WaypointsEntity>> findAllByLocationName(String locationName);
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public class WaypointService {
|
||||
}
|
||||
|
||||
public List<WaypointsEntity> getAllWaypointsByLocation(String locationName) {
|
||||
List<WaypointsEntity> waypoints = waypointRepository.findAllByLocationName(locationName);
|
||||
if (waypoints.isEmpty()) {
|
||||
List<WaypointsEntity> waypoints = waypointRepository.findAllByLocationName(locationName).orElse(null);
|
||||
if (waypoints.isEmpty() || waypoints == null) {
|
||||
return null;
|
||||
}else {
|
||||
return waypoints;
|
||||
|
||||
@@ -21,9 +21,9 @@ create table if not exists Waypoints
|
||||
lon double not null,
|
||||
description varchar(1000) not null,
|
||||
img varchar(1000) not null,
|
||||
locationName varchar(255) not null,
|
||||
location_name varchar(255) not null,
|
||||
primary key (id),
|
||||
foreign key (LocationName) references Location (location)
|
||||
foreign key (Location_name) references Location (location)
|
||||
);
|
||||
|
||||
create table if not exists User
|
||||
@@ -56,19 +56,19 @@ values ('Locarno', 'TI', 46.170794, 8.799534);
|
||||
insert into Location (location, region, lat, lon)
|
||||
values ('Ascona', 'TI', 46.157320, 8.773882);
|
||||
|
||||
insert into Waypoints (name, lat, lon, description, img, LocationName)
|
||||
insert into Waypoints (name, lat, lon, description, img, Location_name)
|
||||
values ('Cascata Santa Petronilla', 46.35328215446709, 8.97758397155138, 'A',
|
||||
'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png', 'Biasca');
|
||||
insert into Waypoints (name, lat, lon, description, img, LocationName)
|
||||
insert into Waypoints (name, lat, lon, description, img, Location_name)
|
||||
values ('Casa Küng', 46.363570208549994, 8.963464722308554, 'Descrizione del punto 2',
|
||||
'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png',
|
||||
'Biasca');
|
||||
insert into Waypoints (name, lat, lon, description, img, LocationName) values ('Punto 1', 46.123,
|
||||
insert into Waypoints (name, lat, lon, description, img, Location_name) values ('Punto 1', 46.123,
|
||||
8.123,
|
||||
'Descrizione del punto 3, un grandissimo',
|
||||
'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png',
|
||||
'Lugano');
|
||||
insert into Waypoints (id, name, lat, lon, description, img, locationName) values (4, 'Punto 2', 46.123, 8.123,
|
||||
insert into Waypoints (id, name, lat, lon, description, img, Location_name) values (4, 'Punto 2', 46.123, 8.123,
|
||||
'Descrizione del punto 4',
|
||||
'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png',
|
||||
'Locarno');
|
||||
|
||||
Reference in New Issue
Block a user