diff --git a/Cargo.lock b/Cargo.lock index 450fb25..cfd242b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1260,7 +1260,12 @@ dependencies = [ name = "sqlite" version = "0.1.0" dependencies = [ + "async-trait", + "chrono", + "domain", "sqlx", + "tracing", + "uuid", ] [[package]] diff --git a/crates/adapters/sqlite/Cargo.toml b/crates/adapters/sqlite/Cargo.toml index 5991bac..223233c 100644 --- a/crates/adapters/sqlite/Cargo.toml +++ b/crates/adapters/sqlite/Cargo.toml @@ -10,3 +10,9 @@ sqlx = { version = "0.8.6", features = [ "uuid", "macros", ] } + +domain = { workspace = true } +uuid = { workspace = true } +chrono = { workspace = true } +tracing = { workspace = true } +async-trait = { workspace = true } diff --git a/crates/adapters/sqlite/src/lib.rs b/crates/adapters/sqlite/src/lib.rs index b93cf3f..d7ad3bc 100644 --- a/crates/adapters/sqlite/src/lib.rs +++ b/crates/adapters/sqlite/src/lib.rs @@ -1,14 +1,64 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right +use domain::{ + errors::DomainError, + events::DomainEvent, + models::{DiaryEntry, DiaryFilter, Movie, Review, ReviewHistory, collections::Paginated}, + ports::MovieRepository, + value_objects::{ExternalMetadataId, MovieId, MovieTitle, ReleaseYear}, +}; +use sqlx::SqlitePool; + +pub struct SqliteMovieRepository { + pool: SqlitePool, } -#[cfg(test)] -mod tests { - use super::*; +impl SqliteMovieRepository { + pub fn new(pool: SqlitePool) -> Self { + Self { pool } + } - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); + fn map_err(e: sqlx::Error) -> DomainError { + tracing::error!("Database error: {:?}", e); + DomainError::InfrastructureError("Database operation failed".into()) + } +} + +#[async_trait::async_trait] +impl MovieRepository for SqliteMovieRepository { + async fn get_movie_by_external_id( + &self, + external_metadata_id: &ExternalMetadataId, + ) -> Result, DomainError> { + todo!() + } + + async fn get_movie_by_id(&self, movie_id: &MovieId) -> Result, DomainError> { + todo!() + } + + async fn get_movies_by_title_and_year( + &self, + title: &MovieTitle, + year: &ReleaseYear, + ) -> Result, DomainError> { + todo!() + } + + async fn upsert_movie(&self, movie: &Movie) -> Result<(), DomainError> { + todo!() + } + + async fn save_review(&self, review: &Review) -> Result { + todo!() + } + + async fn query_diary( + &self, + filter: &DiaryFilter, + ) -> Result, DomainError> { + todo!() + } + + async fn get_review_history(&self, movie_id: &MovieId) -> Result { + todo!() } } diff --git a/crates/domain/src/models/mod.rs b/crates/domain/src/models/mod.rs index edc54c1..cb85804 100644 --- a/crates/domain/src/models/mod.rs +++ b/crates/domain/src/models/mod.rs @@ -52,6 +52,24 @@ impl Movie { } } + pub fn from_persistence( + id: MovieId, + external_metadata_id: Option, + title: MovieTitle, + release_year: ReleaseYear, + director: Option, + poster_path: Option, + ) -> Self { + Self { + id, + external_metadata_id, + title, + release_year, + director, + poster_path, + } + } + pub fn update_poster(&mut self, poster_path: PosterPath) { self.poster_path = Some(poster_path); } @@ -132,6 +150,26 @@ impl Review { }) } + pub fn from_persistence( + id: ReviewId, + movie_id: MovieId, + user_id: UserId, + rating: Rating, + comment: Option, + watched_at: NaiveDateTime, + created_at: NaiveDateTime, + ) -> Self { + Self { + id, + movie_id, + user_id, + rating, + comment, + watched_at, + created_at, + } + } + pub fn id(&self) -> &ReviewId { &self.id }