Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ PASSWORD_VALIDATOR value as follows:

```^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#&()–[{}]:;',?/*~$^+=<>]).{8,32}$```

Password requirement: 8-32 chars, at least 1 uppercase, 1 lowercase, 1 number, 1 special char

# Created by:

Expand Down
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![img.png](src/main/resources/static/readme/banner-app.png)

# We use server port: 8081
# We use server port: 8081 & our Website is responsive!

## Hosting plan

Expand All @@ -21,7 +21,15 @@
- MySQL
- Spring Security
- Log4j2
- Validator

## Frontend Dependencies

- ThymeLeaf
- Bootstrap 5
- Html
- CSS
- JavaScript

## Test Dependencies

Expand All @@ -31,11 +39,33 @@
- Spring Boot Test
- Spring Boot Starter Test
- Spring Boot Test Autoconfigure
- REST endpoints tested with Postman

## Basic setup

- See manual

## Basic coding rules

- Clean code (code readability in main the focus)
- OOP principles
- SOLID principles
- MVC pattern
- 3-tier architecture (Repository, Service, Controller layers)
- Common Error handling
- Creating separate REST API and Controller for Thymeleaf
- Uniform endpoints
- Collaboration on GitHub (branching, pull requests, code review)

## Future plan

- Create separate table for roles (and set a list of roles to the users)
- We plan to use our existing domain: csaba79coder.com
- We plan to make registration with social media
- We also plan to make a mobile app (and using google map's API there for the localization of the users)

# Created by:

![img_1.png](src/main/resources/static/readme/banner-team.png)
![img_1.png](src/main/resources/static/readme/banner-team.png)

![img.png](src/main/resources/static/readme/indexPage.png)
4 changes: 0 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<!--<dependency>
<groupId>org.springframework.security</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
@RequestMapping("/api/auth")
public class EmailController {

private final LitterSnapEmailSenderServiceImpl litterSnapEmailSenderService;

@PostMapping(value = "/email/test",
@PostMapping(value = "/admin/email/test",
produces = "application/json")
public ResponseEntity sendTestEmail(@RequestBody EmailRequest emailRequest) {
boolean emailSent = litterSnapEmailSenderService.sendEmailHtml(emailRequest);
Expand All @@ -27,4 +27,4 @@ public ResponseEntity sendTestEmail(@RequestBody EmailRequest emailRequest) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,46 @@
import java.util.UUID;

@RestController
@RequestMapping("/api/litters")
@RequestMapping("/api/auth")
@RequiredArgsConstructor
public class LitterController {

// TODO: render all litters for the logged in user only!
// TODO: create findByUserId method in ReportRepository

private final LitterService litterService;

@GetMapping
public List<LitterModel> getAllLitters() {
@GetMapping("/admin/litters")
public List<LitterModel> renderAllLitters() {
return litterService.findAllLitters();
}

@PostMapping
@PostMapping("/admin/litters")
public ResponseEntity<LitterModel> addNewLitter(@RequestBody LitterCreateOrModifyModel litterModel,
@RequestBody Address address,
@RequestParam("file") MultipartFile file) {
return ResponseEntity.status(201).body(litterService.addNewLitter(litterModel, address, file));
}

@GetMapping("/{id}")
public ResponseEntity<LitterModel> getLitterById(@PathVariable("id") UUID id) {
@GetMapping("/admin/litters/{id}")
public ResponseEntity<LitterModel> renderLitterById(@PathVariable("id") UUID id) {
LitterModel litter = litterService.findLitterById(id);
if (litter != null) {
return new ResponseEntity<>(litter, HttpStatus.OK);

}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

@PutMapping("/{id}")
@PutMapping("/admin/litters/modify/{id}")
public ResponseEntity<LitterModel> updateExistingLitter(@PathVariable("id") UUID id,
@RequestBody LitterCreateOrModifyModel model) {
return ResponseEntity.status(200).body(litterService.modifyAnExistingLitter(id, model));
}

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@
import java.util.UUID;

@RestController
@RequestMapping("/api/reports")
@RequestMapping("/api/auth")
public class ReportController {

// TODO: render all reports for the logged in user only!
// TODO: create findByUserId method in ReportRepository
private final ReportService reportService;

public ReportController(ReportService reportService) {
this.reportService = reportService;
}

@GetMapping
@GetMapping("/admin/reports")
public List<ReportModel> renderAllReports() {
return reportService.findAllReports();
}

@PostMapping
@PostMapping("/admin/reports")
public ResponseEntity<ReportModel> addNewReport(@RequestBody ReportModel model) {
return ResponseEntity.status(201).body(reportService.addNewReport(model));
}

@GetMapping("/{id}")
@GetMapping("/admin/reports/{id}")
public ResponseEntity<ReportModel> renderReportById(@PathVariable("id") UUID id) {
ReportModel report = reportService.findReportById(id);
if (report != null) {
Expand All @@ -37,16 +39,14 @@ public ResponseEntity<ReportModel> renderReportById(@PathVariable("id") UUID id)
return ResponseEntity.notFound().build(); // Return 404 (Not Found) status
}

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

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

return ResponseEntity.status(204).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,33 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/users")
@RequestMapping("/api/auth")
public class UserController {

// TODO: render user details for the logged in user only!
// TODO: create findByUserId method in ReportRepository

private final UserService userService;

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping(value = "/admin/users",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<UserModel>> renderAllUsers() {
return ResponseEntity.status(200).body(userService.findAllUsers());
}

@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping(value = "/admin/users",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<UserModel> addNewUser(@RequestBody UserRegistrationModel model) {
return ResponseEntity.status(201).body(userService.addNewUser(model));
}

@PutMapping(value = "/{id}",
@PutMapping(value = "/admin/users/{id}",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<UserModel> modifyExistingUser(@PathVariable UUID id, @RequestBody UserModifyModel model) {
return ResponseEntity.status(200).body(userService.modifyAnExistingUser(id, model));
}

@DeleteMapping(value = "/{id}",
@DeleteMapping(value = "/admin/users/{id}",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> deleteAnExistingUser(@PathVariable UUID id) {
userService.deleteUser(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class LitterService {
public List<LitterModel> findAllLitters() {
List<Litter> litters = litterRepository.findAll();


if (litters.isEmpty()) {
String message = "Litter list is empty";
log.error(message);
Expand Down Expand Up @@ -111,13 +110,13 @@ public LitterModel modifyAnExistingLitter(UUID id, LitterCreateOrModifyModel mod
}

public void deleteAnExistingLitter(UUID id) {
Optional<Litter> optionalExistingLitter = litterRepository.findById(id);
if (optionalExistingLitter.isPresent()) {
litterRepository.deleteById(id);
} else {
String message = String.format("Couldn't delete. Litter with id %s not found", id);
log.error(message);
throw new NoSuchElementException(message);
}
Litter litter = litterRepository.findById(id)
.orElseThrow(() -> {
String message = "Litter not found with id: " + id;
log.error(message);
throw new IllegalArgumentException(message);
});
litterRepository.deleteById(litter.getId());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.NoSuchElementException;
import java.util.UUID;
import java.util.stream.Collectors;

Expand All @@ -20,8 +20,6 @@ public class ReportService {

private final ReportRepository reportRepository;



public List<ReportModel> findAllReports() {
return reportRepository.findAll()
.stream()
Expand All @@ -37,42 +35,40 @@ public ReportModel addNewReport(ReportModel reportModel) {


public ReportModel findReportById(UUID id) {
Optional<Report> optionalReport = reportRepository.findReportById(id);
if (optionalReport.isPresent()) {
Report report = optionalReport.get();
return Mapper.mapReportEntityToModel(report);
}
//TODO
// If the report with the specified ID does not exist, you can throw an exception or return null
return null;
Report report = reportRepository.findReportById(id)
.orElseThrow(() -> {
String message = "Report not found with id: " + id;
log.error(message);
throw new NoSuchElementException("Report not found with id: " + id);
});
return Mapper.mapReportEntityToModel(report);
}

public ReportModel modifyAnExistingReport(UUID id, ReportModel model) {
Optional<Report> optionalExistingReport = reportRepository.findById(id);
if (optionalExistingReport.isPresent()) {
Report existingReport = optionalExistingReport.get();
Report report = reportRepository.findReportById(id)
.orElseThrow(() -> {
String message = "Report not found with id: " + id;
log.error(message);
throw new NoSuchElementException("Report not found with id: " + id);
});

// Update the properties of the existing report with the values from the model
existingReport.setLitter(model.getLitter());
// Update the properties of the existing report with the values from the model
report.setLitter(model.getLitter());

// Save the updated report in the repository
Report updatedReport = reportRepository.save(existingReport);
// Save the updated report in the repository
Report updatedReport = reportRepository.save(report);

// Map the updated report entity to a ReportModel and return it
return Mapper.mapReportEntityToModel(updatedReport);
}
//TODO
// If the report with the specified ID does not exist, you can throw an exception or return null
return null;
// Map the updated report entity to a ReportModel and return it
return Mapper.mapReportEntityToModel(updatedReport);
}

public void deleteExistingReport(UUID id) {
Optional<Report> optionalExistingReport = reportRepository.findById(id);
if (optionalExistingReport.isPresent()) {
reportRepository.deleteById(id);
} else {
//TODO
// If the report with the specified ID does not exist, you can throw an exception or return null
}
Report report = reportRepository.findReportById(id)
.orElseThrow(() -> {
String message = "Report not found with id: " + id;
log.error(message);
throw new NoSuchElementException("Report not found with id: " + id);
});
reportRepository.deleteById(report.getId());
}
}
Loading