Added error checking for post calls
This commit is contained in:
@@ -2,6 +2,7 @@ package ch.progetto152.services;
|
||||
|
||||
import ch.progetto152.entity.LocationEntity;
|
||||
import ch.progetto152.repository.LocationRepository;
|
||||
import ch.progetto152.utility.ErrorChecking;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -10,6 +11,7 @@ import java.util.List;
|
||||
@Service
|
||||
public class LocationService {
|
||||
|
||||
private ErrorChecking errorChecking = new ErrorChecking();
|
||||
private final LocationRepository locationRepository;
|
||||
|
||||
@Autowired
|
||||
@@ -30,7 +32,11 @@ public class LocationService {
|
||||
}
|
||||
|
||||
public LocationEntity createLocation(LocationEntity Location) {
|
||||
return locationRepository.save(Location);
|
||||
if(errorChecking.checkLocation(Location)) {
|
||||
return locationRepository.save(Location);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public LocationEntity updateLocation(Long id, LocationEntity Location) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package ch.progetto152.services;
|
||||
|
||||
import ch.progetto152.entity.UserEntity;
|
||||
import ch.progetto152.repository.UserRepository;
|
||||
import ch.progetto152.utility.ErrorChecking;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -11,6 +12,7 @@ import java.util.List;
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
ErrorChecking errorChecking = new ErrorChecking();
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
@@ -35,7 +37,11 @@ public class UserService {
|
||||
}
|
||||
|
||||
public UserEntity createUser(UserEntity user) {
|
||||
return userRepository.save(user);
|
||||
if(errorChecking.checkUser(user)) {
|
||||
return userRepository.save(user);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public UserEntity updateUser(Long id, UserEntity user) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package ch.progetto152.services;
|
||||
|
||||
import ch.progetto152.entity.WaypointsEntity;
|
||||
import ch.progetto152.repository.WaypointRepository;
|
||||
import ch.progetto152.utility.ErrorChecking;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -9,6 +10,8 @@ import java.util.List;
|
||||
|
||||
@Service
|
||||
public class WaypointService {
|
||||
|
||||
ErrorChecking errorChecking = new ErrorChecking();
|
||||
private final WaypointRepository waypointRepository;
|
||||
|
||||
@Autowired
|
||||
@@ -29,7 +32,10 @@ public class WaypointService {
|
||||
}
|
||||
|
||||
public WaypointsEntity createWaypoint(WaypointsEntity waypoint) {
|
||||
return waypointRepository.save(waypoint);
|
||||
if (errorChecking.checkWaypoint(waypoint)) {
|
||||
return waypointRepository.save(waypoint);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public WaypointsEntity updateWaypoint(Long id, WaypointsEntity waypoint) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package ch.progetto152.services;
|
||||
|
||||
import ch.progetto152.entity.WaypointsVisitedEntity;
|
||||
import ch.progetto152.repository.WaypointVisitedRepository;
|
||||
import ch.progetto152.utility.ErrorChecking;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -9,6 +10,8 @@ import java.util.List;
|
||||
|
||||
@Service
|
||||
public class WaypointVisitedService {
|
||||
|
||||
ErrorChecking errorChecking = new ErrorChecking();
|
||||
private final WaypointVisitedRepository waypointVisitedRepository;
|
||||
|
||||
@Autowired
|
||||
@@ -33,7 +36,10 @@ public class WaypointVisitedService {
|
||||
}
|
||||
|
||||
public WaypointsVisitedEntity createWaypoint(WaypointsVisitedEntity waypoint) {
|
||||
return waypointVisitedRepository.save(waypoint);
|
||||
if (errorChecking.checkWaypointVisited(waypoint)) {
|
||||
return waypointVisitedRepository.save(waypoint);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public WaypointsVisitedEntity updateWaypoint(Long id, WaypointsVisitedEntity waypoint) {
|
||||
|
||||
Reference in New Issue
Block a user