Forgot to commit and push. After the base is done, I'll be following normal git principles.

This commit is contained in:
Reeverflow
2026-02-05 11:17:55 +01:00
parent a73221636e
commit cd6cc9812a
7 changed files with 108 additions and 0 deletions

View File

@@ -45,6 +45,13 @@
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.40</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>

View File

@@ -0,0 +1,33 @@
package com.example.video_downloader.controllers;
import com.example.video_downloader.dto.SaveNewVideoRequest;
import com.example.video_downloader.repositories.VideoRepository;
import com.example.video_downloader.services.VideoService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(path = "/video" )
@CrossOrigin(origins = "http://localhost:3000")
public class VideoController {
@Autowired
private VideoService videoService;
@Data
private class Response {
private Long id;
}
@PostMapping(path = "/video")
public Response saveNewVideo(@RequestBody SaveNewVideoRequest request){
videoService.saveNewVideo(request);
Response response = new Response();
response.setId(videoService.saveNewVideo(request).getId());
return response;
}
}

View File

@@ -0,0 +1,8 @@
package com.example.video_downloader.dto;
import lombok.Data;
@Data
public class SaveNewVideoRequest {
private String url;
}

View File

@@ -0,0 +1,5 @@
package com.example.video_downloader.entity;
public enum StatusEnum {
NEW, FAILED, SAVED
}

View File

@@ -0,0 +1,21 @@
package com.example.video_downloader.entity;
import jakarta.persistence.*;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
@Entity
@Table(name = "videos")
public class Video {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private String url;
private String ytld;
private String ytMetaData;
private StatusEnum status;
private String fullPath;
}

View File

@@ -0,0 +1,9 @@
package com.example.video_downloader.repositories;
import com.example.video_downloader.entity.Video;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface VideoRepository extends JpaRepository<Video, Long> {
}

View File

@@ -0,0 +1,25 @@
package com.example.video_downloader.services;
import com.example.video_downloader.dto.SaveNewVideoRequest;
import com.example.video_downloader.entity.StatusEnum;
import com.example.video_downloader.entity.Video;
import com.example.video_downloader.repositories.VideoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class VideoService {
@Autowired
private VideoRepository videoRepository;
public Video saveNewVideo(SaveNewVideoRequest request){
Video video = new Video();
video.setStatus(StatusEnum.NEW);
video.setUrl(request.getUrl());
videoRepository.save(video);
return video;
}
}