Regenerating entity, and changes in all files

This commit is contained in:
2023-04-27 12:03:53 +02:00
parent 9aa7fb0682
commit 69a0e6d271
14 changed files with 126 additions and 131 deletions

View File

@@ -1,9 +1,7 @@
package ch.progetto152; package ch.progetto152;
import ch.progetto152.controller.Controller;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication @SpringBootApplication
public class Progetto152Application { public class Progetto152Application {
@@ -12,6 +10,4 @@ public class Progetto152Application {
SpringApplication.run(Progetto152Application.class, args); SpringApplication.run(Progetto152Application.class, args);
} }
} }

View File

@@ -1,6 +1,6 @@
package ch.progetto152.controller; package ch.progetto152.controller;
import ch.progetto152.entity.Location; import ch.progetto152.entity.LocationEntity;
import ch.progetto152.services.LocationService; import ch.progetto152.services.LocationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@@ -20,14 +20,14 @@ public class LocationController {
} }
@GetMapping("/get/all") @GetMapping("/get/all")
public ResponseEntity<List<Location>> getAllLocations() { public ResponseEntity<List<LocationEntity>> getAllLocations() {
List<Location> Locations = locationService.getAllLocations(); List<LocationEntity> Locations = locationService.getAllLocations();
return new ResponseEntity<>(Locations, HttpStatus.OK); return new ResponseEntity<>(Locations, HttpStatus.OK);
} }
@GetMapping("/get/{id}") @GetMapping("/get/{id}")
public ResponseEntity<Location> getLocationById(@PathVariable("id") Long id) { public ResponseEntity<LocationEntity> getLocationById(@PathVariable("id") Long id) {
Location location = locationService.getLocationByIdService(id); LocationEntity location = locationService.getLocationByIdService(id);
if (location != null) { if (location != null) {
return new ResponseEntity<>(location, HttpStatus.OK); return new ResponseEntity<>(location, HttpStatus.OK);
} else { } else {
@@ -36,8 +36,8 @@ public class LocationController {
} }
@GetMapping("/get/name/{name}") @GetMapping("/get/name/{name}")
public ResponseEntity<Location> getLocationByName(@PathVariable("name") String name) { public ResponseEntity<LocationEntity> getLocationByName(@PathVariable("name") String name) {
Location location = locationService.getLocationByNameService(name); LocationEntity location = locationService.getLocationByNameService(name);
if (location != null) { if (location != null) {
return new ResponseEntity<>(location, HttpStatus.OK); return new ResponseEntity<>(location, HttpStatus.OK);
} else { } else {
@@ -46,14 +46,14 @@ public class LocationController {
} }
@PostMapping("/create/{id}") @PostMapping("/create/{id}")
public ResponseEntity<Location> createLocation(@RequestBody Location location) { public ResponseEntity<LocationEntity> createLocation(@RequestBody LocationEntity location) {
Location createdLocation = locationService.createLocation(location); LocationEntity createdLocation = locationService.createLocation(location);
return new ResponseEntity<>(createdLocation, HttpStatus.CREATED); return new ResponseEntity<>(createdLocation, HttpStatus.CREATED);
} }
@PutMapping("/put/{id}") @PutMapping("/put/{id}")
public ResponseEntity<Location> updateLocation(@PathVariable("id") Long id, @RequestBody Location location) { public ResponseEntity<LocationEntity> updateLocation(@PathVariable("id") Long id, @RequestBody LocationEntity location) {
Location location1 = locationService.updateLocation(id, location); LocationEntity location1 = locationService.updateLocation(id, location);
if (location1 != null) { if (location1 != null) {
return new ResponseEntity<>(location1, HttpStatus.OK); return new ResponseEntity<>(location1, HttpStatus.OK);
} else { } else {

View File

@@ -1,7 +1,7 @@
package ch.progetto152.controller; package ch.progetto152.controller;
import ch.progetto152.entity.User; import ch.progetto152.entity.UserEntity;
import ch.progetto152.services.UserService; import ch.progetto152.services.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@@ -14,7 +14,6 @@ import java.util.List;
@RequestMapping("/api/users") @RequestMapping("/api/users")
public class UserController { public class UserController {
private final UserService userService; private final UserService userService;
@Autowired @Autowired
@@ -23,14 +22,14 @@ public class UserController {
} }
@GetMapping("/get/all") @GetMapping("/get/all")
public ResponseEntity<List<User>> getAllUsers() { public ResponseEntity<List<UserEntity>> getAllUsers() {
List<User> users = userService.getAllUsers(); List<UserEntity> users = userService.getAllUsers();
return new ResponseEntity<>(users, HttpStatus.OK); return new ResponseEntity<>(users, HttpStatus.OK);
} }
@GetMapping("/get/{id}") @GetMapping("/get/{id}")
public ResponseEntity<User> getUserById(@PathVariable("id") Long id) { public ResponseEntity<UserEntity> getUserById(@PathVariable("id") Long id) {
User user = userService.getUserByIdService(id); UserEntity user = userService.getUserByIdService(id);
if (user != null) { if (user != null) {
return new ResponseEntity<>(user, HttpStatus.OK); return new ResponseEntity<>(user, HttpStatus.OK);
} else { } else {
@@ -39,8 +38,8 @@ public class UserController {
} }
@GetMapping("/get/name/{name}") @GetMapping("/get/name/{name}")
public ResponseEntity<User> getUserByName(@PathVariable("name") String name) { public ResponseEntity<UserEntity> getUserByName(@PathVariable("name") String name) {
User user = userService.getUserByNameService(name); UserEntity user = userService.getUserByNameService(name);
if (user != null) { if (user != null) {
return new ResponseEntity<>(user, HttpStatus.OK); return new ResponseEntity<>(user, HttpStatus.OK);
} else { } else {
@@ -49,8 +48,8 @@ public class UserController {
} }
@GetMapping("/get/username/{username}") @GetMapping("/get/username/{username}")
public ResponseEntity<User> getUserByUsername(@PathVariable("username") String username) { public ResponseEntity<UserEntity> getUserByUsername(@PathVariable("username") String username) {
User user = userService.getUserByUsernameService(username); UserEntity user = userService.getUserByUsernameService(username);
if (user != null) { if (user != null) {
return new ResponseEntity<>(user, HttpStatus.OK); return new ResponseEntity<>(user, HttpStatus.OK);
} else { } else {
@@ -59,14 +58,14 @@ public class UserController {
} }
@PostMapping("/create/{id}") @PostMapping("/create/{id}")
public ResponseEntity<User> createUser(@RequestBody User user) { public ResponseEntity<UserEntity> createUser(@RequestBody UserEntity user) {
User createdUser = userService.createUser(user); UserEntity createdUser = userService.createUser(user);
return new ResponseEntity<>(createdUser, HttpStatus.CREATED); return new ResponseEntity<>(createdUser, HttpStatus.CREATED);
} }
@PutMapping("/put/{id}") @PutMapping("/put/{id}")
public ResponseEntity<User> updateUser(@PathVariable("id") Long id, @RequestBody User user) { public ResponseEntity<UserEntity> updateUser(@PathVariable("id") Long id, @RequestBody UserEntity user) {
User updatedUser = userService.updateUser(id, user); UserEntity updatedUser = userService.updateUser(id, user);
if (updatedUser != null) { if (updatedUser != null) {
return new ResponseEntity<>(updatedUser, HttpStatus.OK); return new ResponseEntity<>(updatedUser, HttpStatus.OK);
} else { } else {

View File

@@ -1,6 +1,6 @@
package ch.progetto152.controller; package ch.progetto152.controller;
import ch.progetto152.entity.Waypoints; import ch.progetto152.entity.WaypointsEntity;
import ch.progetto152.services.WaypointService; import ch.progetto152.services.WaypointService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@@ -20,14 +20,14 @@ public class WaypointController {
} }
@GetMapping("/get/all") @GetMapping("/get/all")
public ResponseEntity<List<Waypoints>> getAllWaypoints() { public ResponseEntity<List<WaypointsEntity>> getAllWaypoints() {
List<Waypoints> waypoint = waypointService.getAllWaypoints(); List<WaypointsEntity> waypoint = waypointService.getAllWaypoints();
return new ResponseEntity<>(waypoint, HttpStatus.OK); return new ResponseEntity<>(waypoint, HttpStatus.OK);
} }
@GetMapping("/get/{id}") @GetMapping("/get/{id}")
public ResponseEntity<Waypoints> getWaypointById(@PathVariable("id") Long id) { public ResponseEntity<WaypointsEntity> getWaypointById(@PathVariable("id") Long id) {
Waypoints waypoint = waypointService.getWaypointByIdService(id); WaypointsEntity waypoint = waypointService.getWaypointByIdService(id);
if (waypoint != null) { if (waypoint != null) {
return new ResponseEntity<>(waypoint, HttpStatus.OK); return new ResponseEntity<>(waypoint, HttpStatus.OK);
} else { } else {
@@ -36,8 +36,8 @@ public class WaypointController {
} }
@GetMapping("/get/name/{name}") @GetMapping("/get/name/{name}")
public ResponseEntity<Waypoints> getWaypointByName(@PathVariable("name") String name) { public ResponseEntity<WaypointsEntity> getWaypointByName(@PathVariable("name") String name) {
Waypoints waypoint = waypointService.getWaypointByNameService(name); WaypointsEntity waypoint = waypointService.getWaypointByNameService(name);
if (waypoint != null) { if (waypoint != null) {
return new ResponseEntity<>(waypoint, HttpStatus.OK); return new ResponseEntity<>(waypoint, HttpStatus.OK);
} else { } else {
@@ -46,14 +46,14 @@ public class WaypointController {
} }
@PostMapping("/create/{id}") @PostMapping("/create/{id}")
public ResponseEntity<Waypoints> createWaypoint(@RequestBody Waypoints waypoint) { public ResponseEntity<WaypointsEntity> createWaypoint(@RequestBody WaypointsEntity waypoint) {
Waypoints createdWaypoint = waypointService.createWaypoint(waypoint); WaypointsEntity createdWaypoint = waypointService.createWaypoint(waypoint);
return new ResponseEntity<>(createdWaypoint, HttpStatus.CREATED); return new ResponseEntity<>(createdWaypoint, HttpStatus.CREATED);
} }
@PutMapping("/put/{id}") @PutMapping("/put/{id}")
public ResponseEntity<Waypoints> updateWaypoint(@PathVariable("id") Long id, @RequestBody Waypoints waypoint) { public ResponseEntity<WaypointsEntity> updateWaypoint(@PathVariable("id") Long id, @RequestBody WaypointsEntity waypoint) {
Waypoints updatedWaypoint = waypointService.updateWaypoint(id, waypoint); WaypointsEntity updatedWaypoint = waypointService.updateWaypoint(id, waypoint);
if (updatedWaypoint != null) { if (updatedWaypoint != null) {
return new ResponseEntity<>(updatedWaypoint, HttpStatus.OK); return new ResponseEntity<>(updatedWaypoint, HttpStatus.OK);
} else { } else {

View File

@@ -1,16 +1,14 @@
package ch.progetto152.entity; package ch.progetto152.entity;
import jakarta.persistence.*; import jakarta.persistence.*;
import java.util.Objects; import java.util.Objects;
@Entity @Entity
@Table(name = "Location", schema = "Progetto152", catalog = "") @Table(name = "Location", schema = "Progetto152", catalog = "")
public class Location { public class LocationEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Id @Id
@Column(name = "id")
private int id;
@Basic
@Column(name = "location") @Column(name = "location")
private String location; private String location;
@Basic @Basic
@@ -23,14 +21,6 @@ public class Location {
@Column(name = "lon") @Column(name = "lon")
private double lon; private double lon;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getLocation() { public String getLocation() {
return location; return location;
} }
@@ -71,12 +61,12 @@ public class Location {
if (o == null || getClass() != o.getClass()) { if (o == null || getClass() != o.getClass()) {
return false; return false;
} }
Location that = (Location) o; LocationEntity that = (LocationEntity) o;
return id == that.id && Double.compare(that.lat, lat) == 0 && Double.compare(that.lon, lon) == 0 && Objects.equals(location, that.location) && Objects.equals(region, that.region); return Double.compare(that.lat, lat) == 0 && Double.compare(that.lon, lon) == 0 && Objects.equals(location, that.location) && Objects.equals(region, that.region);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(id, location, region, lat, lon); return Objects.hash(location, region, lat, lon);
} }
} }

View File

@@ -1,20 +1,14 @@
package ch.progetto152.entity; package ch.progetto152.entity;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.*;
import java.util.Objects; import java.util.Objects;
@Entity @Entity
@Getter @Table(name = "User", schema = "Progetto152", catalog = "")
@Setter public class UserEntity {
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Table
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name = "id") @Column(name = "id")
private int id; private int id;
@Basic @Basic
@@ -27,9 +21,35 @@ public class User {
@Column(name = "password") @Column(name = "password")
private String password; private String password;
public User(String name, String username, String password) { public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name; this.name = name;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username; this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password; this.password = password;
} }
@@ -41,7 +61,7 @@ public class User {
if (o == null || getClass() != o.getClass()) { if (o == null || getClass() != o.getClass()) {
return false; return false;
} }
User that = (User) o; UserEntity that = (UserEntity) o;
return id == that.id && Objects.equals(name, that.name) && Objects.equals(username, that.username) && Objects.equals(password, that.password); return id == that.id && Objects.equals(name, that.name) && Objects.equals(username, that.username) && Objects.equals(password, that.password);
} }

View File

@@ -6,7 +6,7 @@ import java.util.Objects;
@Entity @Entity
@Table(name = "Waypoints", schema = "Progetto152", catalog = "") @Table(name = "Waypoints", schema = "Progetto152", catalog = "")
public class Waypoints { public class WaypointsEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Id @Id
@Column(name = "id") @Column(name = "id")
@@ -27,8 +27,8 @@ public class Waypoints {
@Column(name = "img") @Column(name = "img")
private String img; private String img;
@Basic @Basic
@Column(name = "LocationId") @Column(name = "locationName")
private int locationId; private String locationName;
public int getId() { public int getId() {
return id; return id;
@@ -78,12 +78,12 @@ public class Waypoints {
this.img = img; this.img = img;
} }
public int getLocationId() { public String getLocationName() {
return locationId; return locationName;
} }
public void setLocationId(int locationId) { public void setLocationName(String locationName) {
this.locationId = locationId; this.locationName = locationName;
} }
@Override @Override
@@ -94,12 +94,12 @@ public class Waypoints {
if (o == null || getClass() != o.getClass()) { if (o == null || getClass() != o.getClass()) {
return false; return false;
} }
Waypoints that = (Waypoints) o; WaypointsEntity that = (WaypointsEntity) o;
return id == that.id && Double.compare(that.lat, lat) == 0 && Double.compare(that.lon, lon) == 0 && locationId == that.locationId && Objects.equals(name, that.name) && Objects.equals(description, that.description) && Objects.equals(img, that.img); return id == that.id && Double.compare(that.lat, lat) == 0 && Double.compare(that.lon, lon) == 0 && Objects.equals(name, that.name) && Objects.equals(description, that.description) && Objects.equals(img, that.img) && Objects.equals(locationName, that.locationName);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(id, name, lat, lon, description, img, locationId); return Objects.hash(id, name, lat, lon, description, img, locationName);
} }
} }

View File

@@ -5,17 +5,16 @@ import jakarta.persistence.*;
import java.util.Objects; import java.util.Objects;
@Entity @Entity
public class LocationVisited{ @Table(name = "WaypointsVisited", schema = "Progetto152", catalog = "")
public class WaypointsVisitedEntity {
@Id
@Basic @Basic
@Id
@Column(name = "userId") @Column(name = "userId")
private int userId; private int userId;
@Basic @Basic
@Column(name = "locationid")
private int locationid;
@Id @Id
private Long id; @Column(name = "waypointId")
private int waypointId;
public int getUserId() { public int getUserId() {
return userId; return userId;
@@ -25,12 +24,12 @@ public class LocationVisited{
this.userId = userId; this.userId = userId;
} }
public int getLocationid() { public int getWaypointId() {
return locationid; return waypointId;
} }
public void setLocationid(int locationid) { public void setWaypointId(int waypointId) {
this.locationid = locationid; this.waypointId = waypointId;
} }
@Override @Override
@@ -41,21 +40,12 @@ public class LocationVisited{
if (o == null || getClass() != o.getClass()) { if (o == null || getClass() != o.getClass()) {
return false; return false;
} }
LocationVisited that = (LocationVisited) o; WaypointsVisitedEntity that = (WaypointsVisitedEntity) o;
return userId == that.userId && locationid == that.locationid; return userId == that.userId && waypointId == that.waypointId;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(userId, locationid); return Objects.hash(userId, waypointId);
} }
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
} }

View File

@@ -1,11 +1,11 @@
package ch.progetto152.repository; package ch.progetto152.repository;
import ch.progetto152.entity.Location; import ch.progetto152.entity.LocationEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional; import java.util.Optional;
public interface LocationRepository extends JpaRepository<Location, Long> { public interface LocationRepository extends JpaRepository<LocationEntity, Long> {
Optional<Location> findLocationByLocation(String name); Optional<LocationEntity> findLocationByLocation(String name);
} }

View File

@@ -1,16 +1,16 @@
package ch.progetto152.repository; package ch.progetto152.repository;
import ch.progetto152.entity.User; import ch.progetto152.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Optional; import java.util.Optional;
@Repository @Repository
public interface UserRepository extends JpaRepository<User, Long> { public interface UserRepository extends JpaRepository<UserEntity, Long> {
Optional<User> findUserByName(String name); Optional<UserEntity> findUserByName(String name);
Optional<User> findUserByUsername(String username); Optional<UserEntity> findUserByUsername(String username);
} }

View File

@@ -1,11 +1,11 @@
package ch.progetto152.repository; package ch.progetto152.repository;
import ch.progetto152.entity.Waypoints; import ch.progetto152.entity.WaypointsEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional; import java.util.Optional;
public interface WaypointRepository extends JpaRepository<Waypoints, Long> { public interface WaypointRepository extends JpaRepository<WaypointsEntity, Long> {
Optional<Waypoints> findWaypointByName(String name); Optional<WaypointsEntity> findWaypointByName(String name);
} }

View File

@@ -1,6 +1,6 @@
package ch.progetto152.services; package ch.progetto152.services;
import ch.progetto152.entity.Location; import ch.progetto152.entity.LocationEntity;
import ch.progetto152.repository.LocationRepository; import ch.progetto152.repository.LocationRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -17,24 +17,24 @@ public class LocationService {
this.locationRepository = locationRepository; this.locationRepository = locationRepository;
} }
public List<Location> getAllLocations() { public List<LocationEntity> getAllLocations() {
return locationRepository.findAll(); return locationRepository.findAll();
} }
public Location getLocationByIdService(Long id) { public LocationEntity getLocationByIdService(Long id) {
return locationRepository.findById(id).orElse(null); return locationRepository.findById(id).orElse(null);
} }
public Location getLocationByNameService(String name){ public LocationEntity getLocationByNameService(String name){
return locationRepository.findLocationByLocation(name).orElse(null); return locationRepository.findLocationByLocation(name).orElse(null);
} }
public Location createLocation(Location Location) { public LocationEntity createLocation(LocationEntity Location) {
return locationRepository.save(Location); return locationRepository.save(Location);
} }
public Location updateLocation(Long id, Location Location) { public LocationEntity updateLocation(Long id, LocationEntity Location) {
Location location1 = getLocationByIdService(id); LocationEntity location1 = getLocationByIdService(id);
if (location1 != null) { if (location1 != null) {
location1.setLocation(Location.getLocation()); location1.setLocation(Location.getLocation());
location1.setRegion(Location.getRegion()); location1.setRegion(Location.getRegion());

View File

@@ -1,7 +1,7 @@
package ch.progetto152.services; package ch.progetto152.services;
import ch.progetto152.entity.User; import ch.progetto152.entity.UserEntity;
import ch.progetto152.repository.UserRepository; import ch.progetto152.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -18,28 +18,28 @@ public class UserService {
this.userRepository = userRepository; this.userRepository = userRepository;
} }
public List<User> getAllUsers() { public List<UserEntity> getAllUsers() {
return userRepository.findAll(); return userRepository.findAll();
} }
public User getUserByIdService(Long id) { public UserEntity getUserByIdService(Long id) {
return userRepository.findById(id).orElse(null); return userRepository.findById(id).orElse(null);
} }
public User getUserByNameService(String name){ public UserEntity getUserByNameService(String name){
return userRepository.findUserByName(name).orElse(null); return userRepository.findUserByName(name).orElse(null);
} }
public User getUserByUsernameService(String username){ public UserEntity getUserByUsernameService(String username){
return userRepository.findUserByUsername(username).orElse(null); return userRepository.findUserByUsername(username).orElse(null);
} }
public User createUser(User user) { public UserEntity createUser(UserEntity user) {
return userRepository.save(user); return userRepository.save(user);
} }
public User updateUser(Long id, User user) { public UserEntity updateUser(Long id, UserEntity user) {
User user1 = getUserByIdService(id); UserEntity user1 = getUserByIdService(id);
if (user1 != null) { if (user1 != null) {
user1.setName(user.getName()); user1.setName(user.getName());
user1.setUsername(user.getUsername()); user1.setUsername(user.getUsername());

View File

@@ -1,6 +1,6 @@
package ch.progetto152.services; package ch.progetto152.services;
import ch.progetto152.entity.Waypoints; import ch.progetto152.entity.WaypointsEntity;
import ch.progetto152.repository.WaypointRepository; import ch.progetto152.repository.WaypointRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -16,31 +16,31 @@ public class WaypointService {
this.waypointRepository = waypointRepository; this.waypointRepository = waypointRepository;
} }
public List<Waypoints> getAllWaypoints() { public List<WaypointsEntity> getAllWaypoints() {
return waypointRepository.findAll(); return waypointRepository.findAll();
} }
public Waypoints getWaypointByIdService(Long id) { public WaypointsEntity getWaypointByIdService(Long id) {
return waypointRepository.findById(id).orElse(null); return waypointRepository.findById(id).orElse(null);
} }
public Waypoints getWaypointByNameService(String name) { public WaypointsEntity getWaypointByNameService(String name) {
return waypointRepository.findWaypointByName(name).orElse(null); return waypointRepository.findWaypointByName(name).orElse(null);
} }
public Waypoints createWaypoint(Waypoints waypoint) { public WaypointsEntity createWaypoint(WaypointsEntity waypoint) {
return waypointRepository.save(waypoint); return waypointRepository.save(waypoint);
} }
public Waypoints updateWaypoint(Long id, Waypoints waypoint) { public WaypointsEntity updateWaypoint(Long id, WaypointsEntity waypoint) {
Waypoints waypoint1 = getWaypointByIdService(id); WaypointsEntity waypoint1 = getWaypointByIdService(id);
if (waypoint1 != null) { if (waypoint1 != null) {
waypoint1.setName(waypoint.getName()); waypoint1.setName(waypoint.getName());
waypoint1.setLat(waypoint.getLat()); waypoint1.setLat(waypoint.getLat());
waypoint1.setLon(waypoint.getLon()); waypoint1.setLon(waypoint.getLon());
waypoint1.setDescription(waypoint.getDescription()); waypoint1.setDescription(waypoint.getDescription());
waypoint1.setImg(waypoint.getImg()); waypoint1.setImg(waypoint.getImg());
waypoint1.setLocationId(waypoint.getLocationId()); waypoint1.setLocationName(waypoint.getLocationName());
return waypointRepository.save(waypoint1); return waypointRepository.save(waypoint1);
} else { } else {