Skip to content

Commit

Permalink
Reviews functionality (#12)
Browse files Browse the repository at this point in the history
* refactor(backend): move func to mod parent

* feat(backend): add models for storing reviews

* refactor(backend): hoist common code to module

* fix(backend): add metadata field to review

* fix(backend): add visibility field for review

* fix(backend): use correct number for migration

* chore(backend): generate entities for reviews

* feat(backend): make review rating optional

* fix(backend): fetch correct authors for movies

* fix(backend): use correct author names for shows

* fix(frontend): do not display author names for shows

* fix(backend): wrong page being used for audible search

* fix(frontend): carousel height

* build(frontend): add humaize duration deps

* feat(frontend): display humaized durations on dashboard

* fix(frontend): autofocus fields

* feat(backend): add skeleton for reviews resolver

* feat(backend): add resolver to post/update a review

* chore(graphql): add mutation to post a review

* feat(backend): add resolver to get reviews for a media item

* chore(graphql): add query to get reviews

* feat(backend): return user id from reviews endpoint

* fix(backend): return only public reviews from endpoint

* chore(graphql): get posted on date

* feat(frontend): display reviews for media item

* feat(backend): make rating a decimal

* chore(generated): re-generate types

* fix(frontend): add autosize component around reviews panel

* fix(backend): make visibility field optional

* feat(frontend): add page to post review

* ci: update rome to nightly

* ci(frontend): apply linting warning

* fix(frontend): make reviews stacked

* feat(frontend): allow updating reviews

* fix(backend): arrange posts in reverse order

* chore(graphql): return user id from resolver

* feat(frontend): add button to edit review

* fix(frontend): remove `staletime` option from most queries

* docs: add full form of project
  • Loading branch information
IgnisDa authored May 7, 2023
1 parent e917284 commit dc9d638
Show file tree
Hide file tree
Showing 41 changed files with 943 additions and 178 deletions.
2 changes: 0 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
FROM ignisda/archlinux:latest

USER root
RUN curl -L https://github.com/rome/tools/releases/download/cli%2Fv12.0.0/rome-linux-x64 -o /usr/bin/rome
RUN chmod +x /usr/bin/rome

USER $USERNAME
RUN cargo binstall sea-orm-cli --locked --secure --no-confirm
10 changes: 5 additions & 5 deletions .helix/languages.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[[language]]
name = "typescript"
auto-format = true
formatter = { command = "rome", args = ["format", "--stdin-file-path", "source.ts"] }
formatter = { command = "npx", args = ["rome", "format", "--stdin-file-path", "source.ts"] }

[[language]]
name = "javascript"
auto-format = true
formatter = { command = "rome", args = ["format", "--stdin-file-path", "source.js"] }
formatter = { command = "npx", args = ["rome", "format", "--stdin-file-path", "source.js"] }

[[language]]
name = "json"
auto-format = true
formatter = { command = "rome", args = ["format", "--stdin-file-path", "source.json"] }
formatter = { command = "npx", args = ["rome", "format", "--stdin-file-path", "source.json"] }

[[language]]
name = "tsx"
auto-format = true
formatter = { command = "rome", args = ["format", "--stdin-file-path", "source.tsx"] }
formatter = { command = "npx", args = ["rome", "format", "--stdin-file-path", "source.tsx"] }

[[language]]
name = "jsx"
auto-format = true
formatter = { command = "rome", args = ["format", "--stdin-file-path", "source.jsx"] }
formatter = { command = "npx", args = ["rome", "format", "--stdin-file-path", "source.jsx"] }
29 changes: 29 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ryot

Ryot is a self hosted platform for tracking movies, TV shows, video games,
books and audiobooks.
**R**oll **Y**our **O**wn **T**racker (Ryot) is a self hosted platform for
tracking movies, TV shows, video games, books and audiobooks.

## Project Status

Expand Down
5 changes: 4 additions & 1 deletion apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ edition = "2021"
anyhow = "1.0.70"
apalis = { version = "0.3.6", features = ["sqlite", "extensions"] }
argon2 = "0.5.0"
async-graphql = { version = "5.0.7", features = ["chrono", "log", "uuid"] }
async-graphql = { version = "5.0.7", features = ["chrono", "decimal", "log", "uuid"] }
async-graphql-axum = "5.0.7"
axum = { version = "0.6.12", features = ["macros"] }
chrono = "0.4.24"
cookie = "0.17.0"
decimal = "2.1.0"
dotenvy = "0.15.7"
figment = { version = "0.10.8", features = ["env", "json", "toml", "yaml"] }
http = "0.2.9"
mime_guess = "2.0.4"
regex = "1.8.1"
ron = "0.8.0"
rust-embed = "6.6.1"
rust_decimal = "1.29.1"
sea-orm = { version = "0.11.1", features = [
"sqlx-mysql",
"sqlx-postgres",
Expand All @@ -29,6 +31,7 @@ sea-orm = { version = "0.11.1", features = [
"macros",
"with-chrono",
"with-uuid",
"with-rust_decimal",
"debug-print",
] }
sea-orm-migration = "0.11.1"
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/audio_books/audible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl AudibleService {
.query(&SearchQuery {
title: query.to_owned(),
num_results: LIMIT,
page: page.unwrap_or(1),
page: page.unwrap_or(1) - 1,
products_sort_by: "Relevance".to_owned(),
primary: PrimaryQuery::default(),
})
Expand Down
8 changes: 8 additions & 0 deletions apps/backend/src/entities/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum Relation {
MetadataImage,
#[sea_orm(has_one = "super::movie::Entity")]
Movie,
#[sea_orm(has_many = "super::review::Entity")]
Review,
#[sea_orm(has_many = "super::seen::Entity")]
Seen,
#[sea_orm(has_one = "super::show::Entity")]
Expand Down Expand Up @@ -61,6 +63,12 @@ impl Related<super::movie::Entity> for Entity {
}
}

impl Related<super::review::Entity> for Entity {
fn to() -> RelationDef {
Relation::Review.def()
}
}

impl Related<super::seen::Entity> for Entity {
fn to() -> RelationDef {
Relation::Seen.def()
Expand Down
18 changes: 18 additions & 0 deletions apps/backend/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,28 @@ pub mod metadata_image;
pub mod metadata_to_creator;
pub mod metadata_to_genre;
pub mod movie;
pub mod review;
pub mod seen;
pub mod show;
pub mod summary;
pub mod token;
pub mod user;
pub mod user_to_metadata;
pub mod video_game;

pub mod utils {
use async_graphql::SimpleObject;
use sea_orm::FromJsonQueryResult;
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, SimpleObject)]
pub struct SeenSeasonExtraInformation {
pub season: i32,
pub episode: i32,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, FromJsonQueryResult)]
pub enum SeenExtraInformation {
Show(SeenSeasonExtraInformation),
}
}
1 change: 1 addition & 0 deletions apps/backend/src/entities/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub use super::metadata_image::Entity as MetadataImage;
pub use super::metadata_to_creator::Entity as MetadataToCreator;
pub use super::metadata_to_genre::Entity as MetadataToGenre;
pub use super::movie::Entity as Movie;
pub use super::review::Entity as Review;
pub use super::seen::Entity as Seen;
pub use super::show::Entity as Show;
pub use super::summary::Entity as Summary;
Expand Down
57 changes: 57 additions & 0 deletions apps/backend/src/entities/review.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2

use rust_decimal::Decimal;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

use crate::migrator::Visibility;

use super::utils::SeenExtraInformation;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "review")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub posted_on: DateTimeUtc,
pub rating: Option<Decimal>,
pub text: Option<String>,
pub visibility: Visibility,
pub user_id: i32,
pub metadata_id: i32,
pub extra_information: Option<SeenExtraInformation>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::metadata::Entity",
from = "Column::MetadataId",
to = "super::metadata::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Metadata,
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
User,
}

impl Related<super::metadata::Entity> for Entity {
fn to() -> RelationDef {
Relation::Metadata.def()
}
}

impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
11 changes: 1 addition & 10 deletions apps/backend/src/entities/seen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, SimpleObject)]
pub struct SeenSeasonExtraInformation {
pub season: i32,
pub episode: i32,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, FromJsonQueryResult)]
pub enum SeenExtraInformation {
Show(SeenSeasonExtraInformation),
}
use super::utils::{SeenExtraInformation, SeenSeasonExtraInformation};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, SimpleObject)]
#[graphql(name = "Seen")]
Expand Down
5 changes: 5 additions & 0 deletions apps/backend/src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
resolver::{MoviesMutation, MoviesQuery, MoviesService},
tmdb::TmdbService as MovieTmdbService,
},
reviews::resolver::{ReviewsMutation, ReviewsQuery, ReviewsService},
shows::{
resolver::{ShowsMutation, ShowsQuery, ShowsService},
tmdb::TmdbService as ShowTmdbService,
Expand Down Expand Up @@ -92,6 +93,7 @@ pub struct QueryRoot(
VideoGamesQuery,
UsersQuery,
AudioBooksQuery,
ReviewsQuery,
);

#[derive(MergedObject, Default)]
Expand All @@ -103,6 +105,7 @@ pub struct MutationRoot(
ShowsMutation,
VideoGamesMutation,
AudioBooksMutation,
ReviewsMutation,
);

pub type GraphqlSchema = Schema<QueryRoot, MutationRoot, EmptySubscription>;
Expand All @@ -120,6 +123,7 @@ pub async fn get_schema(db: DatabaseConnection, config: &AppConfig) -> GraphqlSc
let igdb_service = IgdbService::new(&config.video_games).await;
let video_games_service = VideoGamesService::new(&db, &igdb_service, &media_service);
let users_service = UsersService::new(&db);
let reviews_service = ReviewsService::new(&db);
Schema::build(
QueryRoot::default(),
MutationRoot::default(),
Expand All @@ -134,5 +138,6 @@ pub async fn get_schema(db: DatabaseConnection, config: &AppConfig) -> GraphqlSc
.data(users_service)
.data(video_games_service)
.data(audio_books_service)
.data(reviews_service)
.finish()
}
1 change: 1 addition & 0 deletions apps/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mod graphql;
mod media;
mod migrator;
mod movies;
mod reviews;
mod shows;
mod users;
mod utils;
Expand Down
15 changes: 8 additions & 7 deletions apps/backend/src/media/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use crate::{
AudioBook, Book, Creator, Genre, Metadata, MetadataImage, Movie, Seen, Show,
UserToMetadata, VideoGame,
},
seen::{self, SeenExtraInformation, SeenSeasonExtraInformation},
show, user_to_metadata, video_game,
seen, show, user_to_metadata,
utils::{SeenExtraInformation, SeenSeasonExtraInformation},
video_game,
},
graphql::IdObject,
migrator::{MetadataImageLot, MetadataLot},
Expand Down Expand Up @@ -586,15 +587,15 @@ impl MediaService {
.await
.unwrap()
{
c
drop(c);
} else {
let c = metadata_image::ActiveModel {
url: ActiveValue::Set(image.to_owned()),
lot: ActiveValue::Set(MetadataImageLot::Poster),
metadata_id: ActiveValue::Set(metadata.id),
..Default::default()
};
c.insert(&self.db).await.unwrap()
c.insert(&self.db).await.ok();
};
}
for image in backdrop_images.iter() {
Expand All @@ -604,15 +605,15 @@ impl MediaService {
.await
.unwrap()
{
c
drop(c);
} else {
let c = metadata_image::ActiveModel {
url: ActiveValue::Set(image.to_owned()),
lot: ActiveValue::Set(MetadataImageLot::Backdrop),
metadata_id: ActiveValue::Set(metadata.id),
..Default::default()
};
c.insert(&self.db).await.unwrap()
c.insert(&self.db).await.ok();
};
}
for name in creator_names.iter() {
Expand All @@ -634,7 +635,7 @@ impl MediaService {
metadata_id: ActiveValue::Set(metadata.id),
creator_id: ActiveValue::Set(creator.id),
};
metadata_creator.insert(&self.db).await.unwrap();
metadata_creator.insert(&self.db).await.ok();
}
for genre in genres {
let db_genre = if let Some(c) = Genre::find()
Expand Down
Loading

0 comments on commit dc9d638

Please sign in to comment.