PAN-52 Added findByName and findByBranch methods to the repository, and created first couple of methods and corresponding tests in the ProofController
This commit is contained in:
+31
@@ -10,6 +10,7 @@ import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -37,6 +38,36 @@ public class ProofController {
|
||||
return new ResponseEntity<>(listOfProofs, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ProofDto> getProofById(@PathVariable("id") final Integer id) {
|
||||
LOG.info("Received request to query for proof with id " + id);
|
||||
if (id == null) {
|
||||
LOG.error("ERROR: ID was null");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
LOG.debug("Querying for proof with id " + id);
|
||||
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
final Optional<ProofDto> proof = proofRepository.findById(id);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||
return proof.map(proofDto -> {
|
||||
LOG.info("Returning proof with id " + id);
|
||||
return new ResponseEntity<>(proofDto, HttpStatus.OK);
|
||||
}).orElseGet(
|
||||
() -> {
|
||||
LOG.warn("No proof was found with id " + id);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/{branch}")
|
||||
public @ResponseBody
|
||||
ResponseEntity<List<ProofDto>> getAllProofsByBranch(@PathVariable("branch") final String branch) {
|
||||
|
||||
Reference in New Issue
Block a user