Skip to content

Commit

Permalink
feat: allow sorting by provider rating
Browse files Browse the repository at this point in the history
Fixes #981.
  • Loading branch information
IgnisDa committed Aug 28, 2024
1 parent 992af8f commit 3abd10a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/models/media/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ pub enum MediaSortBy {
ReleaseDate,
LastSeen,
UserRating,
ProviderRating,
}

#[derive(Debug, Serialize, Deserialize, Enum, Clone, PartialEq, Eq, Copy, Default)]
Expand Down
11 changes: 8 additions & 3 deletions crates/services/miscellaneous/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ impl MiscellaneousService {
) -> Result<SearchResults<String>> {
let preferences = user_preferences_by_id(&self.db, &user_id, &self.config).await?;

let avg_rating_col = "average_rating";
let avg_rating_col = "user_average_rating";
let cloned_user_id_1 = user_id.clone();
let cloned_user_id_2 = user_id.clone();
#[derive(Debug, FromQueryResult)]
Expand Down Expand Up @@ -1025,13 +1025,18 @@ impl MiscellaneousService {
order_by,
NullOrdering::Last,
),
MediaSortBy::LastSeen => query.order_by_with_nulls(
seen::Column::FinishedOn.max(),
order_by,
NullOrdering::Last,
),
MediaSortBy::UserRating => query.order_by_with_nulls(
Expr::col(Alias::new(avg_rating_col)),
order_by,
NullOrdering::Last,
),
MediaSortBy::LastSeen => query.order_by_with_nulls(
seen::Column::FinishedOn.max(),
MediaSortBy::ProviderRating => query.order_by_with_nulls(
metadata::Column::ProviderRating,
order_by,
NullOrdering::Last,
),
Expand Down
1 change: 1 addition & 0 deletions libs/generated/src/graphql/backend/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ export enum MediaLot {
export enum MediaSortBy {
LastSeen = 'LAST_SEEN',
LastUpdated = 'LAST_UPDATED',
ProviderRating = 'PROVIDER_RATING',
ReleaseDate = 'RELEASE_DATE',
Title = 'TITLE',
UserRating = 'USER_RATING'
Expand Down

0 comments on commit 3abd10a

Please sign in to comment.