- Database: Update -> Drop and Create

- Removed PostConstruct from services
- Extended Video with MANYTOONE Playlist
- Extended Video with ONETOONE creator
- Extended Playlist with MANYTOMANY with videos
- Created Creator
- Extended Creator with OneToMany to videos
- VideoController now listens to POST on /fire, expects RequestBody input:true
This commit is contained in:
Reeverflow
2026-02-22 18:37:53 +01:00
parent 44ccc885ee
commit afbff59d49
8 changed files with 59 additions and 8 deletions

View File

@@ -6,11 +6,13 @@ import com.example.video_downloader.entity.Playlist;
import com.example.video_downloader.entity.Video;
import com.example.video_downloader.services.PlaylistService;
import com.example.video_downloader.services.VideoService;
import com.example.video_downloader.services.YTDLPService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
@RestController
@@ -24,11 +26,19 @@ public class VideoController {
@Autowired
private PlaylistService playlistService;
@Autowired
private YTDLPService ytdlpService;
@Data
private static class Response {
private Long id;
}
@Data
private static class Trigger {
private boolean input;
}
@PostMapping(path = "/videos")
public Response saveNewVideo(@RequestBody SaveNewVideoRequest request){
@@ -56,4 +66,14 @@ public class VideoController {
return ResponseEntity.ok(videoService.getVideoById(id));
}
@PostMapping(path = "/fire")
public int getJobDone(@RequestBody Trigger trigger) throws IOException, InterruptedException {
int statusCode = 200;
if(trigger.input) {
ytdlpService.validateVideos();
}
return statusCode;
}
}

View File

@@ -4,7 +4,6 @@ import lombok.Data;
@Data
public class SaveNewPlaylistRequest {
private String playlist_name;
private String playlistName;
private String url;
}

View File

@@ -5,5 +5,4 @@ import lombok.Data;
@Data
public class SaveNewVideoRequest {
private String url;
}

View File

@@ -0,0 +1,20 @@
package com.example.video_downloader.entity;
import jakarta.persistence.*;
import lombok.Data;
import java.util.List;
@Data
@Entity
public class Creator {
@Id
@GeneratedValue
private Long id;
private String name;
private String url;
@OneToMany(mappedBy = "creator")
private List<Video> videos;
}

View File

@@ -17,12 +17,17 @@ public class Playlist {
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private String playlist_name;
private String playlistName;
private String url;
private StatusEnum status;
@OneToMany(mappedBy = "playlist", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Video> videos = new ArrayList<>();
@ManyToMany
@JoinTable(
name = "video_playlist",
joinColumns = @JoinColumn(name = "playlist_id"),
inverseJoinColumns = @JoinColumn(name = "video_id")
)
private List<Video> videos;
}

View File

@@ -26,4 +26,10 @@ public class Video {
@JoinColumn(name = "playlist_id")
private Playlist playlist;
@OneToOne
@JoinColumn(name = "creator_id")
private Creator creator;
}

View File

@@ -5,6 +5,7 @@ import com.example.video_downloader.entity.Video;
import com.example.video_downloader.repositories.VideoRepository;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import java.io.IOException;
@@ -13,6 +14,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
@Service
public class YTDLPService {
@Autowired
@@ -24,7 +26,6 @@ public class YTDLPService {
@Autowired
private ProcessService processService;
@PostConstruct
public void validateVideos() throws HttpClientErrorException, IOException, InterruptedException {
List<Video> response = videoRepository.findByStatus(StatusEnum.NEW);
for(Video video : response) {
@@ -34,6 +35,7 @@ public class YTDLPService {
if(Files.exists(filePath) && Files.isRegularFile(filePath)) {
System.out.println("Apparently it exists mate.");
video.setFullPath(String.valueOf(filePath));
video.setStatus(StatusEnum.SAVED);
} else {
System.out.println("Nah it does not exist mate.");

View File

@@ -2,4 +2,4 @@ spring.application.name=video_downloader
spring.datasource.url = jdbc:postgresql://localhost:5432/videos
spring.datasource.username = postgres
spring.datasource.password = 5995
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.ddl-auto = create-drop