From a0e7c5d3c17a466c95941b3bffa3650ea73830de Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sun, 22 Dec 2024 20:19:52 +0100 Subject: [PATCH] history feature --- Cargo.lock | 2 +- migrations/0005_history.sql | 9 +++++++ src/library/history.rs | 43 +++++++++++++++++++++++++++++++++ src/library/mod.rs | 3 +++ src/main.rs | 3 ++- src/pages/components.rs | 48 +++++++++++++++++++++---------------- src/pages/user.rs | 17 +++++++++++++ src/pages/watch.rs | 9 ++++++- 8 files changed, 111 insertions(+), 23 deletions(-) create mode 100644 migrations/0005_history.sql create mode 100644 src/library/history.rs diff --git a/Cargo.lock b/Cargo.lock index 36385f6..3a7b8f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,7 +158,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "based" version = "0.1.0" -source = "git+https://git.hydrar.de/jmarya/based#291949b8c65e90aaacead7d108f77366c742125a" +source = "git+https://git.hydrar.de/jmarya/based#a89c5661208585b2a9f09d5ee337ad1c60ea9a49" dependencies = [ "bcrypt", "chrono", diff --git a/migrations/0005_history.sql b/migrations/0005_history.sql new file mode 100644 index 0000000..77d3779 --- /dev/null +++ b/migrations/0005_history.sql @@ -0,0 +1,9 @@ + +CREATE TABLE IF NOT EXISTS video_history ( + id BIGSERIAL PRIMARY KEY, + username VARCHAR(255) NOT NULL, + video_id UUID NOT NULL, + timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW(), + FOREIGN KEY (username) REFERENCES users (username) ON DELETE CASCADE, + FOREIGN KEY (video_id) REFERENCES videos (id) ON DELETE CASCADE +); diff --git a/src/library/history.rs b/src/library/history.rs new file mode 100644 index 0000000..75c8177 --- /dev/null +++ b/src/library/history.rs @@ -0,0 +1,43 @@ +use based::{auth::User, get_pg}; + +use super::Video; + +pub trait VideoHistory { + async fn last_video(&self) -> Option; + async fn insert_history(&self, vid: uuid::Uuid); + async fn history_of(&self, n: i64) -> Vec