Browse Source

updated sql schema

master
Gowrisankar J g 4 years ago
parent
commit
fa5671b3f2
4 changed files with 64 additions and 1 deletions
  1. 19
      UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/controller/UserController.java
  2. 28
      UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/model/UserLogin.java
  3. 5
      UB_UserServiceProxy/src/main/java/com/example/urbanbazaar/repository/UserRepository.java
  4. 13
      grocery_db_tables.sql

19
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<String> userLogin(@RequestBody UserLogin user) {
User currentUser = repo.findByuserfirstname(user.getUserfirstname());
if(currentUser == null)
return new ResponseEntity<String>("User doesn't exist. Please create a new account.", HttpStatus.NOT_FOUND);
if(!currentUser.getUserpassword().equals(user.getUserpassword()))
return new ResponseEntity<String>("Password mismatch.", HttpStatus.BAD_REQUEST);
return new ResponseEntity<String>("Login success !!", HttpStatus.OK);
}
}

28
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() {}
}

5
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<User, Integer> {
// @Query(value="select * from user where UserFirstName=?1" , nativeQuery=true)
public User findByuserfirstname(String username);
}

13
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';

Loading…
Cancel
Save