diff --git a/inventory-manager/src/components/user/DeleteUser.jsx b/inventory-manager/src/components/user/DeleteUser.jsx index 1c38f441fe9a6ff417c5a83431a22be8bcc1c0f0..ac4b9cdc641af8153bb2e6dc4b7b69128818c930 100644 --- a/inventory-manager/src/components/user/DeleteUser.jsx +++ b/inventory-manager/src/components/user/DeleteUser.jsx @@ -7,12 +7,22 @@ export const DeleteUser = () => { const handleSubmit = (e) => { e.preventDefault(); - Axios.post("http://localhost:8080/user/delete", { - email: email, + Axios.delete("http://localhost:8080/user/delete", { + headers: {}, + data: { + email: email + } }).then((response) => { console.log(response); }); - }; + }; + + // Axios.delete("http://localhost:8080/user/delete", { + // email: email, + // }).then((response) => { + // console.log(response); + // }); + // }; return ( <div className="auth-form-container"> diff --git a/inventory-manager/src/components/user/Login.jsx b/inventory-manager/src/components/user/Login.jsx index 3891a0a993f68d144bc084ef38beca37213f3015..694d9a729e8b9aeaee5ab98937e05cdb1815608c 100644 --- a/inventory-manager/src/components/user/Login.jsx +++ b/inventory-manager/src/components/user/Login.jsx @@ -1,4 +1,5 @@ import React, { useState } from "react"; +import Axios from "axios"; export const Login = (props) => { const [email, setEmail] = useState(""); @@ -8,6 +9,7 @@ export const Login = (props) => { e.preventDefault(); console.log(email); console.log(pass); + }; return ( diff --git a/inventory-manager/src/components/user/Register.jsx b/inventory-manager/src/components/user/Register.jsx index 811a646595f87dcf586edaa2acc67e47d5d81ae3..83f7abd5af541dc955bad6aeefb4fb1ac4ad4191 100644 --- a/inventory-manager/src/components/user/Register.jsx +++ b/inventory-manager/src/components/user/Register.jsx @@ -10,7 +10,6 @@ export const Register = (props) => { const handleSubmit = (e) => { e.preventDefault(); - Axios.post("http://localhost:8080/user/add", { email: email, lname: lname, diff --git a/inventory-manager/src/components/user/UpdatePassword.jsx b/inventory-manager/src/components/user/UpdatePassword.jsx index 52eb0c6e7767feb36d07d0f94e3e820e7f449dd4..a97b7d32db657362d1285ef04755c57824a0bdab 100644 --- a/inventory-manager/src/components/user/UpdatePassword.jsx +++ b/inventory-manager/src/components/user/UpdatePassword.jsx @@ -8,7 +8,7 @@ export const UpdatePassword = () => { const handleSubmit = (e) => { e.preventDefault(); - Axios.post("http://localhost:8080/user/updatepass", { + Axios.put("http://localhost:8080/user/changepass", { email: email, password: pass, }).then((response) => { diff --git a/src/main/java/com/example/accessingdatamysql/MainController.java b/src/main/java/com/example/accessingdatamysql/MainController.java index 6a1c0b3294b8f8d6e17ce12a48cc5052ab33be73..9e226655bdef9125834bf786aba937a376fb7939 100644 --- a/src/main/java/com/example/accessingdatamysql/MainController.java +++ b/src/main/java/com/example/accessingdatamysql/MainController.java @@ -9,7 +9,8 @@ import org.springframework.web.bind.annotation.*; import java.util.Map; import java.util.Optional; -@Controller // This means that this class is a Controller +@CrossOrigin +@RestController // This means that this class is a Controller @RequestMapping(path="/user") // This means URL's start with /demo (after Application path) public class MainController { @Autowired // This means to get the bean called userRepository @@ -60,18 +61,27 @@ public class MainController { } @GetMapping(path = "/user") - public @ResponseBody Optional<User> getUser(@RequestBody String email) + public @ResponseBody Optional<User> getUser(@RequestBody Map<String, String> json) { + String email = json.get("email"); return userRepository.findById(email); } @DeleteMapping(path = "/delete") - public @ResponseBody User deleteUser(@RequestBody String email) + public @ResponseBody User deleteUser(@RequestBody Map<String, String> json) { User found = null; - found = userRepository.findById(email).get(); - if (found != null) + String email = json.get("email"); + Optional<User> optionalUser = userRepository.findById(email); + + if (optionalUser.isPresent()) + { + System.out.println("in if statement"); + found = optionalUser.get(); userRepository.deleteById(email); - return found; + + return found; + } + return null; } } \ No newline at end of file diff --git a/src/main/java/com/example/accessingdatamysql/User.java b/src/main/java/com/example/accessingdatamysql/User.java index 65ba1629b6364c7fc3e33ab013f971aa476a5970..b5e9a76437417b765aa700017a66206d96558cc0 100644 --- a/src/main/java/com/example/accessingdatamysql/User.java +++ b/src/main/java/com/example/accessingdatamysql/User.java @@ -31,11 +31,11 @@ public class User { this.password = password; } - public Integer getPhoneNumber() { + public String getPhoneNumber() { return phoneNumber; } - public void setPhoneNumber(Integer phoneNumber) { + public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } @@ -46,7 +46,7 @@ public class User { private String password; - private Integer phoneNumber; + private String phoneNumber; @Id @Column(nullable = false) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9dca1e157892d572a9afe5a7b1ac4084aa26316f..0855ee3cbfa77172488d42b827b9dfd6d6e0ff83 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,6 +2,6 @@ spring.jpa.hibernate.ddl-auto=create spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/inventory spring.datasource.username=root -spring.datasource.password=czarthak +spring.datasource.password=CSD@mysql-1872 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver #spring.jpa.show-sql: true \ No newline at end of file