add new concept report
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user