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