From 22aeac0b03b75cc7fff210d8c2d4c88b60799ff9 Mon Sep 17 00:00:00 2001 From: grata Date: Wed, 26 Apr 2023 16:20:21 +0200 Subject: [PATCH] fix non tanto fix di springBoot --- .idea/misc.xml | 3 + .idea/vcs.xml | 1 - HELP.md | 25 ++++ pom.xml | 118 ++++++++++-------- src/main/java/ch/progetto152/Controller.java | 56 --------- src/main/java/ch/progetto152/Main.java | 18 --- .../progetto152/Progetto152Application.java | 20 +++ .../java/ch/progetto152/entity/Location.java | 2 +- .../progetto152/entity/LocationVisited.java | 6 +- src/main/java/ch/progetto152/entity/User.java | 4 +- .../java/ch/progetto152/entity/Waypoints.java | 3 +- .../ch/progetto152/services/UserService.java | 32 +++++ src/main/resources/application.properties | 4 + src/main/resources/hibernate.cfg.xml | 25 ---- src/main/resources/mysql.sql | 43 ------- src/main/resources/restApi.txt | 16 --- 16 files changed, 160 insertions(+), 216 deletions(-) create mode 100644 HELP.md delete mode 100644 src/main/java/ch/progetto152/Controller.java delete mode 100644 src/main/java/ch/progetto152/Main.java create mode 100644 src/main/java/ch/progetto152/Progetto152Application.java create mode 100644 src/main/java/ch/progetto152/services/UserService.java create mode 100644 src/main/resources/application.properties delete mode 100644 src/main/resources/hibernate.cfg.xml delete mode 100644 src/main/resources/mysql.sql delete mode 100644 src/main/resources/restApi.txt diff --git a/.idea/misc.xml b/.idea/misc.xml index e8d124d..fcd71ce 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -10,4 +10,7 @@ + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 9f3e7b6..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,6 +2,5 @@ - \ No newline at end of file diff --git a/HELP.md b/HELP.md new file mode 100644 index 0000000..ed7e4ec --- /dev/null +++ b/HELP.md @@ -0,0 +1,25 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.0.6/maven-plugin/reference/html/) +* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.0.6/maven-plugin/reference/html/#build-image) +* [Spring Data JPA](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#data.sql.jpa-and-spring-data) +* [Spring Web](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#web) +* [Spring Session](https://docs.spring.io/spring-session/reference/) +* [Rest Repositories](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#howto.data-access.exposing-spring-data-repositories-as-rest) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/) +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) +* [Accessing JPA Data with REST](https://spring.io/guides/gs/accessing-data-rest/) +* [Accessing Neo4j Data with REST](https://spring.io/guides/gs/accessing-neo4j-data-rest/) +* [Accessing MongoDB Data with REST](https://spring.io/guides/gs/accessing-mongodb-data-rest/) + diff --git a/pom.xml b/pom.xml index 8d3075c..8a001cb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,55 +1,71 @@ - - 4.0.0 + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.6 + + + ch + progetto152 + 0.0.1-SNAPSHOT + progetto152 + Progetto 152 + + 17 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-data-rest + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.session + spring-session-core + - org.example - prova - 1.0-SNAPSHOT + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + - - 17 - 17 - UTF-8 - - - - - org.springframework.boot - spring-boot-starter-web - 2.7.11 - + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + - - - org.springframework.boot - spring-boot-starter-data-jpa - 2.7.11 - - - mysql - mysql-connector-java - 8.0.28 - - - javax.persistence - javax.persistence-api - 2.2 - - - org.hibernate - hibernate-core - 5.3.20.Final - - - org.springframework - spring-web - 5.3.27 - - - - - - - \ No newline at end of file + diff --git a/src/main/java/ch/progetto152/Controller.java b/src/main/java/ch/progetto152/Controller.java deleted file mode 100644 index 949c47f..0000000 --- a/src/main/java/ch/progetto152/Controller.java +++ /dev/null @@ -1,56 +0,0 @@ -package ch.progetto152; - - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -@RestController -@RequestMapping("/api/users") -public class Controller { - - @Autowired - private UserService userService; - - @GetMapping - public ResponseEntity> getAllUsers() { - List users = userService.getAllUsers(); - return new ResponseEntity<>(users, HttpStatus.OK); - } - - @GetMapping("/{id}") - public ResponseEntity getUserById(@PathVariable("id") Long id) { - User user = userService.getUserById(id); - if (user != null) { - return new ResponseEntity<>(user, HttpStatus.OK); - } else { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); - } - } - - @PostMapping - public ResponseEntity createUser(@RequestBody User user) { - User createdUser = userService.createUser(user); - return new ResponseEntity<>(createdUser, HttpStatus.CREATED); - } - - @PutMapping("/{id}") - public ResponseEntity updateUser(@PathVariable("id") Long id, @RequestBody User user) { - User updatedUser = userService.updateUser(id, user); - if (updatedUser != null) { - return new ResponseEntity<>(updatedUser, HttpStatus.OK); - } else { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); - } - } - - @DeleteMapping("/{id}") - public ResponseEntity deleteUser(@PathVariable("id") Long id) { - boolean deleted = userService.deleteUser(id); - if (deleted) { - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } else { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); - } - } -} diff --git a/src/main/java/ch/progetto152/Main.java b/src/main/java/ch/progetto152/Main.java deleted file mode 100644 index 7b6889f..0000000 --- a/src/main/java/ch/progetto152/Main.java +++ /dev/null @@ -1,18 +0,0 @@ -package ch.progetto152; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class Main { - public static void main(String[] args) { - SpringApplication.run(Main.class, args); - } - - @Bean - public Controller controller() { - return new Controller(); - } - -} \ No newline at end of file diff --git a/src/main/java/ch/progetto152/Progetto152Application.java b/src/main/java/ch/progetto152/Progetto152Application.java new file mode 100644 index 0000000..d094331 --- /dev/null +++ b/src/main/java/ch/progetto152/Progetto152Application.java @@ -0,0 +1,20 @@ +package ch.progetto152; + +import ch.progetto152.controller.UserController; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class Progetto152Application { + + public static void main(String[] args) { + SpringApplication.run(Progetto152Application.class, args); + } + + @Bean + public UserController newController() { + return new UserController(); + } + +} diff --git a/src/main/java/ch/progetto152/entity/Location.java b/src/main/java/ch/progetto152/entity/Location.java index 69c5291..b4dd0ea 100644 --- a/src/main/java/ch/progetto152/entity/Location.java +++ b/src/main/java/ch/progetto152/entity/Location.java @@ -1,6 +1,6 @@ package ch.progetto152.entity; -import javax.persistence.*; +import jakarta.persistence.*; import java.util.Objects; @Entity diff --git a/src/main/java/ch/progetto152/entity/LocationVisited.java b/src/main/java/ch/progetto152/entity/LocationVisited.java index 80ee32f..439d64d 100644 --- a/src/main/java/ch/progetto152/entity/LocationVisited.java +++ b/src/main/java/ch/progetto152/entity/LocationVisited.java @@ -1,11 +1,13 @@ package ch.progetto152.entity; -import javax.persistence.*; +import jakarta.persistence.*; + import java.util.Objects; @Entity -@Table(name = "LocationVisited", schema = "Progetto152", catalog = "") public class LocationVisited{ + + @Id @Basic @Column(name = "userId") private int userId; diff --git a/src/main/java/ch/progetto152/entity/User.java b/src/main/java/ch/progetto152/entity/User.java index d55c65e..39b2d11 100644 --- a/src/main/java/ch/progetto152/entity/User.java +++ b/src/main/java/ch/progetto152/entity/User.java @@ -1,10 +1,10 @@ package ch.progetto152.entity; -import javax.persistence.*; +import jakarta.persistence.*; + import java.util.Objects; @Entity -@Table(name = "User", schema = "Progetto152", catalog = "") public class User { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id diff --git a/src/main/java/ch/progetto152/entity/Waypoints.java b/src/main/java/ch/progetto152/entity/Waypoints.java index 02802bb..6d6fa7f 100644 --- a/src/main/java/ch/progetto152/entity/Waypoints.java +++ b/src/main/java/ch/progetto152/entity/Waypoints.java @@ -1,6 +1,7 @@ package ch.progetto152.entity; -import javax.persistence.*; +import jakarta.persistence.*; + import java.util.Objects; @Entity diff --git a/src/main/java/ch/progetto152/services/UserService.java b/src/main/java/ch/progetto152/services/UserService.java new file mode 100644 index 0000000..ebf92f0 --- /dev/null +++ b/src/main/java/ch/progetto152/services/UserService.java @@ -0,0 +1,32 @@ +package ch.progetto152.services; + + +import ch.progetto152.entity.User; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class UserService { + + + public List getAllUsers() { + return null; + } + + public User getUserByIdService(Long id) { + return null; + } + + public User createUser(User user) { + return null; + } + + public User updateUser(Long id, User user) { + return null; + } + + public boolean deleteUser(Long id) { + return false; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..d9adbbc --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url=jdbc:mysql://localhost:3306/Progetto152 +spring.datasource.username=root +spring.datasource.password=Admin123 \ No newline at end of file diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml deleted file mode 100644 index a62c02d..0000000 --- a/src/main/resources/hibernate.cfg.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - root - - Admin123 - - jdbc:mysql://localhost:3306/ICT - - com.mysql.cj.jdbc.Driver - - false - - org.hibernate.dialect.MySQL5Dialect - - - - - diff --git a/src/main/resources/mysql.sql b/src/main/resources/mysql.sql deleted file mode 100644 index 41f02aa..0000000 --- a/src/main/resources/mysql.sql +++ /dev/null @@ -1,43 +0,0 @@ -drop database if exists Progetto152; -create database if not exists Progetto152; -use Progetto152; - - - -create table if not exists Location -( - id int auto_increment not null, - location varchar(255) not null unique, - region varchar(3) not null, - lat double not null, - lon double not null, - primary key (id) -); - -create table if not exists Waypoints -( - id int not null auto_increment, - name varchar(10) not null, - lat double not null, - lon double not null, - description varchar(1000) not null, - img varchar(1000) not null, - LocationId int not null, - primary key (id), - foreign key (LocationId) references Location (id) -); - -create table if not exists User( - id int not null auto_increment, - name varchar(45) not null, - username varchar(100) not null, - password varchar(100) not null, - primary key (id) -); - -create table if not exists LocationVisited( - userId int not null, - locationid int not null, - foreign key (userId) references User(id), - foreign key (locationid) references Location(id) -) \ No newline at end of file diff --git a/src/main/resources/restApi.txt b/src/main/resources/restApi.txt deleted file mode 100644 index 4265960..0000000 --- a/src/main/resources/restApi.txt +++ /dev/null @@ -1,16 +0,0 @@ -get: - progetto152/locations - progetto152/location/{location} - progetto152/waypoints/{location} - progetto152/waypoint/{location}/{id} - maybe: - progetto152/user/{user} - progetto152/user/{user}/location - -post: - progetto152/location - progetto152/waypoint - maybe: - progetto152/user - progetto152/user/{user}/location -