51 lines
2.0 KiB
Java
51 lines
2.0 KiB
Java
package com.aiteacher.concept;
|
|
|
|
import com.aiteacher.topic.Topic;
|
|
import com.aiteacher.topic.TopicRepository;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.NoSuchElementException;
|
|
import java.util.UUID;
|
|
import java.util.stream.Collectors;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/v1/topics/{id}/concept-reports")
|
|
public class ConceptReportController {
|
|
|
|
private final TopicRepository topicRepository;
|
|
private final ConceptReportService conceptReportService;
|
|
|
|
public ConceptReportController(TopicRepository topicRepository,
|
|
ConceptReportService conceptReportService) {
|
|
this.topicRepository = topicRepository;
|
|
this.conceptReportService = conceptReportService;
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<ConceptReportResponse> generate(@PathVariable String id) {
|
|
Topic topic = topicRepository.findById(id)
|
|
.orElseThrow(() -> new NoSuchElementException("Topic not found."));
|
|
return ResponseEntity.ok(conceptReportService.generateReport(topic));
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<List<SavedConceptReportItem>> list(@PathVariable String id) {
|
|
topicRepository.findById(id)
|
|
.orElseThrow(() -> new NoSuchElementException("Topic not found."));
|
|
return ResponseEntity.ok(conceptReportService.listReports(id));
|
|
}
|
|
|
|
@GetMapping("/{reportId}")
|
|
public ResponseEntity<ConceptReportResponse> get(@PathVariable String id,
|
|
@PathVariable UUID reportId) {
|
|
topicRepository.findById(id)
|
|
.orElseThrow(() -> new NoSuchElementException("Topic not found."));
|
|
Map<String, String> topicNames = topicRepository.findAll().stream()
|
|
.collect(Collectors.toMap(Topic::getId, Topic::getName, (a, b) -> a));
|
|
return ResponseEntity.ok(conceptReportService.getReport(reportId, topicNames));
|
|
}
|
|
}
|