first implementation
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.aiteacher.topic;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/topics")
|
||||
public class TopicController {
|
||||
|
||||
private final TopicConfigLoader topicConfigLoader;
|
||||
private final TopicSummaryService topicSummaryService;
|
||||
|
||||
public TopicController(TopicConfigLoader topicConfigLoader,
|
||||
TopicSummaryService topicSummaryService) {
|
||||
this.topicConfigLoader = topicConfigLoader;
|
||||
this.topicSummaryService = topicSummaryService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Topic>> list() {
|
||||
return ResponseEntity.ok(topicConfigLoader.getAll());
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/summary")
|
||||
public ResponseEntity<TopicSummaryResponse> generateSummary(@PathVariable String id) {
|
||||
Topic topic = topicConfigLoader.findById(id)
|
||||
.orElseThrow(() -> new NoSuchElementException("Topic not found."));
|
||||
|
||||
TopicSummaryResponse response = topicSummaryService.generateSummary(topic);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user