refactor(transcription): split reorderBlocks for command-query separation
Some checks failed
CI / Unit & Component Tests (push) Failing after 1m46s
CI / Backend Unit Tests (push) Failing after 2m26s
CI / E2E Tests (push) Has started running
CI / Unit & Component Tests (pull_request) Failing after 1m11s
CI / Backend Unit Tests (pull_request) Failing after 2m24s
CI / E2E Tests (pull_request) Failing after 1h25m31s
Some checks failed
CI / Unit & Component Tests (push) Failing after 1m46s
CI / Backend Unit Tests (push) Failing after 2m26s
CI / E2E Tests (push) Has started running
CI / Unit & Component Tests (pull_request) Failing after 1m11s
CI / Backend Unit Tests (pull_request) Failing after 2m24s
CI / E2E Tests (pull_request) Failing after 1h25m31s
TranscriptionService.reorderBlocks() now returns void (command). Controller calls listBlocks() separately after reorder (query). Updated test to match new void signature. Fixes @Felix: "reorderBlocks violates command-query separation" Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -77,7 +77,8 @@ public class TranscriptionBlockController {
|
||||
public List<TranscriptionBlock> reorderBlocks(
|
||||
@PathVariable UUID documentId,
|
||||
@RequestBody ReorderTranscriptionBlocksDTO dto) {
|
||||
return transcriptionService.reorderBlocks(documentId, dto);
|
||||
transcriptionService.reorderBlocks(documentId, dto);
|
||||
return transcriptionService.listBlocks(documentId);
|
||||
}
|
||||
|
||||
@GetMapping("/{blockId}/history")
|
||||
|
||||
@@ -107,14 +107,13 @@ public class TranscriptionService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<TranscriptionBlock> reorderBlocks(UUID documentId, ReorderTranscriptionBlocksDTO dto) {
|
||||
public void reorderBlocks(UUID documentId, ReorderTranscriptionBlocksDTO dto) {
|
||||
List<UUID> blockIds = dto.getBlockIds();
|
||||
for (int i = 0; i < blockIds.size(); i++) {
|
||||
TranscriptionBlock block = getBlock(documentId, blockIds.get(i));
|
||||
block.setSortOrder(i);
|
||||
blockRepository.save(block);
|
||||
}
|
||||
return blockRepository.findByDocumentIdOrderBySortOrderAsc(documentId);
|
||||
}
|
||||
|
||||
public List<TranscriptionBlockVersion> getBlockHistory(UUID documentId, UUID blockId) {
|
||||
|
||||
@@ -184,7 +184,6 @@ class TranscriptionServiceTest {
|
||||
when(blockRepository.findByIdAndDocumentId(id2, docId)).thenReturn(Optional.of(block2));
|
||||
when(blockRepository.findByIdAndDocumentId(id1, docId)).thenReturn(Optional.of(block1));
|
||||
when(blockRepository.save(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
when(blockRepository.findByDocumentIdOrderBySortOrderAsc(docId)).thenReturn(List.of(block2, block1));
|
||||
|
||||
ReorderTranscriptionBlocksDTO dto = new ReorderTranscriptionBlocksDTO(List.of(id2, id1));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user