Skip to content

Commit

Permalink
Allow order by times consumed (#1208)
Browse files Browse the repository at this point in the history
* feat(backend): allow order metadata list by times consumed

* fix(utils/dependent): use correct  query for ordering by seen count

* chore(utils/dependent): change order of match arms

* fix(utils/dependent): remove useless group
  • Loading branch information
IgnisDa authored Jan 26, 2025
1 parent 75693e1 commit 2883943
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions crates/models/media/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,12 +1263,13 @@ pub enum GraphqlSortOrder {

#[derive(Debug, Serialize, Deserialize, Enum, Clone, PartialEq, Eq, Copy, Default)]
pub enum MediaSortBy {
LastUpdated,
Title,
#[default]
ReleaseDate,
LastSeen,
UserRating,
#[default]
ReleaseDate,
LastUpdated,
TimesConsumed,
ProviderRating,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/utils/dependent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2792,7 +2792,6 @@ pub async fn metadata_list(
avg_rating_col,
)
.group_by(metadata::Column::Id)
.group_by(user_to_entity::Column::MediaReason)
.filter(user_to_entity::Column::UserId.eq(user_id))
.apply_if(input.lot, |query, v| {
query.filter(metadata::Column::Lot.eq(v))
Expand Down Expand Up @@ -2866,10 +2865,11 @@ pub async fn metadata_list(
})),
})
.apply_if(input.sort.map(|s| s.by), |query, v| match v {
MediaSortBy::Title => query.order_by(metadata::Column::Title, order_by),
MediaSortBy::TimesConsumed => query.order_by(seen::Column::Id.count(), order_by),
MediaSortBy::LastUpdated => query
.order_by(user_to_entity::Column::LastUpdatedOn, order_by)
.group_by(user_to_entity::Column::LastUpdatedOn),
MediaSortBy::Title => query.order_by(metadata::Column::Title, order_by),
MediaSortBy::ReleaseDate => query.order_by_with_nulls(
metadata::Column::PublishYear,
order_by,
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 @@ -1005,6 +1005,7 @@ export enum MediaSortBy {
LastUpdated = 'LAST_UPDATED',
ProviderRating = 'PROVIDER_RATING',
ReleaseDate = 'RELEASE_DATE',
TimesConsumed = 'TIMES_CONSUMED',
Title = 'TITLE',
UserRating = 'USER_RATING'
}
Expand Down
1 change: 1 addition & 0 deletions libs/generated/src/graphql/backend/types.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ export enum MediaSortBy {
LastUpdated = 'LAST_UPDATED',
ProviderRating = 'PROVIDER_RATING',
ReleaseDate = 'RELEASE_DATE',
TimesConsumed = 'TIMES_CONSUMED',
Title = 'TITLE',
UserRating = 'USER_RATING'
}
Expand Down

0 comments on commit 2883943

Please sign in to comment.