refactor(ocr): return TrainingInfoResponse directly from getTrainingInfo endpoint
Remove the intermediate Map<String,Object> and return the typed record directly
so OpenAPI codegen produces a concrete TypeScript type. Fixes lastRun serializing
as {} (empty object) instead of null when no training run exists.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,6 @@ import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBo
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -131,19 +130,8 @@ public class OcrController {
|
||||
|
||||
@GetMapping("/api/ocr/training-info")
|
||||
@RequirePermission(Permission.ADMIN)
|
||||
public Map<String, Object> getTrainingInfo() {
|
||||
OcrTrainingService.TrainingInfoResponse info = ocrTrainingService.getTrainingInfo();
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("availableBlocks", info.availableBlocks());
|
||||
result.put("totalOcrBlocks", info.totalOcrBlocks());
|
||||
result.put("availableDocuments", info.availableDocuments());
|
||||
result.put("availableSegBlocks", info.availableSegBlocks());
|
||||
result.put("ocrServiceAvailable", info.ocrServiceAvailable());
|
||||
result.put("lastRun", info.lastRun() != null ? info.lastRun() : Map.of());
|
||||
result.put("runs", info.runs());
|
||||
result.put("personNames", info.personNames());
|
||||
return result;
|
||||
public OcrTrainingService.TrainingInfoResponse getTrainingInfo() {
|
||||
return ocrTrainingService.getTrainingInfo();
|
||||
}
|
||||
|
||||
private UUID resolveUserId(Authentication authentication) {
|
||||
|
||||
@@ -264,6 +264,18 @@ class OcrControllerTest {
|
||||
.andExpect(jsonPath("$.personNames." + personId).value("Max Mustermann"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithMockUser(authorities = "ADMIN")
|
||||
void getTrainingInfo_serializes_null_lastRun_as_json_null() throws Exception {
|
||||
OcrTrainingService.TrainingInfoResponse info =
|
||||
new OcrTrainingService.TrainingInfoResponse(0, 0, 0, 0, false, null, List.of(), Map.of());
|
||||
when(ocrTrainingService.getTrainingInfo()).thenReturn(info);
|
||||
|
||||
mockMvc.perform(get("/api/ocr/training-info"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.lastRun").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithMockUser(authorities = "READ_ALL")
|
||||
void getDocumentOcrStatus_returnsNone_whenNoOcrJobExists() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user