WebsiteChannelController.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
// website/controller/WebsiteChannelController.java
package com.aigeo.website.controller;
import com.aigeo.website.entity.WebsiteChannel;
import com.aigeo.website.service.WebsiteChannelService;
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/website-channels")
public class WebsiteChannelController {
@Autowired
private WebsiteChannelService websiteChannelService;
@GetMapping("/project/{projectId}")
public List<WebsiteChannel> getChannelsByProjectId(@PathVariable Integer projectId) {
return websiteChannelService.getChannelsByProjectId(projectId);
}
@GetMapping("/project/{projectId}/parent/{parentId}")
public List<WebsiteChannel> getChannelsByProjectIdAndParentId(
@PathVariable Integer projectId, @PathVariable Integer parentId) {
return websiteChannelService.getChannelsByProjectIdAndParentId(projectId, parentId);
}
@GetMapping("/parent/{parentId}")
public List<WebsiteChannel> getChannelsByParentId(@PathVariable Integer parentId) {
return websiteChannelService.getChannelsByParentId(parentId);
}
@GetMapping("/{id}")
public ResponseEntity<WebsiteChannel> getChannelById(@PathVariable Integer id) {
Optional<WebsiteChannel> channel = websiteChannelService.getChannelById(id);
return channel.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
public WebsiteChannel createChannel(@RequestBody WebsiteChannel channel) {
return websiteChannelService.saveChannel(channel);
}
@PutMapping("/{id}")
public ResponseEntity<WebsiteChannel> updateChannel(@PathVariable Integer id,
@RequestBody WebsiteChannel channelDetails) {
Optional<WebsiteChannel> channel = websiteChannelService.getChannelById(id);
if (channel.isPresent()) {
WebsiteChannel updatedChannel = channel.get();
updatedChannel.setName(channelDetails.getName());
updatedChannel.setPath(channelDetails.getPath());
updatedChannel.setChannelType(channelDetails.getChannelType());
updatedChannel.setDisplayOrder(channelDetails.getDisplayOrder());
updatedChannel.setIsVisibleInNav(channelDetails.getIsVisibleInNav());
updatedChannel.setParentId(channelDetails.getParentId());
WebsiteChannel savedChannel = websiteChannelService.saveChannel(updatedChannel);
return ResponseEntity.ok(savedChannel);
} else {
return ResponseEntity.notFound().build();
}
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteChannel(@PathVariable Integer id) {
websiteChannelService.deleteChannel(id);
return ResponseEntity.noContent().build();
}
}