first implementation - image/drawing integration
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.aiteacher.book;
|
||||
|
||||
import com.aiteacher.document.FigureEntity;
|
||||
import com.aiteacher.document.FigureRepository;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -15,9 +17,11 @@ import java.util.UUID;
|
||||
public class BookController {
|
||||
|
||||
private final BookService bookService;
|
||||
private final FigureRepository figureRepository;
|
||||
|
||||
public BookController(BookService bookService) {
|
||||
public BookController(BookService bookService, FigureRepository figureRepository) {
|
||||
this.bookService = bookService;
|
||||
this.figureRepository = figureRepository;
|
||||
}
|
||||
|
||||
@PostMapping(consumes = "multipart/form-data")
|
||||
@@ -46,6 +50,36 @@ public class BookController {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/reembed")
|
||||
public ResponseEntity<Map<String, Object>> reembed(@PathVariable UUID id) {
|
||||
Book book = bookService.reembed(id);
|
||||
return ResponseEntity.accepted().body(Map.of(
|
||||
"bookId", book.getId(),
|
||||
"status", BookStatus.PROCESSING.name()
|
||||
));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/figures")
|
||||
public ResponseEntity<List<FigureResponse>> figures(@PathVariable UUID id) {
|
||||
bookService.getById(id); // 404 if not found
|
||||
List<FigureResponse> responses = figureRepository.findAllByBookId(id)
|
||||
.stream()
|
||||
.map(f -> toFigureResponse(id, f))
|
||||
.toList();
|
||||
return ResponseEntity.ok(responses);
|
||||
}
|
||||
|
||||
private FigureResponse toFigureResponse(UUID bookId, FigureEntity f) {
|
||||
String filename = f.getImagePath().substring(f.getImagePath().lastIndexOf('/') + 1);
|
||||
String imageUrl = "/api/v1/figures/" + bookId + "/" + filename;
|
||||
return new FigureResponse(
|
||||
f.getId(), f.getLabel(), f.getCaption(),
|
||||
f.getFigureType().name(), f.getPage(), imageUrl,
|
||||
f.getSectionId(),
|
||||
null // section title not eagerly loaded here
|
||||
);
|
||||
}
|
||||
|
||||
private Map<String, Object> toSummaryResponse(Book book) {
|
||||
return Map.of(
|
||||
"id", book.getId(),
|
||||
|
||||
Reference in New Issue
Block a user