Skip to content

Commit 7b7feee

Browse files
Merge pull request #14 from Csaba79-coder/developer
Developer
2 parents 3a1fb19 + 049ec88 commit 7b7feee

File tree

10 files changed

+200
-123
lines changed

10 files changed

+200
-123
lines changed

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

Lines changed: 6 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,14 +44,15 @@ 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
}
57+
5758
}

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: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77
import com.csaba79coder.littersnap.util.Mapper;
88
import org.springframework.stereotype.Controller;
99
import org.springframework.ui.Model;
10-
import org.springframework.web.bind.annotation.GetMapping;
11-
import org.springframework.web.bind.annotation.ModelAttribute;
12-
import org.springframework.web.bind.annotation.PathVariable;
13-
import org.springframework.web.bind.annotation.PostMapping;
14-
import org.springframework.web.bind.annotation.RequestMapping;
15-
import org.springframework.web.bind.annotation.RequestParam;
10+
import org.springframework.web.bind.annotation.*;
1611
import org.springframework.web.multipart.MultipartFile;
1712

1813
import java.util.Base64;
@@ -32,9 +27,9 @@ public LitterViewController(LitterService litterService) {
3227

3328

3429
@GetMapping
35-
public String getAllLitters(Model model) {
30+
public String renderAllLitters(Model model) {
3631
try {
37-
List<LitterModel> litters = litterService.getAllLitters();
32+
List<LitterModel> litters = litterService.findAllLitters();
3833
model.addAttribute("litters", litters);
3934
model.addAttribute("view", "litter_list");
4035
return "welcome"; // Replace with the actual view name for displaying the list of litters
@@ -45,9 +40,9 @@ public String getAllLitters(Model model) {
4540
}
4641

4742
@GetMapping("/{id}")
48-
public String getLitterById(@PathVariable("id") UUID id, Model model) {
43+
public String renderLitterById(@PathVariable("id") UUID id, Model model) {
4944
try {
50-
LitterModel litter = litterService.getLitterById(id);
45+
LitterModel litter = litterService.findLitterById(id);
5146
model.addAttribute("id", litter.getId());
5247
model.addAttribute("createdAt", litter.getCreatedAt());
5348
model.addAttribute("updatedAt", litter.getUpdatedAt());
@@ -71,25 +66,23 @@ public String getLitterById(@PathVariable("id") UUID id, Model model) {
7166
}
7267

7368
@GetMapping("/create")
74-
public String showAddLitterForm(Model model) {
69+
public String showAddLitterForm(Model model, @RequestParam(value = "city", required = false) String capturedCity) {
7570
try {
7671
LitterCreateOrModifyModel litterModel = new LitterCreateOrModifyModel();
77-
7872
// Set any other necessary properties in the litterModel object
7973

74+
model.addAttribute("city", capturedCity);
8075
model.addAttribute("litter", litterModel);
81-
return "litter_add_form";
76+
model.addAttribute("view","litter_add_form");
77+
return "welcome";
8278
} catch (NoSuchElementException e) {
8379
model.addAttribute("errorMessage", e.getMessage());
8480
return "error_page"; // Redirect to the error page to display the error message
8581
}
8682
}
8783

8884
@PostMapping("/create")
89-
public String addNewLitter(@ModelAttribute("litter") LitterCreateOrModifyModel litterModel,
90-
@ModelAttribute("address") Address address,
91-
@RequestParam("file") MultipartFile file,
92-
Model model) {
85+
public String addNewLitter(@ModelAttribute("litter") LitterCreateOrModifyModel litterModel, @ModelAttribute("address") Address address, @RequestParam("file") MultipartFile file, Model model) {
9386
try {
9487
litterService.addNewLitter(litterModel, address, file);
9588
return "redirect:/thy/litter";
@@ -102,15 +95,15 @@ public String addNewLitter(@ModelAttribute("litter") LitterCreateOrModifyModel l
10295
@GetMapping("/edit/{id}")
10396
public String showEditForm(@PathVariable UUID id, Model model) {
10497
try {
105-
LitterCreateOrModifyModel litter = Mapper.mapModelToLitterCreateOrModifyModel(litterService.getLitterById(id));
98+
LitterCreateOrModifyModel litter = Mapper.mapModelToLitterCreateOrModifyModel(litterService.findLitterById(id));
10699
model.addAttribute("id", litter.getId());
107100
model.addAttribute("firstline", litter.getAddress().getFirstLine());
108101
model.addAttribute("city", litter.getAddress().getCity());
109102
model.addAttribute("country", litter.getAddress().getCountry());
110103
model.addAttribute("postcode", litter.getAddress().getPostCode());
111104
model.addAttribute("description", litter.getDescription());
112105
model.addAttribute("image", litter.getImage());
113-
model.addAttribute("view","litter_edit_form");
106+
model.addAttribute("view", "litter_edit_form");
114107
return "welcome";
115108
} catch (NoSuchElementException e) {
116109
model.addAttribute("errorMessage", e.getMessage());
@@ -119,9 +112,9 @@ public String showEditForm(@PathVariable UUID id, Model model) {
119112
}
120113

121114
@PostMapping("/edit/{id}")
122-
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) {
123116
try {
124-
litterService.updateExistingLitter(id, litterModel);
117+
litterService.modifyAnExistingLitter(id, litterModel);
125118
return "redirect:/reports"; // Redirect to the URL for displaying all reports after successful update
126119
} catch (NoSuchElementException e) {
127120
model.addAttribute("errorMessage", e.getMessage());
@@ -131,18 +124,13 @@ public String updateLitter(@PathVariable UUID id, @ModelAttribute("report") Litt
131124

132125

133126
@GetMapping("/delete/{id}")
134-
public String deleteLitter(@PathVariable UUID id,Model model) {
135-
127+
public String deleteAnExistingLitter(@PathVariable UUID id, Model model) {
136128
try {
137-
litterService.deleteLitter(id);
129+
litterService.deleteAnExistingLitter(id);
138130
return "redirect:/thy/litter"; // Redirect to the URL for displaying all reports after successful deletion
139131
} catch (NoSuchElementException e) {
140132
model.addAttribute("errorMessage", e.getMessage());
141133
return "error_page"; // Redirect to the error page to display the error message
142134
}
143-
144135
}
145-
146-
147-
148136
}

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 {

src/main/resources/static/style.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,46 @@ body {
2424
z-index: 999;
2525
}
2626

27+
/*Image redendering size controll*/
28+
.image-container {
29+
max-width: 350px; /* Set the maximum width for the image container */
30+
margin: auto; /* Center the container horizontally */
31+
cursor: pointer; /* Show the pointer cursor when hovering */
32+
}
33+
34+
.image-container img {
35+
width: 100%; /* Make the image fill the container */
36+
height: auto; /* Maintain aspect ratio */
37+
transition: transform 0.3s; /* Add a smooth transition effect */
38+
}
39+
40+
.image-container img:hover {
41+
transform: scale(1.2); /* Scale the image to 120% on hover */
42+
}
43+
44+
/*NavBar style*/
45+
.navbar {
46+
background-color: #f8f9fa;
47+
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
48+
}
49+
50+
.navbar-brand {
51+
font-size: 1.5rem;
52+
font-weight: bold;
53+
color: #333;
54+
}
55+
56+
.navbar-nav .nav-link {
57+
font-size: 1.1rem;
58+
color: #333;
59+
transition: color 0.3s;
60+
}
61+
62+
.navbar-nav .nav-link:hover {
63+
color: #007bff;
64+
}
65+
66+
/*Logo Style*/
2767
.logo-and-slogan-container {
2868
position: relative;
2969
}

0 commit comments

Comments
 (0)