fix non tanto fix di springBoot
This commit is contained in:
@@ -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<List<User>> getAllUsers() {
|
||||
List<User> users = userService.getAllUsers();
|
||||
return new ResponseEntity<>(users, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<User> 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<User> createUser(@RequestBody User user) {
|
||||
User createdUser = userService.createUser(user);
|
||||
return new ResponseEntity<>(createdUser, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<User> 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<Void> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
20
src/main/java/ch/progetto152/Progetto152Application.java
Normal file
20
src/main/java/ch/progetto152/Progetto152Application.java
Normal file
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package ch.progetto152.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import jakarta.persistence.*;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ch.progetto152.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
|
||||
32
src/main/java/ch/progetto152/services/UserService.java
Normal file
32
src/main/java/ch/progetto152/services/UserService.java
Normal file
@@ -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<User> 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;
|
||||
}
|
||||
}
|
||||
4
src/main/resources/application.properties
Normal file
4
src/main/resources/application.properties
Normal file
@@ -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
|
||||
@@ -1,25 +0,0 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
|
||||
<!-- a SessionFactory instance listed as /jndi/name -->
|
||||
<session-factory>
|
||||
<property name="hibernate.connection.username">root</property>
|
||||
|
||||
<property name="hibernate.connection.password">Admin123</property>
|
||||
|
||||
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/ICT</property>
|
||||
|
||||
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
|
||||
|
||||
<property name="hibernate.show_sql">false</property>
|
||||
|
||||
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
|
||||
|
||||
|
||||
</session-factory>
|
||||
|
||||
</hibernate-configuration>
|
||||
@@ -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)
|
||||
)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user