PAN-52 Added findByName to the TheoremRepository, and to the TheoremController as well as the corresponding tests, and a foreign key mapping from the proofs table to the corresponding theorem in the theorems table

This commit is contained in:
2019-03-14 12:28:59 -06:00
parent d560f5831f
commit 4d0658a268
4 changed files with 83 additions and 9 deletions
@@ -101,6 +101,36 @@ public class TheoremController {
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
}
@GetMapping("/{name}")
public @ResponseBody
ResponseEntity<List<TheoremDto>> getAllTheoremsByName(@PathVariable("name") final String name) {
LOG.info("Received request to query for theorems whose name is " + name);
if (name == null) {
LOG.error("ERROR: name was null");
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
LOG.debug("Querying for theorems with name " + name);
final StopWatch stopWatch = new StopWatch();
stopWatch.start();
final List<TheoremDto> listOfTheorems = theoremRepository.findByName(name);
stopWatch.stop();
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
LOG.info("Returning list of all theorems with size " + listOfTheorems.size());
if (listOfTheorems.isEmpty()) {
LOG.warn("No theorems were found with name {}", name);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
LOG.info("Returning list of theorems with name {}", name);
return new ResponseEntity<>(listOfTheorems, HttpStatus.OK);
}
@GetMapping("/{id}")
public @ResponseBody
ResponseEntity<TheoremDto> getTheoremById(@PathVariable("id") final Integer id) {
@@ -12,4 +12,6 @@ public interface TheoremRepository extends JpaRepository<TheoremDto, Integer> {
List<TheoremDto> findByBranch(String branch);
List<TheoremDto> findByProvenStatus(Boolean provenStatus);
List<TheoremDto> findByName(String name);
}