TopicFetchTaskController.java
3.0 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
// keyword/controller/TopicFetchTaskController.java
package com.aigeo.keyword.controller;
import com.aigeo.keyword.entity.TopicFetchTask;
import com.aigeo.common.enums.TaskStatus;
import com.aigeo.keyword.service.TopicFetchTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/api/topic-fetch-tasks")
public class TopicFetchTaskController {
@Autowired
private TopicFetchTaskService topicFetchTaskService;
@GetMapping
public List<TopicFetchTask> getAllTasks() {
return topicFetchTaskService.getAllTasks();
}
@GetMapping("/{id}")
public ResponseEntity<TopicFetchTask> getTaskById(@PathVariable Integer id) {
Optional<TopicFetchTask> task = topicFetchTaskService.getTaskById(id);
return task.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@GetMapping("/company/{companyId}")
public List<TopicFetchTask> getTasksByCompanyId(@PathVariable Integer companyId) {
return topicFetchTaskService.getTasksByCompanyId(companyId);
}
@GetMapping("/user/{userId}")
public List<TopicFetchTask> getTasksByUserId(@PathVariable Integer userId) {
return topicFetchTaskService.getTasksByUserId(userId);
}
@GetMapping("/source/{topicSourceId}")
public List<TopicFetchTask> getTasksByTopicSourceId(@PathVariable Integer topicSourceId) {
return topicFetchTaskService.getTasksByTopicSourceId(topicSourceId);
}
@GetMapping("/status/{status}")
public List<TopicFetchTask> getTasksByStatus(@PathVariable TaskStatus status) {
return topicFetchTaskService.getTasksByStatus(status);
}
@PostMapping
public TopicFetchTask createTask(@RequestBody TopicFetchTask task) {
return topicFetchTaskService.saveTask(task);
}
@PutMapping("/{id}")
public ResponseEntity<TopicFetchTask> updateTask(@PathVariable Integer id,
@RequestBody TopicFetchTask taskDetails) {
Optional<TopicFetchTask> task = topicFetchTaskService.getTaskById(id);
if (task.isPresent()) {
TopicFetchTask updatedTask = task.get();
updatedTask.setKeywords(taskDetails.getKeywords());
updatedTask.setStatus(taskDetails.getStatus());
updatedTask.setResultCount(taskDetails.getResultCount());
updatedTask.setRawResponse(taskDetails.getRawResponse());
TopicFetchTask savedTask = topicFetchTaskService.saveTask(updatedTask);
return ResponseEntity.ok(savedTask);
} else {
return ResponseEntity.notFound().build();
}
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteTask(@PathVariable Integer id) {
topicFetchTaskService.deleteTask(id);
return ResponseEntity.noContent().build();
}
}