feat: add Stream table & boilerplate
This commit is contained in:
31
src/main/java/com/ddf/vodsystem/entities/Stream.java
Normal file
31
src/main/java/com/ddf/vodsystem/entities/Stream.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.ddf.vodsystem.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "streams")
|
||||
@Data
|
||||
public class Stream {
|
||||
@Id
|
||||
@Column(name = "id", nullable = false, unique = true)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JsonIgnore
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private User user;
|
||||
|
||||
@Column(name = "start_date")
|
||||
private LocalDateTime startDate;
|
||||
|
||||
@Column(name = "end_date")
|
||||
private LocalDateTime endDate;
|
||||
|
||||
@Column(name = "last_seen")
|
||||
private LocalDateTime lastSeen;
|
||||
}
|
||||
@@ -34,5 +34,8 @@ public class User {
|
||||
|
||||
@Column(name = "created_at")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "stream_key")
|
||||
private String streamKey;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.ddf.vodsystem.repositories;
|
||||
|
||||
import com.ddf.vodsystem.entities.Stream;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface StreamRepository extends JpaRepository<Stream, Long> {
|
||||
}
|
||||
@@ -11,4 +11,7 @@ import java.util.Optional;
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
@Query("SELECT u FROM User u WHERE u.googleId = ?1")
|
||||
Optional<User> findByGoogleId(String googleId);
|
||||
|
||||
@Query("SELECT u FROM User u WHERE u.streamKey = ?1")
|
||||
Optional<User> findByStreamKey(String streamKey);
|
||||
}
|
||||
|
||||
24
src/main/java/com/ddf/vodsystem/services/StreamService.java
Normal file
24
src/main/java/com/ddf/vodsystem/services/StreamService.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.ddf.vodsystem.services;
|
||||
|
||||
import com.ddf.vodsystem.entities.User;
|
||||
import com.ddf.vodsystem.repositories.StreamRepository;
|
||||
|
||||
public class StreamService {
|
||||
private StreamRepository streamRepository;
|
||||
|
||||
public StreamService(StreamRepository streamRepository) {
|
||||
this.streamRepository = streamRepository;
|
||||
}
|
||||
|
||||
public void startStream(User user) {
|
||||
|
||||
}
|
||||
|
||||
public void endStream(User user) {
|
||||
|
||||
}
|
||||
|
||||
public void heartbeatStream(User user) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,10 @@ public class UserService {
|
||||
return jwtService.generateToken(user.getId());
|
||||
}
|
||||
|
||||
public Optional<User> getUserByStreamKey(String streamKey) {
|
||||
return userRepository.findByStreamKey(streamKey);
|
||||
}
|
||||
|
||||
private User createOrUpdateUser(User user) {
|
||||
Optional<User> existingUser = userRepository.findByGoogleId(user.getGoogleId());
|
||||
|
||||
|
||||
@@ -9,9 +9,21 @@ CREATE TABLE IF NOT EXISTS users (
|
||||
name VARCHAR(100) NOT NULL,
|
||||
profile_picture_url VARCHAR(255),
|
||||
role INTEGER DEFAULT 0,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
stream_key VARCHAR(64) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS streams (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
user_id BIGSERIAL,
|
||||
start_time TIMESTAMPTZ DEFAULT NOW(),
|
||||
end_time TIMESTAMPTZ DEFAULT NULL,
|
||||
last_seen TIMESTAMPTZ DEFAULT NULL
|
||||
|
||||
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)
|
||||
|
||||
CREATE TABLE IF NOT EXISTS clips (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user