Skip to content

feature-refactor-new-namings implemented and tested #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class LitterController {

@GetMapping
public List<LitterModel> getAllLitters() {
return litterService.getAllLitters();
return litterService.findAllLitters();
}

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

@GetMapping("/{id}")
public ResponseEntity<LitterModel> getLitterById(@PathVariable("id") UUID id) {
LitterModel litter = litterService.getLitterById(id);
LitterModel litter = litterService.findLitterById(id);
if (litter != null) {
return new ResponseEntity<>(litter, HttpStatus.OK);
}
Expand All @@ -44,13 +44,13 @@ public ResponseEntity<LitterModel> getLitterById(@PathVariable("id") UUID id) {
@PutMapping("/{id}")
public ResponseEntity<LitterModel> updateExistingLitter(@PathVariable("id") UUID id,
@RequestBody LitterCreateOrModifyModel model) {
return ResponseEntity.status(200).body(litterService.updateExistingLitter(id, model));
return ResponseEntity.status(200).body(litterService.modifyAnExistingLitter(id, model));
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteExistingLitter(@PathVariable("id") UUID id) {
LitterModel litter = litterService.getLitterById(id);
litterService.deleteLitter(id);
LitterModel litter = litterService.findLitterById(id);
litterService.deleteAnExistingLitter(id);

return ResponseEntity.status(204).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public ReportController(ReportService reportService) {
}

@GetMapping
public List<ReportModel> getAllReports() {
return reportService.getAllReports();
public List<ReportModel> renderAllReports() {
return reportService.findAllReports();
}

@PostMapping
Expand All @@ -29,22 +29,22 @@ public ResponseEntity<ReportModel> addNewReport(@RequestBody ReportModel model)
}

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

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

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteExistingReport(@PathVariable("id") UUID id) {
ReportModel litter = reportService.getReportById(id);
public ResponseEntity<Void> deleteAnExistingReport(@PathVariable("id") UUID id) {
ReportModel litter = reportService.findReportById(id);
reportService.deleteExistingReport(id);

return ResponseEntity.status(204).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class LitterService {

private final AddressRepository addressRepository;

public List<LitterModel> getAllLitters() {
public List<LitterModel> findAllLitters() {
List<Litter> litters = litterRepository.findAll();


Expand Down Expand Up @@ -71,7 +71,7 @@ public LitterModel addNewLitter(LitterCreateOrModifyModel litterModel, Address a
return Mapper.mapLitterEntityToModel(savedLitterEntity);
}

public LitterModel getLitterById(UUID id) {
public LitterModel findLitterById(UUID id) {
Optional<Litter> litterOptional = litterRepository.findById(id);
if (litterOptional.isPresent()) {
Litter litter = litterOptional.get();
Expand All @@ -86,7 +86,7 @@ public LitterModel getLitterById(UUID id) {
}
}

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

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

}

public void deleteLitter(UUID id) {
public void deleteAnExistingLitter(UUID id) {
Optional<Litter> optionalExistingLitter = litterRepository.findById(id);
if (optionalExistingLitter.isPresent()) {
litterRepository.deleteById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ReportService {



public List<ReportModel> getAllReports() {
public List<ReportModel> findAllReports() {
return reportRepository.findAll()
.stream()
.map(Mapper::mapReportEntityToModel)
Expand All @@ -36,7 +36,7 @@ public ReportModel addNewReport(ReportModel reportModel) {
}


public ReportModel getReportById(UUID id) {
public ReportModel findReportById(UUID id) {
Optional<Report> optionalReport = reportRepository.findReportById(id);
if (optionalReport.isPresent()) {
Report report = optionalReport.get();
Expand All @@ -47,7 +47,7 @@ public ReportModel getReportById(UUID id) {
return null;
}

public ReportModel updateExistingReport(UUID id, ReportModel model) {
public ReportModel modifyAnExistingReport(UUID id, ReportModel model) {
Optional<Report> optionalExistingReport = reportRepository.findById(id);
if (optionalExistingReport.isPresent()) {
Report existingReport = optionalExistingReport.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public LitterViewController(LitterService litterService) {


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

@GetMapping("/{id}")
public String getLitterById(@PathVariable("id") UUID id, Model model) {
public String renderLitterById(@PathVariable("id") UUID id, Model model) {
try {
LitterModel litter = litterService.getLitterById(id);
LitterModel litter = litterService.findLitterById(id);
model.addAttribute("id", litter.getId());
model.addAttribute("createdAt", litter.getCreatedAt());
model.addAttribute("updatedAt", litter.getUpdatedAt());
Expand Down Expand Up @@ -95,7 +95,7 @@ public String addNewLitter(@ModelAttribute("litter") LitterCreateOrModifyModel l
@GetMapping("/edit/{id}")
public String showEditForm(@PathVariable UUID id, Model model) {
try {
LitterCreateOrModifyModel litter = Mapper.mapModelToLitterCreateOrModifyModel(litterService.getLitterById(id));
LitterCreateOrModifyModel litter = Mapper.mapModelToLitterCreateOrModifyModel(litterService.findLitterById(id));
model.addAttribute("id", litter.getId());
model.addAttribute("firstline", litter.getAddress().getFirstLine());
model.addAttribute("city", litter.getAddress().getCity());
Expand All @@ -112,9 +112,9 @@ public String showEditForm(@PathVariable UUID id, Model model) {
}

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


@GetMapping("/delete/{id}")
public String deleteLitter(@PathVariable UUID id, Model model) {

public String deleteAnExistingLitter(@PathVariable UUID id, Model model) {
try {
litterService.deleteLitter(id);
litterService.deleteAnExistingLitter(id);
return "redirect:/thy/litter"; // Redirect to the URL for displaying all reports after successful deletion
} catch (NoSuchElementException e) {
model.addAttribute("errorMessage", e.getMessage());
return "error_page"; // Redirect to the error page to display the error message
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ReportViewController(ReportService reportService) {

@GetMapping
public String getAllReports(Model model) {
List<ReportModel> reports = reportService.getAllReports();
List<ReportModel> reports = reportService.findAllReports();

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

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

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

@GetMapping("/edit/{id}")
public String showEditForm(@PathVariable UUID id, Model model) {
ReportModel currentReport = reportService.getReportById(id);
ReportModel currentReport = reportService.findReportById(id);
if (currentReport == null) {
return "error_page";
} else {
Expand Down