Skip to content

Commit 049ec88

Browse files
Merge pull request #12 from Csaba79-coder/feature-refactor-method-new-namings-vasile
feature-refactor-new-namings implemented and tested
2 parents a1099d9 + c924ace commit 049ec88

File tree

6 files changed

+32
-36
lines changed

6 files changed

+32
-36
lines changed

src/main/java/com/csaba79coder/littersnap/controller/LitterController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class LitterController {
2222

2323
@GetMapping
2424
public List<LitterModel> getAllLitters() {
25-
return litterService.getAllLitters();
25+
return litterService.findAllLitters();
2626
}
2727

2828
@PostMapping
@@ -34,7 +34,7 @@ public ResponseEntity<LitterModel> addNewLitter(@RequestBody LitterCreateOrModif
3434

3535
@GetMapping("/{id}")
3636
public ResponseEntity<LitterModel> getLitterById(@PathVariable("id") UUID id) {
37-
LitterModel litter = litterService.getLitterById(id);
37+
LitterModel litter = litterService.findLitterById(id);
3838
if (litter != null) {
3939
return new ResponseEntity<>(litter, HttpStatus.OK);
4040
}
@@ -44,13 +44,13 @@ public ResponseEntity<LitterModel> getLitterById(@PathVariable("id") UUID id) {
4444
@PutMapping("/{id}")
4545
public ResponseEntity<LitterModel> updateExistingLitter(@PathVariable("id") UUID id,
4646
@RequestBody LitterCreateOrModifyModel model) {
47-
return ResponseEntity.status(200).body(litterService.updateExistingLitter(id, model));
47+
return ResponseEntity.status(200).body(litterService.modifyAnExistingLitter(id, model));
4848
}
4949

5050
@DeleteMapping("/{id}")
5151
public ResponseEntity<Void> deleteExistingLitter(@PathVariable("id") UUID id) {
52-
LitterModel litter = litterService.getLitterById(id);
53-
litterService.deleteLitter(id);
52+
LitterModel litter = litterService.findLitterById(id);
53+
litterService.deleteAnExistingLitter(id);
5454

5555
return ResponseEntity.status(204).build();
5656
}

src/main/java/com/csaba79coder/littersnap/controller/ReportController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public ReportController(ReportService reportService) {
1919
}
2020

2121
@GetMapping
22-
public List<ReportModel> getAllReports() {
23-
return reportService.getAllReports();
22+
public List<ReportModel> renderAllReports() {
23+
return reportService.findAllReports();
2424
}
2525

2626
@PostMapping
@@ -29,22 +29,22 @@ public ResponseEntity<ReportModel> addNewReport(@RequestBody ReportModel model)
2929
}
3030

3131
@GetMapping("/{id}")
32-
public ResponseEntity<ReportModel> getReportById(@PathVariable("id") UUID id) {
33-
ReportModel report = reportService.getReportById(id);
32+
public ResponseEntity<ReportModel> renderReportById(@PathVariable("id") UUID id) {
33+
ReportModel report = reportService.findReportById(id);
3434
if (report != null) {
3535
return ResponseEntity.ok(report); // Include the report in the response body with status code 200 (OK)
3636
}
3737
return ResponseEntity.notFound().build(); // Return 404 (Not Found) status
3838
}
3939

4040
@PutMapping("/{id}")
41-
public ResponseEntity<ReportModel> updateExistingReport(@PathVariable("id") UUID id, @RequestBody ReportModel model) {
42-
return ResponseEntity.status(200).body(reportService.updateExistingReport(id, model));
41+
public ResponseEntity<ReportModel> updateAnExistingReport(@PathVariable("id") UUID id, @RequestBody ReportModel model) {
42+
return ResponseEntity.status(200).body(reportService.modifyAnExistingReport(id, model));
4343
}
4444

4545
@DeleteMapping("/{id}")
46-
public ResponseEntity<Void> deleteExistingReport(@PathVariable("id") UUID id) {
47-
ReportModel litter = reportService.getReportById(id);
46+
public ResponseEntity<Void> deleteAnExistingReport(@PathVariable("id") UUID id) {
47+
ReportModel litter = reportService.findReportById(id);
4848
reportService.deleteExistingReport(id);
4949

5050
return ResponseEntity.status(204).build();

src/main/java/com/csaba79coder/littersnap/model/litter/service/LitterService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class LitterService {
2929

3030
private final AddressRepository addressRepository;
3131

32-
public List<LitterModel> getAllLitters() {
32+
public List<LitterModel> findAllLitters() {
3333
List<Litter> litters = litterRepository.findAll();
3434

3535

@@ -71,7 +71,7 @@ public LitterModel addNewLitter(LitterCreateOrModifyModel litterModel, Address a
7171
return Mapper.mapLitterEntityToModel(savedLitterEntity);
7272
}
7373

74-
public LitterModel getLitterById(UUID id) {
74+
public LitterModel findLitterById(UUID id) {
7575
Optional<Litter> litterOptional = litterRepository.findById(id);
7676
if (litterOptional.isPresent()) {
7777
Litter litter = litterOptional.get();
@@ -86,7 +86,7 @@ public LitterModel getLitterById(UUID id) {
8686
}
8787
}
8888

89-
public LitterModel updateExistingLitter(UUID id, LitterCreateOrModifyModel model) {
89+
public LitterModel modifyAnExistingLitter(UUID id, LitterCreateOrModifyModel model) {
9090
Optional<Litter> optionalExistingLitter = litterRepository.findById(id);
9191
if (optionalExistingLitter.isPresent()) {
9292

@@ -110,7 +110,7 @@ public LitterModel updateExistingLitter(UUID id, LitterCreateOrModifyModel model
110110

111111
}
112112

113-
public void deleteLitter(UUID id) {
113+
public void deleteAnExistingLitter(UUID id) {
114114
Optional<Litter> optionalExistingLitter = litterRepository.findById(id);
115115
if (optionalExistingLitter.isPresent()) {
116116
litterRepository.deleteById(id);

src/main/java/com/csaba79coder/littersnap/model/report/service/ReportService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ReportService {
2222

2323

2424

25-
public List<ReportModel> getAllReports() {
25+
public List<ReportModel> findAllReports() {
2626
return reportRepository.findAll()
2727
.stream()
2828
.map(Mapper::mapReportEntityToModel)
@@ -36,7 +36,7 @@ public ReportModel addNewReport(ReportModel reportModel) {
3636
}
3737

3838

39-
public ReportModel getReportById(UUID id) {
39+
public ReportModel findReportById(UUID id) {
4040
Optional<Report> optionalReport = reportRepository.findReportById(id);
4141
if (optionalReport.isPresent()) {
4242
Report report = optionalReport.get();
@@ -47,7 +47,7 @@ public ReportModel getReportById(UUID id) {
4747
return null;
4848
}
4949

50-
public ReportModel updateExistingReport(UUID id, ReportModel model) {
50+
public ReportModel modifyAnExistingReport(UUID id, ReportModel model) {
5151
Optional<Report> optionalExistingReport = reportRepository.findById(id);
5252
if (optionalExistingReport.isPresent()) {
5353
Report existingReport = optionalExistingReport.get();

src/main/java/com/csaba79coder/littersnap/view/LitterViewController.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public LitterViewController(LitterService litterService) {
2727

2828

2929
@GetMapping
30-
public String getAllLitters(Model model) {
30+
public String renderAllLitters(Model model) {
3131
try {
32-
List<LitterModel> litters = litterService.getAllLitters();
32+
List<LitterModel> litters = litterService.findAllLitters();
3333
model.addAttribute("litters", litters);
3434
model.addAttribute("view", "litter_list");
3535
return "welcome"; // Replace with the actual view name for displaying the list of litters
@@ -40,9 +40,9 @@ public String getAllLitters(Model model) {
4040
}
4141

4242
@GetMapping("/{id}")
43-
public String getLitterById(@PathVariable("id") UUID id, Model model) {
43+
public String renderLitterById(@PathVariable("id") UUID id, Model model) {
4444
try {
45-
LitterModel litter = litterService.getLitterById(id);
45+
LitterModel litter = litterService.findLitterById(id);
4646
model.addAttribute("id", litter.getId());
4747
model.addAttribute("createdAt", litter.getCreatedAt());
4848
model.addAttribute("updatedAt", litter.getUpdatedAt());
@@ -95,7 +95,7 @@ public String addNewLitter(@ModelAttribute("litter") LitterCreateOrModifyModel l
9595
@GetMapping("/edit/{id}")
9696
public String showEditForm(@PathVariable UUID id, Model model) {
9797
try {
98-
LitterCreateOrModifyModel litter = Mapper.mapModelToLitterCreateOrModifyModel(litterService.getLitterById(id));
98+
LitterCreateOrModifyModel litter = Mapper.mapModelToLitterCreateOrModifyModel(litterService.findLitterById(id));
9999
model.addAttribute("id", litter.getId());
100100
model.addAttribute("firstline", litter.getAddress().getFirstLine());
101101
model.addAttribute("city", litter.getAddress().getCity());
@@ -112,9 +112,9 @@ public String showEditForm(@PathVariable UUID id, Model model) {
112112
}
113113

114114
@PostMapping("/edit/{id}")
115-
public String updateLitter(@PathVariable UUID id, @ModelAttribute("report") LitterCreateOrModifyModel litterModel, Model model) {
115+
public String modifyExistingLitter(@PathVariable UUID id, @ModelAttribute("report") LitterCreateOrModifyModel litterModel, Model model) {
116116
try {
117-
litterService.updateExistingLitter(id, litterModel);
117+
litterService.modifyAnExistingLitter(id, litterModel);
118118
return "redirect:/reports"; // Redirect to the URL for displaying all reports after successful update
119119
} catch (NoSuchElementException e) {
120120
model.addAttribute("errorMessage", e.getMessage());
@@ -124,17 +124,13 @@ public String updateLitter(@PathVariable UUID id, @ModelAttribute("report") Litt
124124

125125

126126
@GetMapping("/delete/{id}")
127-
public String deleteLitter(@PathVariable UUID id, Model model) {
128-
127+
public String deleteAnExistingLitter(@PathVariable UUID id, Model model) {
129128
try {
130-
litterService.deleteLitter(id);
129+
litterService.deleteAnExistingLitter(id);
131130
return "redirect:/thy/litter"; // Redirect to the URL for displaying all reports after successful deletion
132131
} catch (NoSuchElementException e) {
133132
model.addAttribute("errorMessage", e.getMessage());
134133
return "error_page"; // Redirect to the error page to display the error message
135134
}
136-
137135
}
138-
139-
140136
}

src/main/java/com/csaba79coder/littersnap/view/ReportViewController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public ReportViewController(ReportService reportService) {
2323

2424
@GetMapping
2525
public String getAllReports(Model model) {
26-
List<ReportModel> reports = reportService.getAllReports();
26+
List<ReportModel> reports = reportService.findAllReports();
2727

2828
if (reports.isEmpty()) {
2929
return "error_page";
@@ -35,7 +35,7 @@ public String getAllReports(Model model) {
3535

3636
@GetMapping("/{id}")
3737
public String getReportById(@PathVariable UUID id, Model model) {
38-
ReportModel currentReport = reportService.getReportById(id);
38+
ReportModel currentReport = reportService.findReportById(id);
3939

4040
if (currentReport == null) {
4141
return "error_page";
@@ -47,7 +47,7 @@ public String getReportById(@PathVariable UUID id, Model model) {
4747

4848
@GetMapping("/edit/{id}")
4949
public String showEditForm(@PathVariable UUID id, Model model) {
50-
ReportModel currentReport = reportService.getReportById(id);
50+
ReportModel currentReport = reportService.findReportById(id);
5151
if (currentReport == null) {
5252
return "error_page";
5353
} else {

0 commit comments

Comments
 (0)