Added Lombok and created api fow WaypointsVisitedEntity
This commit is contained in:
@@ -21,11 +21,11 @@ public class LocationService {
|
||||
return locationRepository.findAll();
|
||||
}
|
||||
|
||||
public LocationEntity getLocationByIdService(Long id) {
|
||||
public LocationEntity getLocationById(Long id) {
|
||||
return locationRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public LocationEntity getLocationByNameService(String name){
|
||||
public LocationEntity getLocationByName(String name){
|
||||
return locationRepository.findLocationByLocation(name).orElse(null);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class LocationService {
|
||||
}
|
||||
|
||||
public LocationEntity updateLocation(Long id, LocationEntity Location) {
|
||||
LocationEntity location1 = getLocationByIdService(id);
|
||||
LocationEntity location1 = getLocationById(id);
|
||||
if (location1 != null) {
|
||||
location1.setLocation(Location.getLocation());
|
||||
location1.setRegion(Location.getRegion());
|
||||
|
||||
@@ -22,15 +22,15 @@ public class UserService {
|
||||
return userRepository.findAll();
|
||||
}
|
||||
|
||||
public UserEntity getUserByIdService(Long id) {
|
||||
public UserEntity getUserById(Long id) {
|
||||
return userRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public UserEntity getUserByNameService(String name){
|
||||
public UserEntity getUserByName(String name){
|
||||
return userRepository.findUserByName(name).orElse(null);
|
||||
}
|
||||
|
||||
public UserEntity getUserByUsernameService(String username){
|
||||
public UserEntity getUserByUsername(String username){
|
||||
return userRepository.findUserByUsername(username).orElse(null);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class UserService {
|
||||
}
|
||||
|
||||
public UserEntity updateUser(Long id, UserEntity user) {
|
||||
UserEntity user1 = getUserByIdService(id);
|
||||
UserEntity user1 = getUserById(id);
|
||||
if (user1 != null) {
|
||||
user1.setName(user.getName());
|
||||
user1.setUsername(user.getUsername());
|
||||
|
||||
@@ -20,11 +20,11 @@ public class WaypointService {
|
||||
return waypointRepository.findAll();
|
||||
}
|
||||
|
||||
public WaypointsEntity getWaypointByIdService(Long id) {
|
||||
public WaypointsEntity getWaypointById(Long id) {
|
||||
return waypointRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public WaypointsEntity getWaypointByNameService(String name) {
|
||||
public WaypointsEntity getWaypointByName(String name) {
|
||||
return waypointRepository.findWaypointByName(name).orElse(null);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class WaypointService {
|
||||
}
|
||||
|
||||
public WaypointsEntity updateWaypoint(Long id, WaypointsEntity waypoint) {
|
||||
WaypointsEntity waypoint1 = getWaypointByIdService(id);
|
||||
WaypointsEntity waypoint1 = getWaypointById(id);
|
||||
if (waypoint1 != null) {
|
||||
waypoint1.setName(waypoint.getName());
|
||||
waypoint1.setLat(waypoint.getLat());
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package ch.progetto152.services;
|
||||
|
||||
import ch.progetto152.entity.WaypointsVisitedEntity;
|
||||
import ch.progetto152.repository.WaypointVisitedRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class WaypointVisitedService {
|
||||
private final WaypointVisitedRepository waypointVisitedRepository;
|
||||
|
||||
@Autowired
|
||||
public WaypointVisitedService(WaypointVisitedRepository waypointVisitedRepository) {
|
||||
this.waypointVisitedRepository = waypointVisitedRepository;
|
||||
}
|
||||
|
||||
public List<WaypointsVisitedEntity> getAllWaypointsVisited() {
|
||||
return waypointVisitedRepository.findAll();
|
||||
}
|
||||
|
||||
public WaypointsVisitedEntity getWaypointById(Long id) {
|
||||
return waypointVisitedRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public WaypointsVisitedEntity getWaypointsVisitedByUserId(Long id) {
|
||||
return waypointVisitedRepository.findWaypointsVisitedEntitiesByUserId(id).orElse(null);
|
||||
}
|
||||
|
||||
public WaypointsVisitedEntity getWaypointsVisitedByWaypointId(Long id) {
|
||||
return waypointVisitedRepository.findWaypointsVisitedEntitiesByWaypointId(id).orElse(null);
|
||||
}
|
||||
|
||||
public WaypointsVisitedEntity createWaypoint(WaypointsVisitedEntity waypoint) {
|
||||
return waypointVisitedRepository.save(waypoint);
|
||||
}
|
||||
|
||||
public WaypointsVisitedEntity updateWaypoint(Long id, WaypointsVisitedEntity waypoint) {
|
||||
WaypointsVisitedEntity waypoint1 = getWaypointById(id);
|
||||
if (waypoint1 != null) {
|
||||
waypoint1.setWaypointId(waypoint.getWaypointId());
|
||||
waypoint1.setUserId(waypoint.getUserId());
|
||||
return waypointVisitedRepository.save(waypoint1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteWaypoint(Long id) {
|
||||
boolean exists = waypointVisitedRepository.existsById(id);
|
||||
if (!exists) {
|
||||
return false;
|
||||
}
|
||||
waypointVisitedRepository.deleteById(id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user