|
|
@ -3,13 +3,17 @@ package com.example.urbanbazaar.controller; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
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.GetMapping; |
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
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.User; |
|
|
|
|
|
import com.example.urbanbazaar.model.UserLogin; |
|
|
import com.example.urbanbazaar.repository.UserRepository; |
|
|
import com.example.urbanbazaar.repository.UserRepository; |
|
|
|
|
|
|
|
|
@RestController |
|
|
@RestController |
|
|
@ -32,4 +36,19 @@ public class UserController { |
|
|
public User findUserById(@PathVariable int userId) { |
|
|
public User findUserById(@PathVariable int userId) { |
|
|
return repo.findById(userId).get(); |
|
|
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); |
|
|
|
|
|
} |
|
|
} |
|
|
} |