From 1b8403a6a30663842d36476d0b5fd6b4f5508b7d Mon Sep 17 00:00:00 2001 From: Andrei Troie Date: Thu, 10 Oct 2024 16:22:33 +0100 Subject: [PATCH 1/2] Use camelCase method naming --- .../bbc/news/elections/controllers/ResultsController.java | 6 +++--- .../bbc/news/elections/service/MapBasedRepository.java | 6 +++--- .../java/bbc/news/elections/service/ResultService.java | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/election-api-java/src/main/java/bbc/news/elections/controllers/ResultsController.java b/election-api-java/src/main/java/bbc/news/elections/controllers/ResultsController.java index 05ac937..d931ca2 100644 --- a/election-api-java/src/main/java/bbc/news/elections/controllers/ResultsController.java +++ b/election-api-java/src/main/java/bbc/news/elections/controllers/ResultsController.java @@ -24,17 +24,17 @@ public ResultsController(ResultService resultService) { @GetMapping("/result/{id}") ConstituencyResult getResult(@PathVariable Integer id) { - ConstituencyResult result = resultService.GetResult(id); + ConstituencyResult result = resultService.getResult(id); if (result == null) { throw new ResultNotFoundException(id); } - return resultService.GetResult(id); + return resultService.getResult(id); } @PostMapping("/result") ResponseEntity newResult(@RequestBody ConstituencyResult result) { if (result.getId() != null) { - resultService.NewResult(result); + resultService.newResult(result); return ResponseEntity.created(URI.create("/result/"+result.getId())).build(); } return ResponseEntity.badRequest().body("Id was null"); diff --git a/election-api-java/src/main/java/bbc/news/elections/service/MapBasedRepository.java b/election-api-java/src/main/java/bbc/news/elections/service/MapBasedRepository.java index f3c712d..abea5cb 100644 --- a/election-api-java/src/main/java/bbc/news/elections/service/MapBasedRepository.java +++ b/election-api-java/src/main/java/bbc/news/elections/service/MapBasedRepository.java @@ -16,17 +16,17 @@ public MapBasedRepository() { } @Override - public ConstituencyResult GetResult(Integer id) { + public ConstituencyResult getResult(Integer id) { return results.get(id); } @Override - public void NewResult(ConstituencyResult result) { + public void newResult(ConstituencyResult result) { results.put(result.getId(), result); } @Override - public Map GetAll() { + public Map getAll() { return results; } diff --git a/election-api-java/src/main/java/bbc/news/elections/service/ResultService.java b/election-api-java/src/main/java/bbc/news/elections/service/ResultService.java index 7ed1fcf..31d8d37 100644 --- a/election-api-java/src/main/java/bbc/news/elections/service/ResultService.java +++ b/election-api-java/src/main/java/bbc/news/elections/service/ResultService.java @@ -2,12 +2,11 @@ import bbc.news.elections.model.ConstituencyResult; -import java.util.List; import java.util.Map; public interface ResultService { - ConstituencyResult GetResult(Integer id); - void NewResult(ConstituencyResult result); - Map GetAll(); + ConstituencyResult getResult(Integer id); + void newResult(ConstituencyResult result); + Map getAll(); void reset(); } From c2182630885051db52711c5023a35f974e0667ea Mon Sep 17 00:00:00 2001 From: Andrei Troie Date: Thu, 10 Oct 2024 19:50:30 +0100 Subject: [PATCH 2/2] Reuse result instead of calling method again --- .../java/bbc/news/elections/controllers/ResultsController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/election-api-java/src/main/java/bbc/news/elections/controllers/ResultsController.java b/election-api-java/src/main/java/bbc/news/elections/controllers/ResultsController.java index d931ca2..dc6623f 100644 --- a/election-api-java/src/main/java/bbc/news/elections/controllers/ResultsController.java +++ b/election-api-java/src/main/java/bbc/news/elections/controllers/ResultsController.java @@ -28,7 +28,7 @@ ConstituencyResult getResult(@PathVariable Integer id) { if (result == null) { throw new ResultNotFoundException(id); } - return resultService.getResult(id); + return result; } @PostMapping("/result")