diff --git a/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/controller/UserController.java b/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/controller/UserController.java index 255be4d..835536b 100644 --- a/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/controller/UserController.java +++ b/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/controller/UserController.java @@ -3,13 +3,17 @@ package com.example.urbanbazaar.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.function.EntityResponse; import com.example.urbanbazaar.model.User; +import com.example.urbanbazaar.model.UserLogin; import com.example.urbanbazaar.repository.UserRepository; @RestController @@ -32,4 +36,19 @@ public class UserController { public User findUserById(@PathVariable int userId) { return repo.findById(userId).get(); } + + @GetMapping("/findUserByName/{name}") + public User findUserByName(@PathVariable String name) { + return repo.findByuserfirstname(name); + } + + @PostMapping("/login") + public ResponseEntity userLogin(@RequestBody UserLogin user) { + User currentUser = repo.findByuserfirstname(user.getUserfirstname()); + if(currentUser == null) + return new ResponseEntity("User doesn't exist. Please create a new account.", HttpStatus.NOT_FOUND); + if(!currentUser.getUserpassword().equals(user.getUserpassword())) + return new ResponseEntity("Password mismatch.", HttpStatus.BAD_REQUEST); + return new ResponseEntity("Login success !!", HttpStatus.OK); + } } diff --git a/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/model/UserLogin.java b/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/model/UserLogin.java new file mode 100644 index 0000000..798823c --- /dev/null +++ b/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/model/UserLogin.java @@ -0,0 +1,28 @@ +package com.example.urbanbazaar.model; + +public class UserLogin { + + private String userpassword; + private String userfirstname; + + public String getUserpassword() { + return userpassword; + } + public void setUserpassword(String userpassword) { + this.userpassword = userpassword; + } + public String getUserfirstname() { + return userfirstname; + } + public void setUserfirstname(String userfirstname) { + this.userfirstname = userfirstname; + } + + public UserLogin(String userpassword, String userfirstname) { + super(); + this.userpassword = userpassword; + this.userfirstname = userfirstname; + } + + public UserLogin() {} +} diff --git a/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/repository/UserRepository.java b/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/repository/UserRepository.java index a8732b9..6a2ed7a 100644 --- a/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/repository/UserRepository.java +++ b/UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/repository/UserRepository.java @@ -1,10 +1,13 @@ package com.example.urbanbazaar.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import com.example.urbanbazaar.model.User; public interface UserRepository extends JpaRepository { - + + // @Query(value="select * from user where UserFirstName=?1" , nativeQuery=true) + public User findByuserfirstname(String username); } diff --git a/grocery_db_tables.sql b/grocery_db_tables.sql index 85d6906..023e238 100644 --- a/grocery_db_tables.sql +++ b/grocery_db_tables.sql @@ -156,6 +156,19 @@ INSERT INTO members VALUES(100, 3, "Shyam", 10,"1234598745", 800); select * from members; +-- Cart Table Schema +CREATE TABLE IF NOT EXISTS `cart` ( + `CartID` int NOT NULL, + `UserID` int NOT NULL, + `OrderID` int NOT NULL, + `ProductName` varchar(50) NOT NULL, + `Quantity` int NOT NULL, + PRIMARY KEY (`CartID`), + FOREIGN KEY (`UserID`) REFERENCES users(`UserID`) +); + +ALTER TABLE cart AUTO_INCREMENT = 1000; + ----------------------------------------------------------------------------------------- drop user 'testuser';