Skip to content

Commit

Permalink
refactor(*): remove monitored field
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Jul 30, 2023
1 parent a77f47b commit 1f801ad
Show file tree
Hide file tree
Showing 12 changed files with 7 additions and 169 deletions.
1 change: 0 additions & 1 deletion apps/backend/src/entities/user_to_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub metadata_id: i32,
pub last_updated_on: DateTimeUtc,
pub monitored: bool,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
8 changes: 0 additions & 8 deletions apps/backend/src/migrator/m20230417_000002_create_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ impl MigrationName for Migration {
/// - the user has it in their seen history
/// - added it to a collection
/// - has reviewed it
/// - added to their monitored media
#[derive(Iden)]
pub enum UserToMetadata {
Table,
UserId,
MetadataId,
LastUpdatedOn,
Monitored,
}

#[derive(
Expand Down Expand Up @@ -101,12 +99,6 @@ impl MigrationTrait for Migration {
.integer()
.not_null(),
)
.col(
ColumnDef::new(UserToMetadata::Monitored)
.boolean()
.default(false)
.not_null(),
)
.primary_key(
Index::create()
.name("pk-user_metadata")
Expand Down
37 changes: 0 additions & 37 deletions apps/backend/src/migrator/m20230727_000021_add_monitored_field.rs

This file was deleted.

2 changes: 0 additions & 2 deletions apps/backend/src/migrator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ mod m20230717_000017_change_rating_value;
mod m20230717_000018_add_user_sink_integrations_field;
mod m20230722_000019_add_state_field;
mod m20230726_000020_rename_table;
mod m20230727_000021_add_monitored_field;
mod m20230728_000022_add_user_summary_field;
mod m20230728_000023_add_metadata_status_field;
mod m20230728_000024_add_user_notification_field;
Expand Down Expand Up @@ -62,7 +61,6 @@ impl MigratorTrait for Migrator {
Box::new(m20230717_000018_add_user_sink_integrations_field::Migration),
Box::new(m20230722_000019_add_state_field::Migration),
Box::new(m20230726_000020_rename_table::Migration),
Box::new(m20230727_000021_add_monitored_field::Migration),
Box::new(m20230728_000022_add_user_summary_field::Migration),
Box::new(m20230728_000023_add_metadata_status_field::Migration),
Box::new(m20230728_000024_add_user_notification_field::Migration),
Expand Down
63 changes: 3 additions & 60 deletions apps/backend/src/miscellaneous/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ use crate::{
UserYankIntegrationSetting, UserYankIntegrations,
},
utils::{
associate_user_with_metadata, convert_naive_to_utc, get_case_insensitive_like_query,
get_user_and_metadata_association, user_id_from_token, MemoryAuthData, MemoryDatabase,
AUTHOR, COOKIE_NAME, DOCS_LINK, PAGE_LIMIT, REPOSITORY_LINK, VERSION,
convert_naive_to_utc, get_case_insensitive_like_query, user_id_from_token, MemoryAuthData,
MemoryDatabase, AUTHOR, COOKIE_NAME, DOCS_LINK, PAGE_LIMIT, REPOSITORY_LINK, VERSION,
},
};

Expand Down Expand Up @@ -417,7 +416,6 @@ enum MediaGeneralFilter {
OnAHold,
Completed,
Unseen,
Monitored,
}

#[derive(Debug, Serialize, Deserialize, InputObject, Clone)]
Expand Down Expand Up @@ -486,8 +484,6 @@ struct UserMediaDetails {
media_details: GraphqlMediaDetails,
/// The next episode of this media.
next_episode: Option<UserMediaNextEpisode>,
/// Whether the user is monitoring this media.
is_monitored: bool,
}

#[derive(SimpleObject)]
Expand Down Expand Up @@ -1023,19 +1019,6 @@ impl MiscellaneousMutation {
service.admin_account_guard(user_id).await?;
service.delete_user(to_delete_user_id).await
}

/// Toggle the monitor on a media for a user.
async fn toggle_media_monitor(
&self,
gql_ctx: &Context<'_>,
to_monitor_metadata_id: i32,
) -> Result<bool> {
let service = gql_ctx.data_unchecked::<Arc<MiscellaneousService>>();
let user_id = service.user_id_from_ctx(gql_ctx).await?;
service
.toggle_media_monitor(user_id, to_monitor_metadata_id)
.await
}
}

pub struct MiscellaneousService {
Expand Down Expand Up @@ -1375,15 +1358,13 @@ impl MiscellaneousService {
}
});
let next_episode = next_episode.filter(|ne| ne.episode_number.is_some());
let is_monitored = self.get_monitored_status(user_id, metadata_id).await?;
Ok(UserMediaDetails {
collections,
reviews,
history,
in_progress,
media_details,
next_episode,
is_monitored,
})
}

Expand All @@ -1406,13 +1387,6 @@ impl MiscellaneousService {
) -> Result<SearchResults<MediaListItem>> {
let meta = UserToMetadata::find()
.filter(user_to_metadata::Column::UserId.eq(user_id))
.apply_if(
match input.filter.as_ref().and_then(|f| f.general) {
Some(MediaGeneralFilter::Monitored) => Some(true),
_ => None,
},
|query, v| query.filter(user_to_metadata::Column::Monitored.eq(v)),
)
.all(&self.db)
.await
.unwrap();
Expand Down Expand Up @@ -1583,7 +1557,6 @@ impl MiscellaneousService {
.collect_vec()
};
match s {
MediaGeneralFilter::Monitored => {}
MediaGeneralFilter::All => {}
MediaGeneralFilter::Rated => {
main_select = main_select
Expand Down Expand Up @@ -1982,9 +1955,7 @@ impl MiscellaneousService {
.await
.unwrap();
let is_in_collection = meta_ids.contains(&u.metadata_id);
// if the metadata is monitored
let is_monitored = u.monitored;
if seen_count + reviewed_count == 0 && !is_in_collection && !is_monitored {
if seen_count + reviewed_count == 0 && !is_in_collection {
tracing::debug!(
"Removing user_to_metadata = {id:?}",
id = (u.user_id, u.metadata_id)
Expand Down Expand Up @@ -3973,34 +3944,6 @@ impl MiscellaneousService {
};
Ok(())
}

async fn toggle_media_monitor(
&self,
user_id: i32,
to_monitor_metadata_id: i32,
) -> Result<bool> {
let metadata =
associate_user_with_metadata(&user_id, &to_monitor_metadata_id, &self.db).await?;
let new_monitored_value = !metadata.monitored;
let mut metadata: user_to_metadata::ActiveModel = metadata.into();
metadata.monitored = ActiveValue::Set(new_monitored_value);
metadata.save(&self.db).await?;
Ok(new_monitored_value)
}

async fn get_monitored_status(
&self,
user_id: i32,
to_monitor_metadata_id: i32,
) -> Result<bool> {
let metadata =
get_user_and_metadata_association(&user_id, &to_monitor_metadata_id, &self.db).await;
Ok(if let Some(m) = metadata {
m.monitored
} else {
false
})
}
}

fn modify_seen_elements(all_seen: &mut [seen::Model]) {
Expand Down
4 changes: 0 additions & 4 deletions apps/frontend/src/pages/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,6 @@ const Page: NextPageWithLayout = () => {
() => MediaGeneralFilter.InProgress,
)
.with("UNSEEN", () => MediaGeneralFilter.Unseen)
.with(
"MONITORED",
() => MediaGeneralFilter.Monitored,
)
.otherwise((_v) => {
throw new Error("Invalid filter selected");
});
Expand Down
25 changes: 0 additions & 25 deletions apps/frontend/src/pages/media/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ import {
type RemoveMediaFromCollectionMutationVariables,
type ReviewItem,
SeenState,
ToggleMediaMonitorDocument,
type ToggleMediaMonitorMutationVariables,
UserMediaDetailsDocument,
} from "@ryot/generated/graphql/backend/graphql";
import { changeCase, getInitials } from "@ryot/utilities";
Expand Down Expand Up @@ -448,18 +446,6 @@ const Page: NextPageWithLayout = () => {
userMediaDetails.refetch();
},
});
const toggleMediaMonitor = useMutation({
mutationFn: async (variables: ToggleMediaMonitorMutationVariables) => {
const { toggleMediaMonitor } = await gqlClient.request(
ToggleMediaMonitorDocument,
variables,
);
return toggleMediaMonitor;
},
onSuccess: () => {
userMediaDetails.refetch();
},
});
const deleteSeenItem = useMutation({
mutationFn: async (variables: DeleteSeenItemMutationVariables) => {
const { deleteSeenItem } = await gqlClient.request(
Expand Down Expand Up @@ -1060,17 +1046,6 @@ const Page: NextPageWithLayout = () => {
/>
) : null}
</>
<Button
variant="outline"
onClick={() => {
toggleMediaMonitor.mutate({
toMonitorMetadataId: metadataId,
});
}}
>
{userMediaDetails.data.isMonitored ? "Stop" : "Start"}{" "}
monitoring
</Button>
<Button
variant="outline"
onClick={() => {
Expand Down
1 change: 0 additions & 1 deletion apps/frontend/src/pages/settings/preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
Box,
Container,
Divider,
Group,
SimpleGrid,
Stack,
Switch,
Expand Down
9 changes: 2 additions & 7 deletions libs/generated/src/graphql/backend/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const documents = {
"mutation RegisterUser($input: UserInput!) {\n registerUser(input: $input) {\n __typename\n ... on RegisterError {\n error\n }\n ... on IdObject {\n id\n }\n }\n}": types.RegisterUserDocument,
"mutation RemoveMediaFromCollection($metadataId: Int!, $collectionName: String!) {\n removeMediaFromCollection(\n metadataId: $metadataId\n collectionName: $collectionName\n ) {\n id\n }\n}": types.RemoveMediaFromCollectionDocument,
"mutation TestUserNotificationPlatform($notificationId: Int!) {\n testUserNotificationPlatform(notificationId: $notificationId)\n}": types.TestUserNotificationPlatformDocument,
"mutation ToggleMediaMonitor($toMonitorMetadataId: Int!) {\n toggleMediaMonitor(toMonitorMetadataId: $toMonitorMetadataId)\n}": types.ToggleMediaMonitorDocument,
"mutation UpdateAllMetadata {\n updateAllMetadata\n}": types.UpdateAllMetadataDocument,
"mutation UpdateUser($input: UpdateUserInput!) {\n updateUser(input: $input) {\n id\n }\n}": types.UpdateUserDocument,
"mutation UpdateUserPreference($input: UpdateUserPreferenceInput!) {\n updateUserPreference(input: $input)\n}": types.UpdateUserPreferenceDocument,
Expand All @@ -62,7 +61,7 @@ const documents = {
"query UserAuthTokens {\n userAuthTokens {\n lastUsedOn\n token\n }\n}": types.UserAuthTokensDocument,
"query UserDetails {\n userDetails {\n __typename\n ... on User {\n id\n email\n name\n lot\n }\n }\n}": types.UserDetailsDocument,
"query UserIntegrations {\n userIntegrations {\n id\n lot\n description\n timestamp\n }\n}": types.UserIntegrationsDocument,
"fragment SeenPart on Seen {\n id\n progress\n state\n startedOn\n finishedOn\n lastUpdatedOn\n showInformation {\n episode\n season\n }\n podcastInformation {\n episode\n }\n}\n\nquery UserMediaDetails($metadataId: Int!) {\n userMediaDetails(metadataId: $metadataId) {\n mediaDetails {\n ...MediaDetailsPart\n }\n collections {\n id\n name\n }\n inProgress {\n ...SeenPart\n }\n history {\n ...SeenPart\n }\n reviews {\n id\n rating\n text\n spoiler\n visibility\n showSeason\n showEpisode\n podcastEpisode\n postedOn\n postedBy {\n id\n name\n }\n }\n isMonitored\n nextEpisode {\n seasonNumber\n episodeNumber\n }\n }\n}": types.SeenPartFragmentDoc,
"fragment SeenPart on Seen {\n id\n progress\n state\n startedOn\n finishedOn\n lastUpdatedOn\n showInformation {\n episode\n season\n }\n podcastInformation {\n episode\n }\n}\n\nquery UserMediaDetails($metadataId: Int!) {\n userMediaDetails(metadataId: $metadataId) {\n mediaDetails {\n ...MediaDetailsPart\n }\n collections {\n id\n name\n }\n inProgress {\n ...SeenPart\n }\n history {\n ...SeenPart\n }\n reviews {\n id\n rating\n text\n spoiler\n visibility\n showSeason\n showEpisode\n podcastEpisode\n postedOn\n postedBy {\n id\n name\n }\n }\n nextEpisode {\n seasonNumber\n episodeNumber\n }\n }\n}": types.SeenPartFragmentDoc,
"query UserNotificationPlatforms {\n userNotificationPlatforms {\n id\n description\n timestamp\n }\n}": types.UserNotificationPlatformsDocument,
"query UserPreferences {\n userPreferences {\n notifications {\n episodeReleased\n statusChanged\n releaseDateChanged\n numberOfSeasonsChanged\n }\n featuresEnabled {\n media {\n anime\n audioBooks\n books\n manga\n movies\n podcasts\n shows\n videoGames\n }\n }\n }\n}": types.UserPreferencesDocument,
"query Users {\n users {\n id\n name\n lot\n }\n}": types.UsersDocument,
Expand Down Expand Up @@ -186,10 +185,6 @@ export function graphql(source: "mutation RemoveMediaFromCollection($metadataId:
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "mutation TestUserNotificationPlatform($notificationId: Int!) {\n testUserNotificationPlatform(notificationId: $notificationId)\n}"): (typeof documents)["mutation TestUserNotificationPlatform($notificationId: Int!) {\n testUserNotificationPlatform(notificationId: $notificationId)\n}"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "mutation ToggleMediaMonitor($toMonitorMetadataId: Int!) {\n toggleMediaMonitor(toMonitorMetadataId: $toMonitorMetadataId)\n}"): (typeof documents)["mutation ToggleMediaMonitor($toMonitorMetadataId: Int!) {\n toggleMediaMonitor(toMonitorMetadataId: $toMonitorMetadataId)\n}"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down Expand Up @@ -281,7 +276,7 @@ export function graphql(source: "query UserIntegrations {\n userIntegrations {\
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "fragment SeenPart on Seen {\n id\n progress\n state\n startedOn\n finishedOn\n lastUpdatedOn\n showInformation {\n episode\n season\n }\n podcastInformation {\n episode\n }\n}\n\nquery UserMediaDetails($metadataId: Int!) {\n userMediaDetails(metadataId: $metadataId) {\n mediaDetails {\n ...MediaDetailsPart\n }\n collections {\n id\n name\n }\n inProgress {\n ...SeenPart\n }\n history {\n ...SeenPart\n }\n reviews {\n id\n rating\n text\n spoiler\n visibility\n showSeason\n showEpisode\n podcastEpisode\n postedOn\n postedBy {\n id\n name\n }\n }\n isMonitored\n nextEpisode {\n seasonNumber\n episodeNumber\n }\n }\n}"): (typeof documents)["fragment SeenPart on Seen {\n id\n progress\n state\n startedOn\n finishedOn\n lastUpdatedOn\n showInformation {\n episode\n season\n }\n podcastInformation {\n episode\n }\n}\n\nquery UserMediaDetails($metadataId: Int!) {\n userMediaDetails(metadataId: $metadataId) {\n mediaDetails {\n ...MediaDetailsPart\n }\n collections {\n id\n name\n }\n inProgress {\n ...SeenPart\n }\n history {\n ...SeenPart\n }\n reviews {\n id\n rating\n text\n spoiler\n visibility\n showSeason\n showEpisode\n podcastEpisode\n postedOn\n postedBy {\n id\n name\n }\n }\n isMonitored\n nextEpisode {\n seasonNumber\n episodeNumber\n }\n }\n}"];
export function graphql(source: "fragment SeenPart on Seen {\n id\n progress\n state\n startedOn\n finishedOn\n lastUpdatedOn\n showInformation {\n episode\n season\n }\n podcastInformation {\n episode\n }\n}\n\nquery UserMediaDetails($metadataId: Int!) {\n userMediaDetails(metadataId: $metadataId) {\n mediaDetails {\n ...MediaDetailsPart\n }\n collections {\n id\n name\n }\n inProgress {\n ...SeenPart\n }\n history {\n ...SeenPart\n }\n reviews {\n id\n rating\n text\n spoiler\n visibility\n showSeason\n showEpisode\n podcastEpisode\n postedOn\n postedBy {\n id\n name\n }\n }\n nextEpisode {\n seasonNumber\n episodeNumber\n }\n }\n}"): (typeof documents)["fragment SeenPart on Seen {\n id\n progress\n state\n startedOn\n finishedOn\n lastUpdatedOn\n showInformation {\n episode\n season\n }\n podcastInformation {\n episode\n }\n}\n\nquery UserMediaDetails($metadataId: Int!) {\n userMediaDetails(metadataId: $metadataId) {\n mediaDetails {\n ...MediaDetailsPart\n }\n collections {\n id\n name\n }\n inProgress {\n ...SeenPart\n }\n history {\n ...SeenPart\n }\n reviews {\n id\n rating\n text\n spoiler\n visibility\n showSeason\n showEpisode\n podcastEpisode\n postedOn\n postedBy {\n id\n name\n }\n }\n nextEpisode {\n seasonNumber\n episodeNumber\n }\n }\n}"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading

0 comments on commit 1f801ad

Please sign in to comment.