@RestController
@RequestMapping("/api/person")
public class PersonApiController {
// @Autowired
// private JwtTokenUtil jwtGen;
/*
#### RESTful API ####
Resource: https://spring.io/guides/gs/rest-service/
*/
// Autowired enables Control to connect POJO Object through JPA
@Autowired
private PersonJpaRepository repository;
private PersonDetailsService sign_up_repository;
/*
GET List of People
*/
@GetMapping("/")
public ResponseEntity<List<Person>> getPeople() {
return new ResponseEntity<>( repository.findAllByOrderByNameAsc(), HttpStatus.OK);
}
/*
GET individual Person using ID
*/
@GetMapping("/{id}")
public ResponseEntity<Person> getPerson(@PathVariable long id) {
Optional<Person> optional = repository.findById(id);
if (optional.isPresent()) { // Good ID
Person person = optional.get(); // value from findByID
return new ResponseEntity<>(person, HttpStatus.OK); // OK HTTP response: status code, headers, and body
}
// Bad ID
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
@PostMapping( "/post")
public ResponseEntity<Object> postPerson(@RequestBody final Map<String,String> map) {
String email = (String) map.get("email");
String password = (String) map.get("password");
String name = (String) map.get("name");
String dobString = (String) map.get("dob");
Date dob;
try {
dob = new SimpleDateFormat("MM-dd-yyyy").parse(dobString);
} catch (Exception e) {
return new ResponseEntity<>(dobString +" error; try MM-dd-yyyy", HttpStatus.BAD_REQUEST);
}
// A person object WITHOUT ID will create a new record with default roles as student
String passwordEncrypt = BCrypt.hashpw(password, BCrypt.gensalt());
Person newUser = new Person(email, passwordEncrypt, name, dob);
repository.save(newUser);
//should hopefully create new user
return new ResponseEntity<>(newUser, HttpStatus.CREATED);
}
Lost points for not having update and delete in the frontend
Lost points for not having a video
Lost points for not having 75% people having full stack
Individual Review Ticket Github Analytics More Github Analytics Backend Commits Team Review Ticket
Some Tangibles
BackEnd Tangibles
Security:
Person:
Login"
Signup:
NATM