Skip to content

Commit eda2f44

Browse files
committed
refactor(backend): Add back fromDto method and controller method #1644
1 parent 83fead2 commit eda2f44

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

backend/src/main/java/ch/puzzle/okr/controller/EvaluationViewController.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,14 @@ public EvaluationViewController(EvaluationViewMapper evaluationViewMapper,
3838
@ApiResponse(responseCode = "404", description = "The quarter or one of the teams were not found", content = @Content),
3939
@ApiResponse(responseCode = "401", description = "Not Authorized", content = @Content) })
4040
@GetMapping("")
41-
public ResponseEntity<EvaluationDto> getEvaluation(
42-
@RequestParam(name = "team") List<Long> teamIds,
43-
@RequestParam(name = "quarter") Long quarterId) {
44-
45-
List<EvaluationViewId> ids = teamIds.stream()
46-
.map(teamId -> EvaluationViewId.Builder.builder()
47-
.withTeamId(teamId)
48-
.withQuarterId(quarterId)
49-
.build())
50-
.toList();
51-
52-
EvaluationDto dto = evaluationViewMapper.toDto(
53-
evaluationViewBusinessService.findByIds(ids)
54-
);
55-
56-
return ResponseEntity.ok(dto);
41+
public ResponseEntity<EvaluationDto> getEvaluation(@RequestParam(name = "team")
42+
@Parameter(description = "List of Team ids the statistics are requested for") List<Long> teamIds,
43+
@RequestParam(name = "quarter")
44+
@Parameter(description = "Quarter id the statistics are requested for ") Long quarterId) {
45+
return ResponseEntity
46+
.status(HttpStatus.OK)
47+
.body(evaluationViewMapper
48+
.toDto(evaluationViewBusinessService
49+
.findByIds(evaluationViewMapper.fromDto(teamIds, quarterId))));
5750
}
5851
}

backend/src/main/java/ch/puzzle/okr/mapper/EvaluationViewMapper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import ch.puzzle.okr.dto.EvaluationDto;
44
import ch.puzzle.okr.models.evaluation.EvaluationView;
55
import java.util.List;
6+
7+
import ch.puzzle.okr.models.evaluation.EvaluationViewId;
68
import ch.puzzle.okr.service.business.EvaluationViewBusinessService;
79
import org.springframework.stereotype.Component;
810

@@ -30,4 +32,8 @@ public EvaluationDto toDto(List<EvaluationView> views) {
3032
evaluationService.calculateKeyResultsInStretchSum(views)
3133
);
3234
}
33-
}
35+
36+
public List<EvaluationViewId> fromDto(List<Long> teamIds, Long quarterId) {
37+
return teamIds.stream().map(teamId -> new EvaluationViewId(teamId, quarterId)).toList();
38+
}
39+
}

0 commit comments

Comments
 (0)