diff --git a/src/main/java/ch/progetto152/Progetto152Application.java b/src/main/java/ch/progetto152/Progetto152Application.java index e7467c1..a9d4470 100644 --- a/src/main/java/ch/progetto152/Progetto152Application.java +++ b/src/main/java/ch/progetto152/Progetto152Application.java @@ -1,9 +1,7 @@ package ch.progetto152; -import ch.progetto152.controller.Controller; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; @SpringBootApplication public class Progetto152Application { @@ -12,6 +10,4 @@ public class Progetto152Application { SpringApplication.run(Progetto152Application.class, args); } - - } diff --git a/src/main/java/ch/progetto152/controller/LocationController.java b/src/main/java/ch/progetto152/controller/LocationController.java index 737346f..c2383df 100644 --- a/src/main/java/ch/progetto152/controller/LocationController.java +++ b/src/main/java/ch/progetto152/controller/LocationController.java @@ -1,6 +1,6 @@ package ch.progetto152.controller; -import ch.progetto152.entity.Location; +import ch.progetto152.entity.LocationEntity; import ch.progetto152.services.LocationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -20,14 +20,14 @@ public class LocationController { } @GetMapping("/get/all") - public ResponseEntity> getAllLocations() { - List Locations = locationService.getAllLocations(); + public ResponseEntity> getAllLocations() { + List Locations = locationService.getAllLocations(); return new ResponseEntity<>(Locations, HttpStatus.OK); } @GetMapping("/get/{id}") - public ResponseEntity getLocationById(@PathVariable("id") Long id) { - Location location = locationService.getLocationByIdService(id); + public ResponseEntity getLocationById(@PathVariable("id") Long id) { + LocationEntity location = locationService.getLocationByIdService(id); if (location != null) { return new ResponseEntity<>(location, HttpStatus.OK); } else { @@ -36,8 +36,8 @@ public class LocationController { } @GetMapping("/get/name/{name}") - public ResponseEntity getLocationByName(@PathVariable("name") String name) { - Location location = locationService.getLocationByNameService(name); + public ResponseEntity getLocationByName(@PathVariable("name") String name) { + LocationEntity location = locationService.getLocationByNameService(name); if (location != null) { return new ResponseEntity<>(location, HttpStatus.OK); } else { @@ -46,14 +46,14 @@ public class LocationController { } @PostMapping("/create/{id}") - public ResponseEntity createLocation(@RequestBody Location location) { - Location createdLocation = locationService.createLocation(location); + public ResponseEntity createLocation(@RequestBody LocationEntity location) { + LocationEntity createdLocation = locationService.createLocation(location); return new ResponseEntity<>(createdLocation, HttpStatus.CREATED); } @PutMapping("/put/{id}") - public ResponseEntity updateLocation(@PathVariable("id") Long id, @RequestBody Location location) { - Location location1 = locationService.updateLocation(id, location); + public ResponseEntity updateLocation(@PathVariable("id") Long id, @RequestBody LocationEntity location) { + LocationEntity location1 = locationService.updateLocation(id, location); if (location1 != null) { return new ResponseEntity<>(location1, HttpStatus.OK); } else { diff --git a/src/main/java/ch/progetto152/controller/UserController.java b/src/main/java/ch/progetto152/controller/UserController.java index 30b2255..8e864fb 100644 --- a/src/main/java/ch/progetto152/controller/UserController.java +++ b/src/main/java/ch/progetto152/controller/UserController.java @@ -1,7 +1,7 @@ package ch.progetto152.controller; -import ch.progetto152.entity.User; +import ch.progetto152.entity.UserEntity; import ch.progetto152.services.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -14,7 +14,6 @@ import java.util.List; @RequestMapping("/api/users") public class UserController { - private final UserService userService; @Autowired @@ -23,14 +22,14 @@ public class UserController { } @GetMapping("/get/all") - public ResponseEntity> getAllUsers() { - List users = userService.getAllUsers(); + public ResponseEntity> getAllUsers() { + List users = userService.getAllUsers(); return new ResponseEntity<>(users, HttpStatus.OK); } @GetMapping("/get/{id}") - public ResponseEntity getUserById(@PathVariable("id") Long id) { - User user = userService.getUserByIdService(id); + public ResponseEntity getUserById(@PathVariable("id") Long id) { + UserEntity user = userService.getUserByIdService(id); if (user != null) { return new ResponseEntity<>(user, HttpStatus.OK); } else { @@ -39,8 +38,8 @@ public class UserController { } @GetMapping("/get/name/{name}") - public ResponseEntity getUserByName(@PathVariable("name") String name) { - User user = userService.getUserByNameService(name); + public ResponseEntity getUserByName(@PathVariable("name") String name) { + UserEntity user = userService.getUserByNameService(name); if (user != null) { return new ResponseEntity<>(user, HttpStatus.OK); } else { @@ -49,8 +48,8 @@ public class UserController { } @GetMapping("/get/username/{username}") - public ResponseEntity getUserByUsername(@PathVariable("username") String username) { - User user = userService.getUserByUsernameService(username); + public ResponseEntity getUserByUsername(@PathVariable("username") String username) { + UserEntity user = userService.getUserByUsernameService(username); if (user != null) { return new ResponseEntity<>(user, HttpStatus.OK); } else { @@ -59,14 +58,14 @@ public class UserController { } @PostMapping("/create/{id}") - public ResponseEntity createUser(@RequestBody User user) { - User createdUser = userService.createUser(user); + public ResponseEntity createUser(@RequestBody UserEntity user) { + UserEntity createdUser = userService.createUser(user); return new ResponseEntity<>(createdUser, HttpStatus.CREATED); } @PutMapping("/put/{id}") - public ResponseEntity updateUser(@PathVariable("id") Long id, @RequestBody User user) { - User updatedUser = userService.updateUser(id, user); + public ResponseEntity updateUser(@PathVariable("id") Long id, @RequestBody UserEntity user) { + UserEntity updatedUser = userService.updateUser(id, user); if (updatedUser != null) { return new ResponseEntity<>(updatedUser, HttpStatus.OK); } else { diff --git a/src/main/java/ch/progetto152/controller/WaypointController.java b/src/main/java/ch/progetto152/controller/WaypointController.java index b65a93c..32ad21f 100644 --- a/src/main/java/ch/progetto152/controller/WaypointController.java +++ b/src/main/java/ch/progetto152/controller/WaypointController.java @@ -1,6 +1,6 @@ package ch.progetto152.controller; -import ch.progetto152.entity.Waypoints; +import ch.progetto152.entity.WaypointsEntity; import ch.progetto152.services.WaypointService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -20,14 +20,14 @@ public class WaypointController { } @GetMapping("/get/all") - public ResponseEntity> getAllWaypoints() { - List waypoint = waypointService.getAllWaypoints(); + public ResponseEntity> getAllWaypoints() { + List waypoint = waypointService.getAllWaypoints(); return new ResponseEntity<>(waypoint, HttpStatus.OK); } @GetMapping("/get/{id}") - public ResponseEntity getWaypointById(@PathVariable("id") Long id) { - Waypoints waypoint = waypointService.getWaypointByIdService(id); + public ResponseEntity getWaypointById(@PathVariable("id") Long id) { + WaypointsEntity waypoint = waypointService.getWaypointByIdService(id); if (waypoint != null) { return new ResponseEntity<>(waypoint, HttpStatus.OK); } else { @@ -36,8 +36,8 @@ public class WaypointController { } @GetMapping("/get/name/{name}") - public ResponseEntity getWaypointByName(@PathVariable("name") String name) { - Waypoints waypoint = waypointService.getWaypointByNameService(name); + public ResponseEntity getWaypointByName(@PathVariable("name") String name) { + WaypointsEntity waypoint = waypointService.getWaypointByNameService(name); if (waypoint != null) { return new ResponseEntity<>(waypoint, HttpStatus.OK); } else { @@ -46,14 +46,14 @@ public class WaypointController { } @PostMapping("/create/{id}") - public ResponseEntity createWaypoint(@RequestBody Waypoints waypoint) { - Waypoints createdWaypoint = waypointService.createWaypoint(waypoint); + public ResponseEntity createWaypoint(@RequestBody WaypointsEntity waypoint) { + WaypointsEntity createdWaypoint = waypointService.createWaypoint(waypoint); return new ResponseEntity<>(createdWaypoint, HttpStatus.CREATED); } @PutMapping("/put/{id}") - public ResponseEntity updateWaypoint(@PathVariable("id") Long id, @RequestBody Waypoints waypoint) { - Waypoints updatedWaypoint = waypointService.updateWaypoint(id, waypoint); + public ResponseEntity updateWaypoint(@PathVariable("id") Long id, @RequestBody WaypointsEntity waypoint) { + WaypointsEntity updatedWaypoint = waypointService.updateWaypoint(id, waypoint); if (updatedWaypoint != null) { return new ResponseEntity<>(updatedWaypoint, HttpStatus.OK); } else { diff --git a/src/main/java/ch/progetto152/entity/Location.java b/src/main/java/ch/progetto152/entity/LocationEntity.java similarity index 72% rename from src/main/java/ch/progetto152/entity/Location.java rename to src/main/java/ch/progetto152/entity/LocationEntity.java index b4dd0ea..2132cb5 100644 --- a/src/main/java/ch/progetto152/entity/Location.java +++ b/src/main/java/ch/progetto152/entity/LocationEntity.java @@ -1,16 +1,14 @@ package ch.progetto152.entity; import jakarta.persistence.*; + import java.util.Objects; @Entity @Table(name = "Location", schema = "Progetto152", catalog = "") -public class Location { +public class LocationEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id - @Column(name = "id") - private int id; - @Basic @Column(name = "location") private String location; @Basic @@ -23,14 +21,6 @@ public class Location { @Column(name = "lon") private double lon; - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - public String getLocation() { return location; } @@ -71,12 +61,12 @@ public class Location { if (o == null || getClass() != o.getClass()) { return false; } - Location that = (Location) 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); + LocationEntity that = (LocationEntity) o; + return Double.compare(that.lat, lat) == 0 && Double.compare(that.lon, lon) == 0 && Objects.equals(location, that.location) && Objects.equals(region, that.region); } @Override public int hashCode() { - return Objects.hash(id, location, region, lat, lon); + return Objects.hash(location, region, lat, lon); } } diff --git a/src/main/java/ch/progetto152/entity/User.java b/src/main/java/ch/progetto152/entity/UserEntity.java similarity index 63% rename from src/main/java/ch/progetto152/entity/User.java rename to src/main/java/ch/progetto152/entity/UserEntity.java index 87157a3..b9d4848 100644 --- a/src/main/java/ch/progetto152/entity/User.java +++ b/src/main/java/ch/progetto152/entity/UserEntity.java @@ -1,20 +1,14 @@ package ch.progetto152.entity; import jakarta.persistence.*; -import lombok.*; import java.util.Objects; @Entity -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -@ToString -@Table -public class User { - @Id +@Table(name = "User", schema = "Progetto152", catalog = "") +public class UserEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id @Column(name = "id") private int id; @Basic @@ -27,9 +21,35 @@ public class User { @Column(name = "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; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { this.password = password; } @@ -41,7 +61,7 @@ public class User { if (o == null || getClass() != o.getClass()) { 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); } diff --git a/src/main/java/ch/progetto152/entity/Waypoints.java b/src/main/java/ch/progetto152/entity/WaypointsEntity.java similarity index 76% rename from src/main/java/ch/progetto152/entity/Waypoints.java rename to src/main/java/ch/progetto152/entity/WaypointsEntity.java index 6d6fa7f..5e402fd 100644 --- a/src/main/java/ch/progetto152/entity/Waypoints.java +++ b/src/main/java/ch/progetto152/entity/WaypointsEntity.java @@ -6,7 +6,7 @@ import java.util.Objects; @Entity @Table(name = "Waypoints", schema = "Progetto152", catalog = "") -public class Waypoints { +public class WaypointsEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id @Column(name = "id") @@ -27,8 +27,8 @@ public class Waypoints { @Column(name = "img") private String img; @Basic - @Column(name = "LocationId") - private int locationId; + @Column(name = "locationName") + private String locationName; public int getId() { return id; @@ -78,12 +78,12 @@ public class Waypoints { this.img = img; } - public int getLocationId() { - return locationId; + public String getLocationName() { + return locationName; } - public void setLocationId(int locationId) { - this.locationId = locationId; + public void setLocationName(String locationName) { + this.locationName = locationName; } @Override @@ -94,12 +94,12 @@ public class Waypoints { if (o == null || getClass() != o.getClass()) { return false; } - Waypoints that = (Waypoints) 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); + WaypointsEntity that = (WaypointsEntity) o; + 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 public int hashCode() { - return Objects.hash(id, name, lat, lon, description, img, locationId); + return Objects.hash(id, name, lat, lon, description, img, locationName); } } diff --git a/src/main/java/ch/progetto152/entity/LocationVisited.java b/src/main/java/ch/progetto152/entity/WaypointsVisitedEntity.java similarity index 52% rename from src/main/java/ch/progetto152/entity/LocationVisited.java rename to src/main/java/ch/progetto152/entity/WaypointsVisitedEntity.java index 439d64d..39fdea2 100644 --- a/src/main/java/ch/progetto152/entity/LocationVisited.java +++ b/src/main/java/ch/progetto152/entity/WaypointsVisitedEntity.java @@ -5,17 +5,16 @@ import jakarta.persistence.*; import java.util.Objects; @Entity -public class LocationVisited{ - - @Id +@Table(name = "WaypointsVisited", schema = "Progetto152", catalog = "") +public class WaypointsVisitedEntity { @Basic + @Id @Column(name = "userId") private int userId; @Basic - @Column(name = "locationid") - private int locationid; @Id - private Long id; + @Column(name = "waypointId") + private int waypointId; public int getUserId() { return userId; @@ -25,12 +24,12 @@ public class LocationVisited{ this.userId = userId; } - public int getLocationid() { - return locationid; + public int getWaypointId() { + return waypointId; } - public void setLocationid(int locationid) { - this.locationid = locationid; + public void setWaypointId(int waypointId) { + this.waypointId = waypointId; } @Override @@ -41,21 +40,12 @@ public class LocationVisited{ if (o == null || getClass() != o.getClass()) { return false; } - LocationVisited that = (LocationVisited) o; - return userId == that.userId && locationid == that.locationid; + WaypointsVisitedEntity that = (WaypointsVisitedEntity) o; + return userId == that.userId && waypointId == that.waypointId; } @Override 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; - } - } diff --git a/src/main/java/ch/progetto152/repository/LocationRepository.java b/src/main/java/ch/progetto152/repository/LocationRepository.java index d37bac5..46f08f8 100644 --- a/src/main/java/ch/progetto152/repository/LocationRepository.java +++ b/src/main/java/ch/progetto152/repository/LocationRepository.java @@ -1,11 +1,11 @@ package ch.progetto152.repository; -import ch.progetto152.entity.Location; +import ch.progetto152.entity.LocationEntity; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; -public interface LocationRepository extends JpaRepository { +public interface LocationRepository extends JpaRepository { - Optional findLocationByLocation(String name); + Optional findLocationByLocation(String name); } diff --git a/src/main/java/ch/progetto152/repository/UserRepository.java b/src/main/java/ch/progetto152/repository/UserRepository.java index 3b04a12..5da9bd0 100644 --- a/src/main/java/ch/progetto152/repository/UserRepository.java +++ b/src/main/java/ch/progetto152/repository/UserRepository.java @@ -1,16 +1,16 @@ package ch.progetto152.repository; -import ch.progetto152.entity.User; +import ch.progetto152.entity.UserEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import java.util.Optional; @Repository -public interface UserRepository extends JpaRepository { +public interface UserRepository extends JpaRepository { - Optional findUserByName(String name); + Optional findUserByName(String name); - Optional findUserByUsername(String username); + Optional findUserByUsername(String username); } diff --git a/src/main/java/ch/progetto152/repository/WaypointRepository.java b/src/main/java/ch/progetto152/repository/WaypointRepository.java index 0e8ce27..462101c 100644 --- a/src/main/java/ch/progetto152/repository/WaypointRepository.java +++ b/src/main/java/ch/progetto152/repository/WaypointRepository.java @@ -1,11 +1,11 @@ package ch.progetto152.repository; -import ch.progetto152.entity.Waypoints; +import ch.progetto152.entity.WaypointsEntity; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; -public interface WaypointRepository extends JpaRepository { +public interface WaypointRepository extends JpaRepository { - Optional findWaypointByName(String name); + Optional findWaypointByName(String name); } diff --git a/src/main/java/ch/progetto152/services/LocationService.java b/src/main/java/ch/progetto152/services/LocationService.java index 8b505cb..9077b76 100644 --- a/src/main/java/ch/progetto152/services/LocationService.java +++ b/src/main/java/ch/progetto152/services/LocationService.java @@ -1,6 +1,6 @@ package ch.progetto152.services; -import ch.progetto152.entity.Location; +import ch.progetto152.entity.LocationEntity; import ch.progetto152.repository.LocationRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,24 +17,24 @@ public class LocationService { this.locationRepository = locationRepository; } - public List getAllLocations() { + public List getAllLocations() { return locationRepository.findAll(); } - public Location getLocationByIdService(Long id) { + public LocationEntity getLocationByIdService(Long id) { return locationRepository.findById(id).orElse(null); } - public Location getLocationByNameService(String name){ + public LocationEntity getLocationByNameService(String name){ return locationRepository.findLocationByLocation(name).orElse(null); } - public Location createLocation(Location Location) { + public LocationEntity createLocation(LocationEntity Location) { return locationRepository.save(Location); } - public Location updateLocation(Long id, Location Location) { - Location location1 = getLocationByIdService(id); + public LocationEntity updateLocation(Long id, LocationEntity Location) { + LocationEntity location1 = getLocationByIdService(id); if (location1 != null) { location1.setLocation(Location.getLocation()); location1.setRegion(Location.getRegion()); diff --git a/src/main/java/ch/progetto152/services/UserService.java b/src/main/java/ch/progetto152/services/UserService.java index d765510..190db03 100644 --- a/src/main/java/ch/progetto152/services/UserService.java +++ b/src/main/java/ch/progetto152/services/UserService.java @@ -1,7 +1,7 @@ package ch.progetto152.services; -import ch.progetto152.entity.User; +import ch.progetto152.entity.UserEntity; import ch.progetto152.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,28 +18,28 @@ public class UserService { this.userRepository = userRepository; } - public List getAllUsers() { + public List getAllUsers() { return userRepository.findAll(); } - public User getUserByIdService(Long id) { + public UserEntity getUserByIdService(Long id) { return userRepository.findById(id).orElse(null); } - public User getUserByNameService(String name){ + public UserEntity getUserByNameService(String name){ return userRepository.findUserByName(name).orElse(null); } - public User getUserByUsernameService(String username){ + public UserEntity getUserByUsernameService(String username){ return userRepository.findUserByUsername(username).orElse(null); } - public User createUser(User user) { + public UserEntity createUser(UserEntity user) { return userRepository.save(user); } - public User updateUser(Long id, User user) { - User user1 = getUserByIdService(id); + public UserEntity updateUser(Long id, UserEntity user) { + UserEntity user1 = getUserByIdService(id); if (user1 != null) { user1.setName(user.getName()); user1.setUsername(user.getUsername()); diff --git a/src/main/java/ch/progetto152/services/WaypointService.java b/src/main/java/ch/progetto152/services/WaypointService.java index 314ee48..361f739 100644 --- a/src/main/java/ch/progetto152/services/WaypointService.java +++ b/src/main/java/ch/progetto152/services/WaypointService.java @@ -1,6 +1,6 @@ package ch.progetto152.services; -import ch.progetto152.entity.Waypoints; +import ch.progetto152.entity.WaypointsEntity; import ch.progetto152.repository.WaypointRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,31 +16,31 @@ public class WaypointService { this.waypointRepository = waypointRepository; } - public List getAllWaypoints() { + public List getAllWaypoints() { return waypointRepository.findAll(); } - public Waypoints getWaypointByIdService(Long id) { + public WaypointsEntity getWaypointByIdService(Long id) { return waypointRepository.findById(id).orElse(null); } - public Waypoints getWaypointByNameService(String name) { + public WaypointsEntity getWaypointByNameService(String name) { return waypointRepository.findWaypointByName(name).orElse(null); } - public Waypoints createWaypoint(Waypoints waypoint) { + public WaypointsEntity createWaypoint(WaypointsEntity waypoint) { return waypointRepository.save(waypoint); } - public Waypoints updateWaypoint(Long id, Waypoints waypoint) { - Waypoints waypoint1 = getWaypointByIdService(id); + public WaypointsEntity updateWaypoint(Long id, WaypointsEntity waypoint) { + WaypointsEntity waypoint1 = getWaypointByIdService(id); if (waypoint1 != null) { waypoint1.setName(waypoint.getName()); waypoint1.setLat(waypoint.getLat()); waypoint1.setLon(waypoint.getLon()); waypoint1.setDescription(waypoint.getDescription()); waypoint1.setImg(waypoint.getImg()); - waypoint1.setLocationId(waypoint.getLocationId()); + waypoint1.setLocationName(waypoint.getLocationName()); return waypointRepository.save(waypoint1); } else {