Skip to content

Commit 3af0ef3

Browse files
committed
feat: add endpoint to retrieve latest evaluation by control ID
1 parent 8ecf6b4 commit 3af0ef3

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

backend/src/main/java/com/park/utmstack/service/compliance/config/UtmComplianceControlEvaluationLatestService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.springframework.data.domain.Pageable;
1111
import org.springframework.stereotype.Service;
1212

13+
import javax.persistence.EntityNotFoundException;
14+
1315
@Service
1416
public class UtmComplianceControlEvaluationLatestService {
1517

@@ -36,6 +38,12 @@ public Page<UtmComplianceControlLatestEvaluationDto> getControlsWithLastEvaluati
3638
return UtmComplianceControlLatestEvaluationMapper.toDto(controlDto, lastEval);
3739
});
3840
}
41+
42+
public UtmComplianceControlLatestEvaluationDto getControlWithLastEvaluation(Long controlId) {
43+
UtmComplianceControlConfigDto controlDto = configService.findById(controlId);
44+
var lastEval = elasticsearchService.getLatestControlEvaluation(controlId);
45+
return UtmComplianceControlLatestEvaluationMapper.toDto(controlDto, lastEval);
46+
}
3947
}
4048

4149

backend/src/main/java/com/park/utmstack/web/rest/compliance/config/UtmComplianceControlLatestEvaluationResource.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,13 @@ public ResponseEntity<List<UtmComplianceControlLatestEvaluationDto>> getControls
3030
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(controls, "/control-config/get-by-section");
3131
return ResponseEntity.ok().headers(headers).body(controls.getContent());
3232
}
33+
34+
35+
@GetMapping("/get-by-id/{controlId}")
36+
public ResponseEntity<UtmComplianceControlLatestEvaluationDto> getControlLatestEvaluationById(
37+
@PathVariable Long controlId) {
38+
var control = latestEvaluationService.getControlWithLastEvaluation(controlId);
39+
return ResponseEntity.ok(control);
40+
}
3341
}
3442

0 commit comments

Comments
 (0)