54 lines
1.9 KiB
Java
54 lines
1.9 KiB
Java
package com.aiteacher.topic;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.NoSuchElementException;
|
|
import java.util.UUID;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/v1/topics")
|
|
public class TopicController {
|
|
|
|
private final TopicRepository topicRepository;
|
|
private final TopicSummaryService topicSummaryService;
|
|
|
|
public TopicController(TopicRepository topicRepository,
|
|
TopicSummaryService topicSummaryService) {
|
|
this.topicRepository = topicRepository;
|
|
this.topicSummaryService = topicSummaryService;
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<List<Topic>> list() {
|
|
return ResponseEntity.ok(topicRepository.findAll());
|
|
}
|
|
|
|
@PostMapping("/{id}/summary")
|
|
public ResponseEntity<TopicSummaryResponse> generateSummary(@PathVariable String id) {
|
|
Topic topic = topicRepository.findById(id)
|
|
.orElseThrow(() -> new NoSuchElementException("Topic not found."));
|
|
|
|
TopicSummaryResponse response = topicSummaryService.generateSummary(topic);
|
|
return ResponseEntity.ok(response);
|
|
}
|
|
|
|
@GetMapping("/{id}/summaries")
|
|
public ResponseEntity<List<SavedSummaryItem>> listSummaries(@PathVariable String id) {
|
|
topicRepository.findById(id)
|
|
.orElseThrow(() -> new NoSuchElementException("Topic not found."));
|
|
|
|
return ResponseEntity.ok(topicSummaryService.listSummaries(id));
|
|
}
|
|
|
|
@GetMapping("/{id}/summaries/{summaryId}")
|
|
public ResponseEntity<TopicSummaryResponse> getSummary(@PathVariable String id,
|
|
@PathVariable UUID summaryId) {
|
|
topicRepository.findById(id)
|
|
.orElseThrow(() -> new NoSuchElementException("Topic not found."));
|
|
|
|
return ResponseEntity.ok(topicSummaryService.getSummary(summaryId));
|
|
}
|
|
}
|