fix: address code review issues in SQLite adapter
This commit is contained in:
@@ -76,6 +76,7 @@ impl SqliteMovieRepository {
|
|||||||
offset: i64,
|
offset: i64,
|
||||||
) -> Result<Vec<DiaryRow>, DomainError> {
|
) -> Result<Vec<DiaryRow>, DomainError> {
|
||||||
match sort {
|
match sort {
|
||||||
|
// ByRatingDesc only applies to user-scoped queries; falls back to date sort here
|
||||||
SortDirection::Descending | SortDirection::ByRatingDesc => sqlx::query_as!(
|
SortDirection::Descending | SortDirection::ByRatingDesc => sqlx::query_as!(
|
||||||
DiaryRow,
|
DiaryRow,
|
||||||
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
||||||
@@ -116,6 +117,7 @@ impl SqliteMovieRepository {
|
|||||||
offset: i64,
|
offset: i64,
|
||||||
) -> Result<Vec<DiaryRow>, DomainError> {
|
) -> Result<Vec<DiaryRow>, DomainError> {
|
||||||
match sort {
|
match sort {
|
||||||
|
// ByRatingDesc only applies to user-scoped queries; falls back to date sort here
|
||||||
SortDirection::Descending | SortDirection::ByRatingDesc => sqlx::query_as!(
|
SortDirection::Descending | SortDirection::ByRatingDesc => sqlx::query_as!(
|
||||||
DiaryRow,
|
DiaryRow,
|
||||||
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
||||||
@@ -438,13 +440,10 @@ impl MovieRepository for SqliteMovieRepository {
|
|||||||
)?,
|
)?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Some(mid), Some(uid)) => {
|
(Some(_), Some(_)) => {
|
||||||
let mid_str = mid.value().to_string();
|
return Err(DomainError::ValidationError(
|
||||||
let uid_str = uid.value().to_string();
|
"Combined movie_id + user_id filter not supported".into(),
|
||||||
tokio::try_join!(
|
));
|
||||||
self.count_user_diary_entries(&uid_str),
|
|
||||||
self.fetch_movie_diary_rows(&mid_str, &filter.sort_by, limit, offset)
|
|
||||||
)?
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -183,12 +183,6 @@ pub(crate) struct DirectorCountRow {
|
|||||||
pub count: i64,
|
pub count: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(sqlx::FromRow)]
|
|
||||||
pub(crate) struct MonthCountRow {
|
|
||||||
pub month: String,
|
|
||||||
pub count: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(sqlx::FromRow)]
|
#[derive(sqlx::FromRow)]
|
||||||
pub(crate) struct MonthlyRatingRow {
|
pub(crate) struct MonthlyRatingRow {
|
||||||
pub month: String,
|
pub month: String,
|
||||||
|
|||||||
@@ -113,10 +113,7 @@ impl UserRepository for SqliteUserRepository {
|
|||||||
)
|
)
|
||||||
.fetch_all(&self.pool)
|
.fetch_all(&self.pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(Self::map_err)?
|
||||||
tracing::error!("Database error: {:?}", e);
|
|
||||||
DomainError::InfrastructureError("Database operation failed".into())
|
|
||||||
})?
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(UserSummaryRow::to_domain)
|
.map(UserSummaryRow::to_domain)
|
||||||
.collect()
|
.collect()
|
||||||
|
|||||||
Reference in New Issue
Block a user