diff --git a/build.rs b/build.rs index 093db1d..7cbb768 100644 --- a/build.rs +++ b/build.rs @@ -8,6 +8,7 @@ fn main() -> Result<(), Box> { "proto/ratings_features_app.proto", "proto/ratings_features_chart.proto", "proto/ratings_features_user.proto", + "proto/ratings_features_common.proto", ]; tonic_build::configure() diff --git a/proto/ratings_features_app.proto b/proto/ratings_features_app.proto index e6494e4..ac40cff 100644 --- a/proto/ratings_features_app.proto +++ b/proto/ratings_features_app.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package ratings.features.app; +import "ratings_features_common.proto"; + service App { rpc GetRating (GetRatingRequest) returns (GetRatingResponse) {} } @@ -11,20 +13,5 @@ message GetRatingRequest { } message GetRatingResponse { - Rating rating = 1; -} - -message Rating { - string snap_id = 1; - uint64 total_votes = 2; - RatingsBand ratings_band = 3; -} - -enum RatingsBand { - VERY_GOOD = 0; - GOOD = 1; - NEUTRAL = 2; - POOR = 3; - VERY_POOR = 4; - INSUFFICIENT_VOTES = 5; + ratings.features.common.Rating rating = 1; } diff --git a/proto/ratings_features_chart.proto b/proto/ratings_features_chart.proto index b1306ef..19f39d3 100644 --- a/proto/ratings_features_chart.proto +++ b/proto/ratings_features_chart.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package ratings.features.chart; +import "ratings_features_common.proto"; + service Chart { rpc GetChart (GetChartRequest) returns (GetChartResponse) {} } @@ -16,11 +18,8 @@ message GetChartResponse { } message ChartData { - string app = 1; - uint64 total_up_votes = 2; - uint64 total_down_votes = 3; - float rating = 4; - RatingsBand rating_band = 5; + float raw_rating = 1; + ratings.features.common.Rating rating = 2; } enum Timeframe { @@ -28,12 +27,3 @@ enum Timeframe { TIMEFRAME_WEEK = 1; TIMEFRAME_MONTH = 2; } - -enum RatingsBand { - VERY_GOOD = 0; - GOOD = 1; - NEUTRAL = 2; - POOR = 3; - VERY_POOR = 4; - INSUFFICIENT_VOTES = 5; -} diff --git a/proto/ratings_features_common.proto b/proto/ratings_features_common.proto new file mode 100644 index 0000000..84a53d5 --- /dev/null +++ b/proto/ratings_features_common.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package ratings.features.common; + +message Rating { + string snap_id = 1; + uint64 total_votes = 2; + RatingsBand ratings_band = 3; +} + +enum RatingsBand { + VERY_GOOD = 0; + GOOD = 1; + NEUTRAL = 2; + POOR = 3; + VERY_POOR = 4; + INSUFFICIENT_VOTES = 5; +} diff --git a/src/features/app/infrastructure.rs b/src/features/app/infrastructure.rs index 6e8f30e..e5071da 100644 --- a/src/features/app/infrastructure.rs +++ b/src/features/app/infrastructure.rs @@ -1,8 +1,8 @@ -use crate::app::AppContext; +use crate::{app::AppContext, features::common::entities::Vote}; use sqlx::Row; use tracing::error; -use super::{entities::Vote, errors::AppError}; +use super::errors::AppError; pub(crate) async fn get_votes_by_snap_id( app_ctx: &AppContext, diff --git a/src/features/app/interface.rs b/src/features/app/interface.rs index 08b2935..7cc2687 100644 --- a/src/features/app/interface.rs +++ b/src/features/app/interface.rs @@ -8,8 +8,9 @@ use super::{service::AppService, use_cases}; pub mod protobuf { pub use self::app_server::App; - + tonic::include_proto!("ratings.features.common"); tonic::include_proto!("ratings.features.app"); + } #[tonic::async_trait] diff --git a/src/features/app/mod.rs b/src/features/app/mod.rs index 6522bea..d273b6e 100644 --- a/src/features/app/mod.rs +++ b/src/features/app/mod.rs @@ -1,4 +1,3 @@ -pub mod entities; mod errors; mod infrastructure; pub mod interface; diff --git a/src/features/app/use_cases.rs b/src/features/app/use_cases.rs index e36bdf1..c821620 100644 --- a/src/features/app/use_cases.rs +++ b/src/features/app/use_cases.rs @@ -1,7 +1,7 @@ -use crate::app::AppContext; +use crate::{app::AppContext, features::common::entities::Rating}; use tracing::error; -use super::{entities::Rating, errors::AppError, infrastructure::get_votes_by_snap_id}; +use super::{errors::AppError, infrastructure::get_votes_by_snap_id}; pub async fn get_rating(app_ctx: &AppContext, snap_id: String) -> Result { let votes = get_votes_by_snap_id(app_ctx, &snap_id) diff --git a/src/features/app/entities.rs b/src/features/common/entities.rs similarity index 98% rename from src/features/app/entities.rs rename to src/features/common/entities.rs index cda672d..9801597 100644 --- a/src/features/app/entities.rs +++ b/src/features/common/entities.rs @@ -1,6 +1,8 @@ use sqlx::FromRow; -use super::interface::protobuf; +pub mod protobuf { + tonic::include_proto!("ratings.features.common"); +} const INSUFFICIENT_VOTES_QUANTITY: usize = 25; diff --git a/src/features/common/mod.rs b/src/features/common/mod.rs new file mode 100644 index 0000000..0b8f0b5 --- /dev/null +++ b/src/features/common/mod.rs @@ -0,0 +1 @@ +pub mod entities; diff --git a/src/features/mod.rs b/src/features/mod.rs index 836e47e..8663180 100644 --- a/src/features/mod.rs +++ b/src/features/mod.rs @@ -1,2 +1,3 @@ pub mod app; +mod common; pub mod user;