ADD Clip Table

This commit is contained in:
2025-06-13 10:35:52 +02:00
parent fa120fe7b5
commit 0986552059
5 changed files with 95 additions and 2 deletions

View File

@@ -0,0 +1,49 @@
package com.ddf.vodsystem.entities;
import jakarta.persistence.*;
import lombok.Data;
import lombok.ToString;
import java.time.LocalDateTime;
@Entity
@Table(name = "clips")
@Data
public class Clip {
@Id
@Column(name = "id", nullable = false, unique = true)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@ToString.Exclude
@JoinColumn(name = "user_id", nullable = false)
private User user;
@Column(name = "title", nullable = false, length = 255)
private String title;
@Column(name = "description")
private String description;
@Column(name = "created_at")
private LocalDateTime createdAt;
@Column(name = "width", nullable = false)
private Integer width;
@Column(name = "height", nullable = false)
private Integer height;
@Column(name = "fps", nullable = false)
private Integer fps;
@Column(name = "duration", nullable = false)
private Integer duration;
@Column(name = "file_size", nullable = false)
private Long fileSize;
@Column(name = "video_path", nullable = false, length = 255)
private String videoPath;
}

View File

@@ -9,9 +9,9 @@ import java.time.LocalDateTime;
@Table(name = "users") @Table(name = "users")
@Data @Data
public class User { public class User {
@Id
@Column(name = "id", nullable = false, unique = true) @Column(name = "id", nullable = false, unique = true)
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
private Long id; private Long id;
@Column(name = "google_id", nullable = false, unique = true) @Column(name = "google_id", nullable = false, unique = true)
@@ -26,6 +26,9 @@ public class User {
@Column(name = "name", nullable = false) @Column(name = "name", nullable = false)
private String name; private String name;
@Column(name = "role", nullable = false)
private Integer role; // 0: user, 1: admin
@Column(name = "created_at", nullable = false) @Column(name = "created_at", nullable = false)
private LocalDateTime createdAt; private LocalDateTime createdAt;
} }

View File

@@ -0,0 +1,9 @@
package com.ddf.vodsystem.repositories;
import com.ddf.vodsystem.entities.Clip;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ClipRepository extends JpaRepository<Clip, Long> {
}

View File

@@ -9,4 +9,17 @@ VALUES
(7, 'google-uid-007', 'unicorn', 'sparkle@rainbow.com', 'Princess Sparklehoof'), (7, 'google-uid-007', 'unicorn', 'sparkle@rainbow.com', 'Princess Sparklehoof'),
(8, 'google-uid-008', 'pirate', 'blackbeard@seas.com', 'Edward Teach'), (8, 'google-uid-008', 'pirate', 'blackbeard@seas.com', 'Edward Teach'),
(9, 'google-uid-009', 'detective', 'holmes@bakerstreet.uk', 'Sherlock Holmes'), (9, 'google-uid-009', 'detective', 'holmes@bakerstreet.uk', 'Sherlock Holmes'),
(10, 'google-uid-010', 'timey', 'docbrown@delorean.net', 'Dr. Emmett Brown'); (10, 'google-uid-010', 'timey', 'docbrown@delorean.net', 'Dr. Emmett Brown');
INSERT INTO clips (id, user_id, title, description, width, height, fps, duration, file_size, video_path)
VALUES
(1, 4, 'Fireworks Over Hobbiton', 'A magical display of fireworks by Gandalf.', 1920, 1080, 30, 120, 104857600, '/videos/fireworks_hobbiton.mp4'),
(2, 5, 'Catnap Chronicles', 'Sir Whiskers McFluff naps in 12 different positions.', 1280, 720, 24, 60, 52428800, '/videos/catnap_chronicles.mp4'),
(3, 6, 'Bite My Shiny Metal...', 'Bender shows off his new upgrades.', 1920, 1080, 60, 45, 73400320, '/videos/bender_upgrades.mp4'),
(4, 7, 'Rainbow Dash', 'Princess Sparklehoof gallops across a double rainbow.', 1920, 1080, 30, 90, 67108864, '/videos/rainbow_dash.mp4'),
(5, 8, 'Pirate Karaoke Night', 'Blackbeard sings sea shanties with his crew.', 1280, 720, 25, 180, 157286400, '/videos/pirate_karaoke.mp4'),
(6, 9, 'The Case of the Missing Sandwich', 'Sherlock Holmes investigates a lunchtime mystery.', 1920, 1080, 30, 75, 50331648, '/videos/missing_sandwich.mp4'),
(7, 10, '88 Miles Per Hour', 'Doc Brown demonstrates time travel with style.', 1920, 1080, 60, 30, 41943040, '/videos/88mph.mp4'),
(8, 1, 'Alice in Videoland', 'Alice explores a surreal digital wonderland.', 1280, 720, 30, 150, 94371840, '/videos/alice_videoland.mp4'),
(9, 2, 'Bob''s Building Bonanza', 'Bob constructs a house out of cheese.', 1920, 1080, 24, 200, 209715200, '/videos/bob_cheesehouse.mp4'),
(10, 3, 'Carol''s Coding Catastrophe', 'Carol debugs a spaghetti codebase.', 1280, 720, 30, 100, 73400320, '/videos/carol_coding.mp4');

View File

@@ -1,9 +1,28 @@
DROP TABLE IF EXISTS clips;
DROP TABLE IF EXISTS users; DROP TABLE IF EXISTS users;
CREATE TABLE IF NOT EXISTS users ( CREATE TABLE IF NOT EXISTS users (
id BIGINT PRIMARY KEY, id BIGINT PRIMARY KEY,
google_id VARCHAR(64), google_id VARCHAR(64),
username VARCHAR(50) NOT NULL UNIQUE, username VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE, email VARCHAR(100) NOT NULL UNIQUE,
name VARCHAR(100) NOT NULL, name VARCHAR(100) NOT NULL,
role INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS clips (
id BIGINT PRIMARY KEY,
user_id BIGINT NOT NULL,
title VARCHAR(255) NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
width INTEGER NOT NULL,
height INTEGER NOT NULL,
fps INTEGER NOT NULL,
duration INTEGER NOT NULL,
file_size BIGINT NOT NULL,
video_path VARCHAR(255) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
); );