Repository navigation
Expand file tree
/
Copy pathTopicController.java
More file actions
93 lines (73 loc) · 2.14 KB
/
Copy pathTopicController.java
File metadata and controls
93 lines (73 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package hello.controller;
import hello.model.Topic;
import hello.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class TopicController {
@Autowired
private TopicService topicService;
/**
* Get all Topic
* @return
*/
@RequestMapping("/topic")
public List<Topic> getAllTopics() {
return topicService.getAllTopics();
}
/**
* get Topic with ID
* @param id
* @return
*/
@RequestMapping("/topic/{id}")
public ResponseEntity<Topic> getTopicWithID(@PathVariable String id) {
return topicService.getTopicWithId(id)
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.notFound().build());
}
/**
* Add a new topic in list
* @param topic
*/
@RequestMapping(method = RequestMethod.POST, value = "/topic")
public void addTopic(@RequestBody Topic topic) {
topicService.addTopic(topic);
}
/**
* Update Topic in List with id
* @param id
* @param topic
*/
@RequestMapping(method = RequestMethod.PUT, value = "/topic/{id}")
public void updateTopic(@PathVariable String id, @RequestBody Topic topic) {
topicService.updateTopic(id, topic);
}
/**
* Delete a topic with ID
* @param id
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/topic/{id}")
public void deleteTopic(@PathVariable String id) {
topicService.deleteTopic(id);
}
/**
* Get all topics with Id length greater then minimum length
* @param minLength
* @return
*/
@RequestMapping(value = "/topic/minimum/length/{minLength}")
public List<Topic> filterMinimumLengthForId(@PathVariable Integer minLength) {
return topicService.filterMinimumLengthForId(minLength);
}
/**
* Sort with Id
* @return
*/
@RequestMapping("/topic/sort")
public List<Topic> sortTopicsWithID() {
return topicService.sortTopicsWithID();
}
}