Skip to content

Commit e6ee80c

Browse files
committed
comment and test
1 parent bfa78a1 commit e6ee80c

File tree

12 files changed

+426
-36
lines changed

12 files changed

+426
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
## Future plan
6565

66+
- Improve test coverage (unit tests, integration tests, end-to-end tests)
6667
- Implement login form and Spring Security
6768
- Create separate table for roles (and set a list of roles to the users)
6869
- After roles are implemented, we plan to make a separate REST API & Thymeleaf for the user (now only admin implemented)

pom.xml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@
9090
<version>2.19.0</version>
9191
</dependency>
9292

93-
<dependency>
94-
<groupId>org.springframework.boot</groupId>
95-
<artifactId>spring-boot-starter-test</artifactId>
96-
<scope>test</scope>
97-
</dependency>
98-
9993
<dependency>
10094
<groupId>org.junit.jupiter</groupId>
10195
<artifactId>junit-jupiter-engine</artifactId>
@@ -110,6 +104,17 @@
110104
<scope>test</scope>
111105
</dependency>
112106

107+
<dependency>
108+
<groupId>org.springframework.boot</groupId>
109+
<artifactId>spring-boot-starter-test</artifactId>
110+
<scope>test</scope>
111+
<exclusions>
112+
<exclusion>
113+
<groupId>org.junit.vintage</groupId>
114+
<artifactId>junit-vintage-engine</artifactId>
115+
</exclusion>
116+
</exclusions>
117+
</dependency>
113118

114119
<!--<dependency>
115120
<groupId>org.springframework.security</groupId>
@@ -118,8 +123,6 @@
118123
</dependency>-->
119124
</dependencies>
120125

121-
122-
123126
<build>
124127
<plugins>
125128
<plugin>

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

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,29 @@
2727
@RequiredArgsConstructor
2828
public class LitterController {
2929

30-
// TODO: render all litters for the logged in user only!
31-
// TODO: create findByUserId method in ReportRepository
32-
30+
/**
31+
* The LitterService.
32+
* TODO: render all litters for the logged-in user only!
33+
* TODO: create findByUserId method in ReportRepository
34+
*/
3335
private final LitterService litterService;
3436

37+
/**
38+
* This method is used to render all litters.
39+
* @return the list of litters
40+
*/
3541
@GetMapping("/admin/litters")
3642
public List<LitterModel> renderAllLitters() {
3743
return litterService.findAllLitters();
3844
}
3945

46+
/**
47+
* This method is used to add a new litter.
48+
* @param litterModel the litter model
49+
* @param address the address
50+
* @param file the file
51+
* @return the response entity
52+
*/
4053
@PostMapping(value = "/admin/litters",
4154
consumes = "multipart/form-data",
4255
produces = "application/json")
@@ -46,24 +59,39 @@ public ResponseEntity<LitterModel> addNewLitter(@ModelAttribute LitterCreateOrMo
4659
return ResponseEntity.status(201).body(litterService.addNewLitter(litterModel, address, file));
4760
}
4861

62+
/**
63+
* This method is used to render a litter by id.
64+
* @param id the id
65+
* @return the response entity
66+
*/
4967
@GetMapping("/admin/litters/{id}")
5068
public ResponseEntity<LitterModel> renderLitterById(@PathVariable("id") UUID id) {
5169
LitterModel litter = litterService.findLitterById(id);
5270
if (litter != null) {
5371
return new ResponseEntity<>(litter, HttpStatus.OK);
54-
5572
}
5673
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
5774
}
5875

76+
/**
77+
* This method is used to update a litter by id.
78+
* @param id the id
79+
* @param model the model
80+
* @return the response entity
81+
*/
5982
@PutMapping(value = "/admin/litters/modify/{id}",
60-
consumes = "multipart/form-data",
83+
consumes = "application/json",
6184
produces = "application/json")
6285
public ResponseEntity<LitterModel> updateExistingLitter(@PathVariable("id") UUID id,
6386
@RequestBody LitterCreateOrModifyModel model) {
6487
return ResponseEntity.status(200).body(litterService.modifyAnExistingLitter(id, model));
6588
}
6689

90+
/**
91+
* This method is used to delete a litter by id.
92+
* @param id the id
93+
* @return the response entity
94+
*/
6795
@DeleteMapping("/admin/litters/delete/{id}")
6896
public ResponseEntity<Void> deleteExistingLitter(@PathVariable("id") UUID id) {
6997
litterService.deleteAnExistingLitter(id);

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

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,52 @@
22

33
import com.csaba79coder.littersnap.model.report.dto.ReportModel;
44
import com.csaba79coder.littersnap.model.report.service.ReportService;
5+
import lombok.RequiredArgsConstructor;
56
import org.springframework.http.ResponseEntity;
67
import org.springframework.web.bind.annotation.*;
78

89
import java.util.List;
910
import java.util.UUID;
1011

12+
/**
13+
* The ReportController.
14+
*/
1115
@RestController
16+
@RequiredArgsConstructor
1217
@RequestMapping("/api/auth")
1318
public class ReportController {
1419

15-
// TODO: render all reports for the logged in user only!
16-
// TODO: create findByUserId method in ReportRepository
20+
/**
21+
* Dependency injection for the ReportService.
22+
* TODO: render all reports for the logged in user only!
23+
* TODO: create findByUserId method in ReportRepository
24+
*/
1725
private final ReportService reportService;
1826

19-
public ReportController(ReportService reportService) {
20-
this.reportService = reportService;
21-
}
22-
27+
/**
28+
* This method is used to render all reports.
29+
* @return the list of reports, and status code 200 (OK)
30+
*/
2331
@GetMapping("/admin/reports")
24-
public List<ReportModel> renderAllReports() {
25-
return reportService.findAllReports();
32+
public ResponseEntity<List<ReportModel>> renderAllReports() {
33+
return ResponseEntity.status(200).body(reportService.findAllReports());
2634
}
2735

36+
/**
37+
* This method is used to add a new report.
38+
* @param model the report model
39+
* @return the response entity and status code 201 (Created)
40+
*/
2841
@PostMapping("/admin/reports")
2942
public ResponseEntity<ReportModel> addNewReport(@RequestBody ReportModel model) {
3043
return ResponseEntity.status(201).body(reportService.addNewReport(model));
3144
}
3245

46+
/**
47+
* This method is used to render a report by its id.
48+
* @param id the id
49+
* @return the response entity and status code 200 (OK)
50+
*/
3351
@GetMapping("/admin/reports/{id}")
3452
public ResponseEntity<ReportModel> renderReportById(@PathVariable("id") UUID id) {
3553
ReportModel report = reportService.findReportById(id);
@@ -39,11 +57,22 @@ public ResponseEntity<ReportModel> renderReportById(@PathVariable("id") UUID id)
3957
return ResponseEntity.notFound().build(); // Return 404 (Not Found) status
4058
}
4159

60+
/**
61+
* This method is used to update an existing report.
62+
* @param id the id
63+
* @param model the report model
64+
* @return the response entity and status code 200 (OK)
65+
*/
4266
@PutMapping("/admin/reports/{id}")
4367
public ResponseEntity<ReportModel> updateExistingReport(@PathVariable("id") UUID id, @RequestBody ReportModel model) {
4468
return ResponseEntity.status(200).body(reportService.modifyAnExistingReport(id, model));
4569
}
4670

71+
/**
72+
* This method is used to delete an existing report.
73+
* @param id the id
74+
* @return status code 204 (No Content) if successful
75+
*/
4776
@DeleteMapping("/admin/reports/{id}")
4877
public ResponseEntity<Void> deleteExistingReport(@PathVariable("id") UUID id) {
4978
reportService.deleteExistingReport(id);

src/main/java/com/csaba79coder/littersnap/model/email/service/LitterSnapEmailSenderServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* This class contains the litter snap email sender service implementation.
1414
* Also include logs errors and exceptions.
1515
*/
16-
@Service("email")
16+
@Service
1717
@RequiredArgsConstructor
1818
@Slf4j
1919
public class LitterSnapEmailSenderServiceImpl implements LitterSnapEmailSenderService {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public List<LitterModel> findAllLitters() {
7070
* @param file
7171
* @return the litter model
7272
* @throws NoSuchElementException if the address is not found
73+
* if address is already exists (check all fields mathching) then application set the existing address
74+
* it address is not exists in system, then application save the new address and set it to the litter
7375
*/
7476
public LitterModel addNewLitter(LitterCreateOrModifyModel litterModel, Address address, MultipartFile file) {
7577
Optional<Address> addressOptional = addressRepository.findAddressByCityContainingIgnoreCaseAndCountryContainingIgnoreCaseAndPostCodeAndFirstLineContainsIgnoreCase(
@@ -120,6 +122,8 @@ public LitterModel findLitterById(UUID id) {
120122
* @param model
121123
* @return LitterModel
122124
* throws NoSuchElementException if the litter is not found
125+
* if address is already exists (check all fields mathching) then application set the existing address
126+
* it address is not exists in system, then application save the new address and set it to the litter
123127
*/
124128
public LitterModel modifyAnExistingLitter(UUID id, LitterCreateOrModifyModel model) {
125129
Optional<Litter> optionalExistingLitter = litterRepository.findById(id);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
import org.springframework.stereotype.Controller;
44
import org.springframework.web.bind.annotation.GetMapping;
55

6+
/**
7+
* Controller for the index page
8+
*/
69
@Controller
710
public class HomeController {
811

12+
/**
13+
* Renders the index page
14+
* @return the index page
15+
*/
916
@GetMapping({"/","","index","index.html"})
1017
public String renderIndexPage() {
1118
return "index";

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

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.csaba79coder.littersnap.model.litter.dto.LitterModel;
66
import com.csaba79coder.littersnap.model.litter.service.LitterService;
77
import com.csaba79coder.littersnap.util.Mapper;
8+
import lombok.RequiredArgsConstructor;
89
import org.springframework.stereotype.Controller;
910
import org.springframework.ui.Model;
1011
import org.springframework.web.bind.annotation.*;
@@ -15,17 +16,28 @@
1516
import java.util.NoSuchElementException;
1617
import java.util.UUID;
1718

19+
/**
20+
* This class contains the litter view controller.
21+
* Also include logs errors and exceptions.
22+
*/
1823
@Controller
24+
@RequiredArgsConstructor
1925
@RequestMapping("/thy/auth")
2026
public class LitterViewController {
2127

28+
/**
29+
* Dependency injection fields.
30+
* <p>
31+
* litterService: the litter service
32+
* </p>
33+
*/
2234
private final LitterService litterService;
2335

24-
public LitterViewController(LitterService litterService) {
25-
this.litterService = litterService;
26-
}
27-
28-
36+
/**
37+
* This method renders the litter list.
38+
* @param model the model
39+
* @return the view name
40+
*/
2941
@GetMapping("/admin/litters")
3042
public String renderAllLitters(Model model) {
3143
try {
@@ -39,6 +51,12 @@ public String renderAllLitters(Model model) {
3951
}
4052
}
4153

54+
/**
55+
* This method renders the litter details.
56+
* @param id the litter id
57+
* @param model the model
58+
* @return the view name
59+
*/
4260
@GetMapping("/admin/litters/{id}")
4361
public String renderLitterById(@PathVariable("id") UUID id, Model model) {
4462
try {
@@ -65,6 +83,11 @@ public String renderLitterById(@PathVariable("id") UUID id, Model model) {
6583
}
6684
}
6785

86+
/**
87+
* This method creates a litter
88+
* @param capturedCity and add button renders a form
89+
* @return the view name
90+
*/
6891
@GetMapping("/admin/litters/create")
6992
public String showAddLitterForm(Model model, @RequestParam(value = "city", required = false) String capturedCity) {
7093
try {
@@ -81,6 +104,15 @@ public String showAddLitterForm(Model model, @RequestParam(value = "city", requi
81104
}
82105
}
83106

107+
/**
108+
* This method creates a litter
109+
* by the get method with the captured city parameter you can set the litterModel fields
110+
* @param litterModel
111+
* @param address
112+
* @param file
113+
* @param model
114+
* @return the view name
115+
*/
84116
@PostMapping("/admin/litters/create")
85117
public String addNewLitter(@ModelAttribute("litter") LitterCreateOrModifyModel litterModel, @ModelAttribute("address") Address address, @RequestParam("file") MultipartFile file, Model model) {
86118
try {
@@ -92,6 +124,12 @@ public String addNewLitter(@ModelAttribute("litter") LitterCreateOrModifyModel l
92124
}
93125
}
94126

127+
/**
128+
* This method renders the litter edit form.
129+
* @param id the litter id
130+
* @param model the model
131+
* @return the view name
132+
*/
95133
@GetMapping("/admin/litters/edit/{id}")
96134
public String showEditForm(@PathVariable UUID id, Model model) {
97135
try {
@@ -111,6 +149,13 @@ public String showEditForm(@PathVariable UUID id, Model model) {
111149
}
112150
}
113151

152+
/**
153+
* This method updates an existing litter.
154+
* @param id the litter id
155+
* @param litterModel the litter model
156+
* @param model the model
157+
* @return the view name
158+
*/
114159
@PostMapping("/admin/litters/edit/{id}")
115160
public String modifyExistingLitter(@PathVariable UUID id, @ModelAttribute("report") LitterCreateOrModifyModel litterModel, Model model) {
116161
try {
@@ -122,7 +167,12 @@ public String modifyExistingLitter(@PathVariable UUID id, @ModelAttribute("repor
122167
}
123168
}
124169

125-
170+
/**
171+
* This method deletes an existing litter.
172+
* @param id the litter id
173+
* @param model the model
174+
* @return the view name
175+
*/
126176
@GetMapping("/admin/litters/delete/{id}")
127177
public String deleteAnExistingLitter(@PathVariable UUID id, Model model) {
128178
try {

0 commit comments

Comments
 (0)