Skip to content

Commit

Permalink
Export comments (#315)
Browse files Browse the repository at this point in the history
* style(backend): add newline

* feat(backend): return comments for reviews

* fix(backend): get authentication working on routes

* refactor(backend): change name of review struct

* chore(docs): change name of struct

* fix(frontend): add divider b/w reviews

* fix(frontend): remove staletime for user creator details

* build(backend): bump version
  • Loading branch information
IgnisDa authored Aug 31, 2023
1 parent 4dd9848 commit 63afd3d
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 202 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ryot"
version = "2.12.1"
version = "2.12.2"
edition = "2021"
repository = "https://github.com/IgnisDa/ryot"
license = "GPL-V3"
Expand Down
10 changes: 2 additions & 8 deletions apps/backend/src/importer/movary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ pub async fn import(input: DeployMovaryImportInput) -> Result<ImportResult> {
reviews: vec![ImportOrExportItemRating {
// DEV: Rates items out of 10
rating: Some(record.user_rating.saturating_mul(dec!(10))),
review: None,
show_season_number: None,
show_episode_number: None,
podcast_episode_number: None,
..Default::default()
}],
collections: vec![],
})
Expand Down Expand Up @@ -149,10 +146,7 @@ pub async fn import(input: DeployMovaryImportInput) -> Result<ImportResult> {
if review.is_some() {
reviews.push(ImportOrExportItemRating {
review,
rating: None,
show_season_number: None,
show_episode_number: None,
podcast_episode_number: None,
..Default::default()
})
}
media.push(ImportOrExportMediaItem {
Expand Down
26 changes: 15 additions & 11 deletions apps/backend/src/miscellaneous/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ use crate::{
media::{
AddMediaToCollection, AnimeSpecifics, AudioBookSpecifics, BookSpecifics,
CreateOrUpdateCollectionInput, CreatorExtraInformation, ImportOrExportItemRating,
ImportOrExportItemReview, ImportOrExportMediaItem, ImportOrExportMediaItemSeen,
ImportOrExportPersonItem, MangaSpecifics, MediaCreatorSearchItem, MediaDetails,
MediaListItem, MediaSearchItem, MediaSearchItemResponse, MediaSearchItemWithLot,
MediaSpecifics, MetadataCreator, MetadataImage, MetadataImages, MetadataSuggestion,
MovieSpecifics, PodcastSpecifics, PostReviewInput, ProgressUpdateError,
ProgressUpdateErrorVariant, ProgressUpdateInput, ProgressUpdateResultUnion,
ReviewComment, ReviewCommentUser, ReviewComments, SeenOrReviewExtraInformation,
SeenPodcastExtraInformation, SeenShowExtraInformation, ShowSpecifics,
UserMediaReminder, UserSummary, VideoGameSpecifics, Visibility,
ImportOrExportItemReview, ImportOrExportItemReviewComment, ImportOrExportMediaItem,
ImportOrExportMediaItemSeen, ImportOrExportPersonItem, MangaSpecifics,
MediaCreatorSearchItem, MediaDetails, MediaListItem, MediaSearchItem,
MediaSearchItemResponse, MediaSearchItemWithLot, MediaSpecifics, MetadataCreator,
MetadataImage, MetadataImages, MetadataSuggestion, MovieSpecifics, PodcastSpecifics,
PostReviewInput, ProgressUpdateError, ProgressUpdateErrorVariant, ProgressUpdateInput,
ProgressUpdateResultUnion, ReviewCommentUser, ReviewComments,
SeenOrReviewExtraInformation, SeenPodcastExtraInformation, SeenShowExtraInformation,
ShowSpecifics, UserMediaReminder, UserSummary, VideoGameSpecifics, Visibility,
},
IdObject, SearchDetails, SearchInput, SearchResults, StoredUrl,
},
Expand Down Expand Up @@ -319,7 +319,7 @@ struct ReviewItem {
show_season: Option<i32>,
show_episode: Option<i32>,
podcast_episode: Option<i32>,
comments: Vec<ReviewComment>,
comments: Vec<ImportOrExportItemReviewComment>,
}

#[derive(Debug, SimpleObject)]
Expand Down Expand Up @@ -5013,7 +5013,7 @@ impl MiscellaneousService {
comment.liked_by.remove(&user_id);
} else {
let user = user_by_id(&self.db, user_id).await?;
comments.push(ReviewComment {
comments.push(ImportOrExportItemReviewComment {
id: nanoid!(20),
text: input.text.unwrap(),
user: ReviewCommentUser {
Expand Down Expand Up @@ -5057,5 +5057,9 @@ fn get_review_export_item(rev: ReviewItem) -> ImportOrExportItemRating {
show_season_number: rev.show_season,
show_episode_number: rev.show_episode,
podcast_episode_number: rev.podcast_episode,
comments: match rev.comments.is_empty() {
true => None,
false => Some(rev.comments),
},
}
}
8 changes: 6 additions & 2 deletions apps/backend/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ pub mod media {
pub show_episode_number: Option<i32>,
/// If for a podcast, the episode for which this review was for.
pub podcast_episode_number: Option<i32>,
/// The comments attached to this review.
pub comments: Option<Vec<ImportOrExportItemReviewComment>>,
}

/// Details about a specific media item that needs to be imported or exported.
Expand Down Expand Up @@ -730,6 +732,7 @@ pub mod media {
Default,
Hash,
SimpleObject,
Type,
)]
pub struct ReviewCommentUser {
pub id: i32,
Expand All @@ -746,8 +749,9 @@ pub mod media {
Deserialize,
Default,
SimpleObject,
Type,
)]
pub struct ReviewComment {
pub struct ImportOrExportItemReviewComment {
pub id: String,
pub text: String,
pub user: ReviewCommentUser,
Expand All @@ -758,7 +762,7 @@ pub mod media {

// FIXME: Remove this
#[derive(Clone, Debug, PartialEq, FromJsonQueryResult, Eq, Serialize, Deserialize, Default)]
pub struct ReviewComments(pub Vec<ReviewComment>);
pub struct ReviewComments(pub Vec<ImportOrExportItemReviewComment>);

#[derive(
Clone,
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/providers/google_books.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl MediaProvider for GoogleBooksService {
})
}
}

impl GoogleBooksService {
fn google_books_response_to_search_response(
&self,
Expand Down
7 changes: 6 additions & 1 deletion apps/backend/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ pub async fn json_export(
Extension(exercise_service): Extension<Arc<ExerciseService>>,
ctx: AuthContext,
) -> Result<Json<serde_json::Value>, (StatusCode, Json<serde_json::Value>)> {
let user_id = ctx.user_id.unwrap();
let user_id = ctx.user_id.ok_or_else(|| {
(
StatusCode::FORBIDDEN,
Json(json!({"err": "User is not authenticated"})),
)
})?;
let resp = match export_type.as_str() {
"all" => {
let media = media_service.export_media(user_id).await.unwrap();
Expand Down
Loading

0 comments on commit 63afd3d

Please sign in to comment.