-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathVideoController.java
More file actions
110 lines (88 loc) · 3.05 KB
/
VideoController.java
File metadata and controls
110 lines (88 loc) · 3.05 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.example.VideoStreamingPlatform.Controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.VideoStreamingPlatform.Entity.GenreEntity;
import com.example.VideoStreamingPlatform.Entity.VideoEntity;
import com.example.VideoStreamingPlatform.Service.GenreService;
import com.example.VideoStreamingPlatform.Service.VideoService;
import reactor.core.publisher.Mono;
@Controller
public class VideoController {
@Autowired
VideoService vs;
@Autowired
GenreService gs;
//Add Video
@GetMapping("/api/admin/videos")
public String displayAddVideo(Model m) {
VideoEntity video=new VideoEntity();
m.addAttribute("video", video);
return "AddVideoForm";
}
@PostMapping("/api/admin/add/videos")
public String addVideo(@RequestParam("genre") int genre_id, VideoEntity video) {
vs.addVideo(video, genre_id);
return "redirect:/homepage";
}
// Get Video by video ID
@GetMapping("/api/videos/")
public String displayGetVideoByIdForm() {
return "GetVideoByIdForm";
}
@PostMapping("api/videos/get")
public String getVideoByVideoId(@RequestParam("video_id") int id, Model m) {
VideoEntity ve = vs.getDetailsByVideoId(id);
m.addAttribute("video", ve);
return "DisplayVideo";
}
//Get All Videos
@GetMapping("api/allVideos")
public String getAllVideos(Model m) {
List<VideoEntity> list = vs.getAllVideos();
m.addAttribute("videos", list);
return "video_list";
}
//Get Videos By Genre
@GetMapping("api/genre/videos")
public String displayGenreVideoForm() {
return "GetVideoByGenreForm";
}
@PostMapping("/api/genre/videos/display")
public String getVideosByGenre(@RequestParam("genre") int id, Model m) {
GenreEntity genre=gs.getGenreById(id);
List<VideoEntity> list=vs.getVideosByGenre(genre);
m.addAttribute("genre", genre);
m.addAttribute("video", list);
return "DisplayVideoByGenre";
}
//Update Video
@GetMapping("/updateVideo/{video_id}")
public String displayUpdateVideo(@PathVariable("video_id") int video_id, Model m) {
VideoEntity video = vs.getDetailsByVideoId(video_id);
m.addAttribute("video", video);
return "UpdateVideo";
}
@PostMapping("api/admin/videos/{id}")
public String updateGenre(@ModelAttribute VideoEntity video, @PathVariable("id") int id) {
vs.updateVideo(video, id);
return "redirect:/homepage";
}
//Delete Video
@GetMapping("/api/admin/delete/video")
public String deleteVideoForm() {
return "DeleteVideoForm";
}
@PostMapping("/api/admin/delete/video/delete")
public String deleteVideo(@RequestParam("video_id") int video_id) {
vs.deleteVideo(video_id);
return "redirect:/homepage";
}
}