From c058a04eb8ef270e0d8bbd318f144294127c634a Mon Sep 17 00:00:00 2001 From: Sarthak Shrivastava <sarthaks@vt.edu> Date: Fri, 17 Nov 2023 22:15:15 -0500 Subject: [PATCH] working version, may need to adjust schema and password to run locally --- .../src/components/user/DeleteUser.jsx | 16 +++++++++++--- .../src/components/user/Login.jsx | 2 ++ .../src/components/user/Register.jsx | 1 - .../src/components/user/UpdatePassword.jsx | 2 +- .../accessingdatamysql/MainController.java | 22 ++++++++++++++----- .../com/example/accessingdatamysql/User.java | 6 ++--- src/main/resources/application.properties | 2 +- 7 files changed, 36 insertions(+), 15 deletions(-) diff --git a/inventory-manager/src/components/user/DeleteUser.jsx b/inventory-manager/src/components/user/DeleteUser.jsx index 1c38f44..ac4b9cd 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 3891a0a..694d9a7 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 811a646..83f7abd 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 52eb0c6..a97b7d3 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 6a1c0b3..9e22665 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 65ba162..b5e9a76 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 9dca1e1..0855ee3 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 -- GitLab