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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user