Skip to content

Commit 36b93e7

Browse files
committed
IPTE-165: Refactoring WorksController
1 parent 8562439 commit 36b93e7

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

src/main/java/de/doubleslash/keeptime/REST_API/controller/WorksController.java

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,23 @@ public class WorksController {
3131
private WorkRepository workRepository;
3232
private Model model;
3333

34-
public WorksController(final WorkRepository workRepository, final Controller controller,Model model) {
34+
public WorksController(final WorkRepository workRepository, final Controller controller, Model model) {
3535
this.workRepository = workRepository;
36-
this.model= model;
36+
this.model = model;
3737
}
3838

39-
// @GetMapping("")
40-
// public List<Work> getWorks(@RequestParam(name = "name", required = false) final String project) {
41-
// List<Work> works = workRepository.findAll();
42-
//
43-
// if (project != null) {
44-
// return works.stream().filter(work -> work.getProject().equals(project)).collect(Collectors.toList());
45-
// }
46-
// return works;
47-
// }
48-
@GetMapping("")
49-
public List<WorkDTO> getWorks(@RequestParam(name = "name", required = false) final String projectName) {
50-
List<Work> works = workRepository.findAll();
51-
52-
Stream<Work> workStream = works.stream();
53-
54-
if (projectName != null) {
55-
workStream = workStream.filter(work -> work.getProject().getName().equals(projectName));
56-
}
39+
@GetMapping("")
40+
public List<WorkDTO> getWorks(@RequestParam(name = "name", required = false) final String projectName) {
41+
List<Work> works = workRepository.findAll();
5742

58-
return workStream.map(WorkMapper.INSTANCE::workToWorkDTO)
59-
.collect(Collectors.toList());
60-
}
43+
Stream<Work> workStream = works.stream();
6144

45+
if (projectName != null) {
46+
workStream = workStream.filter(work -> work.getProject().getName().equals(projectName));
47+
}
6248

49+
return workStream.map(WorkMapper.INSTANCE::workToWorkDTO).collect(Collectors.toList());
50+
}
6351

6452
@PutMapping("/{id}")
6553
public ResponseEntity<WorkDTO> editWork(@PathVariable("id") Long workId, @RequestBody WorkDTO newValuedWorkDTO) {
@@ -74,7 +62,6 @@ public ResponseEntity<WorkDTO> editWork(@PathVariable("id") Long workId, @Reques
7462
workToBeEdited.setNotes(newValuedWork.getNotes());
7563
workToBeEdited.setProject(newValuedWork.getProject());
7664

77-
7865
Work editedWork = workRepository.save(workToBeEdited);
7966

8067
return ResponseEntity.ok(WorkMapper.INSTANCE.workToWorkDTO(editedWork));
@@ -83,7 +70,6 @@ public ResponseEntity<WorkDTO> editWork(@PathVariable("id") Long workId, @Reques
8370
}
8471
}
8572

86-
8773
@DeleteMapping("/{id}")
8874
public ResponseEntity<String> deleteWork(@PathVariable final long id) {
8975
Optional<Work> optionalWork = workRepository.findById(id);
@@ -96,8 +82,7 @@ public ResponseEntity<String> deleteWork(@PathVariable final long id) {
9682
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Work with the ID " + id + " not found");
9783
}
9884
}
99-
100-
85+
10186
@GetMapping("/current")
10287
public ResponseEntity<WorkDTO> getCurrentWork() {
10388
Work workProjects = model.activeWorkItem.get();

0 commit comments

Comments
 (0)