Forgot to commit and push. After the base is done, I'll be following normal git principles.
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -45,6 +45,13 @@
|
|||||||
<artifactId>spring-boot-starter-webmvc</artifactId>
|
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.40</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.example.video_downloader.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SaveNewVideoRequest {
|
||||||
|
private String url;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.example.video_downloader.entity;
|
||||||
|
|
||||||
|
public enum StatusEnum {
|
||||||
|
NEW, FAILED, SAVED
|
||||||
|
}
|
||||||
21
src/main/java/com/example/video_downloader/entity/Video.java
Normal file
21
src/main/java/com/example/video_downloader/entity/Video.java
Normal 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;
|
||||||
|
}
|
||||||
@@ -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> {
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user