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 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(@PathVariable String id) { topicRepository.findById(id) .orElseThrow(() -> new NoSuchElementException("Topic not found.")); return ResponseEntity.ok(conceptReportService.listReports(id)); } @GetMapping("/{reportId}") public ResponseEntity get(@PathVariable String id, @PathVariable UUID reportId) { topicRepository.findById(id) .orElseThrow(() -> new NoSuchElementException("Topic not found.")); Map topicNames = topicRepository.findAll().stream() .collect(Collectors.toMap(Topic::getId, Topic::getName, (a, b) -> a)); return ResponseEntity.ok(conceptReportService.getReport(reportId, topicNames)); } }