Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.springKaiser.business.joinvideoandtag;

public class JoinVideoAndTagDto {
private int tagId;
private int videoId;

public int getTagId() {
return tagId;
}

public void setTagId(int tagId) {
this.tagId = tagId;
}

public int getVideoId() {
return videoId;
}

public void setVideoId(int videoId) {
this.videoId = videoId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.example.springKaiser.business.joinvideoandtag;

public class JoinVideoAndTagMapper {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.springKaiser.business.joinvideoandtag;

import com.example.springKaiser.entities.JoinVideoAndTag;
import com.example.springKaiser.repositories.JoinVideoAndTagRepository;
import com.example.springKaiser.repositories.TagRepository;
import com.example.springKaiser.repositories.VideoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JoinVideoAndTagService {
@Autowired
TagRepository tagRepository;

@Autowired
VideoRepository videoRepository;

@Autowired
JoinVideoAndTagRepository joinVideoAndTagRepository;

public List<JoinVideoAndTag> listVideoAndTag(){
List<JoinVideoAndTag> listVideoAndTag = joinVideoAndTagRepository.findAll();
return listVideoAndTag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public List<ListPlaylistByChannelDto> listPlaylistNameByChannelName(String chann
listPlaylistByChannelDto.setPlaylistName(playlistVideos.get(i).getPlaylistName().getPlaylistname());
listPlaylistByChannelDto.setChannelName(playlistVideos.get(i).getVideo().getChannel().getChannelName());
listPlaylistByChannelDtos.add(listPlaylistByChannelDto);

}
return listPlaylistByChannelDtos;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.springKaiser.business.tags;

public class TagDto {
private String tagName;

public String getTagName() {
return tagName;
}

public void setTagName(String tagName) {
this.tagName = tagName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.example.springKaiser.business.tags;

public class TagMapper {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.springKaiser.business.tags;

import com.example.springKaiser.entities.Video;
import com.example.springKaiser.repositories.TagRepository;
import com.example.springKaiser.entities.Tags;
import com.example.springKaiser.repositories.VideoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

public class TagService {
@Autowired
TagRepository tagRepository;

@Autowired
VideoRepository videoRepository;

// search videoName, if exists, load tagDetails, convert tagDetails to string object, add extra tag to string object, save back into object and database
// public String addTagToVideo(String tagName, String videoName){
// Video video = videoRepository.findOneByName(videoName);
//
// return "Success";
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public List<Video> listVideo() {
return listVideo;
}

// Homework
// Homework
public List<VideoDto> listVideoDto() {
// List<VideoDto> videoDtoList = videoRepository.findAll().stream().map(this::convertDto).collect(Collectors.toList());
// return videoDtoList;
Expand All @@ -50,7 +50,13 @@ public List<VideoDto> listVideoDto() {
// videoEntry.setLikes(9);
// return convertDto(videoEntry);
// }).collect(Collectors.toList());
return ((List<Video>) videoRepository.findAll()).stream().map(this::convertDto).collect(Collectors.toList());
// return ((List<Video>) videoRepository.findAll()).stream().map(this::convertDto).collect(Collectors.toList());
List<VideoDto> videoDtoList = new ArrayList<>();
List<Video> videoListFromRepository = videoRepository.findAll();
for (Video videoList : videoListFromRepository) {
videoDtoList.add(this.convertDto(videoList));
}
return videoDtoList;
}

//Homework
Expand All @@ -60,7 +66,7 @@ private VideoDto convertDto(Video video){
dto.setComments(video.getComments());
dto.setLikes(video.getLikes());
dto.setViews(video.getViews());
Channel channel = channelRepository.findById(video.getChannel().getId()).get();
// Channel channel = channelRepository.findById(video.getChannel().getId()).get();
dto.setChannelId(video.getChannel().getId());
return dto;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.springKaiser.controller;

import com.example.springKaiser.business.joinvideoandtag.JoinVideoAndTagService;
import com.example.springKaiser.entities.JoinVideoAndTag;
import com.example.springKaiser.repositories.JoinVideoAndTagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class JoinVideoAndTagController {
@Autowired
JoinVideoAndTagRepository joinVideoAndTagRepository;

@Autowired
JoinVideoAndTagService joinVideoAndTagService;

@GetMapping("/listVideoAndTag")
public List<JoinVideoAndTag> listJoinVideoAndTag(){
return joinVideoAndTagService.listVideoAndTag();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public List<PlaylistName> listPlaylist(){
return playlistService.listPlaylist();
}

@GetMapping("/listPlaylistVideo")
public List<PlaylistVideo> listPlaylistVideo(){
return playlistService.listPlaylistVideo();
}

@GetMapping("/findPlaylist/{playlistName}")
public String playlistNames(@PathVariable String playlistName){
return playlistService.countPlaylist(playlistName);
Expand All @@ -63,7 +68,6 @@ public ListPlaylistByVideoNameAndChannelNameDto listPlaylistByVideoNameAndChanne

@GetMapping("/findPlaylistByChannelName/{channelName}")
public List<ListPlaylistByChannelDto> playlistNameByChannelName(@PathVariable String channelName){

return playlistService.listPlaylistNameByChannelName(channelName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.springKaiser.controller;

import com.example.springKaiser.entities.Tags;
import com.example.springKaiser.repositories.TagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TagController {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.example.springKaiser.entities;

import jakarta.persistence.*;
import lombok.Data;

@Data
@Entity
@Table(name = "joinvideoandtagtable", schema = "public")

public class JoinVideoAndTag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@ManyToOne
@JoinColumn(name = "tagid")
private Tags tag;

@ManyToOne
@JoinColumn(name = "videoid")
private Video video;

public JoinVideoAndTag(){}

public JoinVideoAndTag(Integer id, Tags tag, Video video) {
this.id = id;
this.tag = tag;
this.video = video;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public Tags getTag() {
return tag;
}

public void setTag(Tags tag) {
this.tag = tag;
}

public Video getVideo() {
return video;
}

public void setVideo(Video video) {
this.video = video;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.springKaiser.entities;

import jakarta.persistence.*;
import lombok.Data;

@Data
@Entity
@Table(name = "tagtable", schema = "public")
public class Tags {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

private String tagname;

public Tags(){}

public Tags(Integer id, String tagname) {
this.id = id;
this.tagname = tagname;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTagName() {
return tagname;
}

public void setTagName(String tagname) {
this.tagname = tagname;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.springKaiser.repositories;
import com.example.springKaiser.entities.JoinVideoAndTag;
import org.springframework.data.jpa.repository.JpaRepository;

//public interface JoinVideoAndTagRepository{
//
//}
public interface JoinVideoAndTagRepository extends JpaRepository<JoinVideoAndTag, Integer>{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.springKaiser.repositories;

import com.example.springKaiser.entities.Tags;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

//public interface TagRepository {
//
//}
public interface TagRepository extends JpaRepository<Tags, Integer> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ databaseChangeLog:
- include:
file: classpath:db/changelog/scripts/18_playlist.sql
- include:
file: classpath:db/changelog/scripts/19_extra_channel_data.sql
file: classpath:db/changelog/scripts/19_extra_channel_data.sql
- include:
file: classpath:db/changelog/scripts/20_tags.sql
- include:
file: classpath:db/changelog/scripts/21_add_data.sql
28 changes: 28 additions & 0 deletions backend/kaiser/src/main/resources/db/changelog/scripts/20_tags.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE TABLE if not exists tagTable (
id INT,
tagName VARCHAR,
PRIMARY KEY (id)
);

create sequence if not exists tag_id_seq;

alter table tagTable alter column id set default nextval('tag_id_seq');

INSERT INTO tagTable(tagName)
VALUES
('Music'),
('FPS'),
('Video Game'),
('Anime'),
('RPG');

CREATE TABLE if not exists joinvideoandtagtable (
id INT,
tagId INT,
videoId INT,
PRIMARY KEY (id)
);

create sequence if not exists videotag_id_seq;

alter table joinvideoandtagtable alter column id set default nextval('videotag_id_seq');
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
INSERT INTO joinvideoandtagtable(tagId, videoId)
VALUES
(1, 1),
(2, 2),
(3, 3),
(4, 4),
(5, 5),
(5, 6);
Loading