diff --git a/build.rs b/build.rs index e44a24c..c58c034 100644 --- a/build.rs +++ b/build.rs @@ -3,7 +3,7 @@ use std::path::Path; fn init_proto() -> Result<(), Box> { // Define the path to the output directory within the `src` folder - let out_dir = Path::new("proto"); + let out_dir = Path::new("src/protos"); std::fs::create_dir_all(out_dir)?; let descriptor_set_path = format!( @@ -11,12 +11,7 @@ fn init_proto() -> Result<(), Box> { std::env::var("OUT_DIR").unwrap() ); - let files = &[ - "proto/ratings_features_app.proto", - "proto/ratings_features_chart.proto", - "proto/ratings_features_user.proto", - "proto/ratings_features_common.proto", - ]; + let files = &["protos/ratings.proto"]; tonic_build::configure() .protoc_arg("--experimental_allow_proto3_optional") // needed to run on GHA because it's jammy @@ -28,7 +23,7 @@ fn init_proto() -> Result<(), Box> { "Category", r#"#[strum(serialize_all = "kebab_case", ascii_case_insensitive)]"#, ) - .compile(files, &["proto"])?; + .compile(files, &["protos"])?; Ok(()) } diff --git a/proto/ratings_features_app.proto b/proto/ratings_features_app.proto deleted file mode 100644 index ac40cff..0000000 --- a/proto/ratings_features_app.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto3"; - -package ratings.features.app; - -import "ratings_features_common.proto"; - -service App { - rpc GetRating (GetRatingRequest) returns (GetRatingResponse) {} -} - -message GetRatingRequest { - string snap_id = 1; -} - -message GetRatingResponse { - ratings.features.common.Rating rating = 1; -} diff --git a/proto/ratings_features_chart.proto b/proto/ratings_features_chart.proto deleted file mode 100644 index 0c03db6..0000000 --- a/proto/ratings_features_chart.proto +++ /dev/null @@ -1,57 +0,0 @@ -syntax = "proto3"; - -package ratings.features.chart; - -import "ratings_features_common.proto"; - -service Chart { - rpc GetChart (GetChartRequest) returns (GetChartResponse) {} -} - -message GetChartRequest { - Timeframe timeframe = 1; - optional Category category = 2; -} - -message GetChartResponse { - Timeframe timeframe = 1; - repeated ChartData ordered_chart_data = 2; - optional Category category = 3; -} - -message ChartData { - float raw_rating = 1; - ratings.features.common.Rating rating = 2; -} - -enum Timeframe { - TIMEFRAME_UNSPECIFIED = 0; - TIMEFRAME_WEEK = 1; - TIMEFRAME_MONTH = 2; -} - -// The categories that can be selected, these -// are taken directly from `curl -sS -X GET --unix-socket /run/snapd.socket "http://localhost/v2/categories"` -// On 2024-02-03, it may need to be kept in sync. -enum Category { - ART_AND_DESIGN = 0; - BOOK_AND_REFERENCE = 1; - DEVELOPMENT = 2; - DEVICES_AND_IOT = 3; - EDUCATION = 4; - ENTERTAINMENT = 5; - FEATURED = 6; - FINANCE = 7; - GAMES = 8; - HEALTH_AND_FITNESS = 9; - MUSIC_AND_AUDIO = 10; - NEWS_AND_WEATHER = 11; - PERSONALISATION = 12; - PHOTO_AND_VIDEO = 13; - PRODUCTIVITY = 14; - SCIENCE = 15; - SECURITY = 16; - SERVER_AND_CLOUD = 17; - SOCIAL = 18; - UTILITIES = 19; -} diff --git a/proto/ratings_features_common.proto b/proto/ratings_features_common.proto deleted file mode 100644 index 84a53d5..0000000 --- a/proto/ratings_features_common.proto +++ /dev/null @@ -1,18 +0,0 @@ -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/proto/ratings_features_user.proto b/proto/ratings_features_user.proto deleted file mode 100644 index 893133c..0000000 --- a/proto/ratings_features_user.proto +++ /dev/null @@ -1,53 +0,0 @@ -syntax = "proto3"; - -package ratings.features.user; - -import "google/protobuf/empty.proto"; -import "google/protobuf/timestamp.proto"; - -service User { - rpc Authenticate (AuthenticateRequest) returns (AuthenticateResponse) {} - - rpc Delete (google.protobuf.Empty) returns (google.protobuf.Empty) {} - rpc Vote (VoteRequest) returns (google.protobuf.Empty) {} - rpc ListMyVotes (ListMyVotesRequest) returns (ListMyVotesResponse) {} - rpc GetSnapVotes(GetSnapVotesRequest) returns (GetSnapVotesResponse) {} -} - -message AuthenticateRequest { - // sha256([$user:$machineId]) - string id = 1; -} - -message AuthenticateResponse { - string token = 1; -} - -message ListMyVotesRequest { - string snap_id_filter = 1; -} - -message ListMyVotesResponse { - repeated Vote votes = 1; -} - -message GetSnapVotesRequest { - string snap_id = 1; -} - -message GetSnapVotesResponse { - repeated Vote votes = 1; -} - -message Vote { - string snap_id = 1; - int32 snap_revision = 2; - bool vote_up = 3; - google.protobuf.Timestamp timestamp = 4; -} - -message VoteRequest { - string snap_id = 1; - int32 snap_revision = 2; - bool vote_up = 3; -} diff --git a/protos/ratings.proto b/protos/ratings.proto new file mode 100644 index 0000000..81d3745 --- /dev/null +++ b/protos/ratings.proto @@ -0,0 +1,133 @@ +syntax = "proto3"; + +package ratings; + +// Import dependencies +import "google/protobuf/empty.proto"; +import "google/protobuf/timestamp.proto"; + +// App service +service App { + rpc GetRating (GetRatingRequest) returns (GetRatingResponse) {} +} + +message GetRatingRequest { + string snap_id = 1; +} + +message GetRatingResponse { + Rating rating = 1; +} + +// Chart service +service Chart { + rpc GetChart (GetChartRequest) returns (GetChartResponse) {} +} + +message GetChartRequest { + Timeframe timeframe = 1; + optional Category category = 2; +} + +message GetChartResponse { + Timeframe timeframe = 1; + repeated ChartData ordered_chart_data = 2; + optional Category category = 3; +} + +message ChartData { + float raw_rating = 1; + Rating rating = 2; +} + +enum Timeframe { + TIMEFRAME_UNSPECIFIED = 0; + TIMEFRAME_WEEK = 1; + TIMEFRAME_MONTH = 2; +} + +enum Category { + ART_AND_DESIGN = 0; + BOOK_AND_REFERENCE = 1; + DEVELOPMENT = 2; + DEVICES_AND_IOT = 3; + EDUCATION = 4; + ENTERTAINMENT = 5; + FEATURED = 6; + FINANCE = 7; + GAMES = 8; + HEALTH_AND_FITNESS = 9; + MUSIC_AND_AUDIO = 10; + NEWS_AND_WEATHER = 11; + PERSONALISATION = 12; + PHOTO_AND_VIDEO = 13; + PRODUCTIVITY = 14; + SCIENCE = 15; + SECURITY = 16; + SERVER_AND_CLOUD = 17; + SOCIAL = 18; + UTILITIES = 19; +} + +// User service +service User { + rpc Authenticate (AuthenticateRequest) returns (AuthenticateResponse) {} + + rpc Delete (google.protobuf.Empty) returns (google.protobuf.Empty) {} + rpc Vote (VoteRequest) returns (google.protobuf.Empty) {} + rpc ListMyVotes (ListMyVotesRequest) returns (ListMyVotesResponse) {} + rpc GetSnapVotes(GetSnapVotesRequest) returns (GetSnapVotesResponse) {} +} + +message AuthenticateRequest { + string id = 1; +} + +message AuthenticateResponse { + string token = 1; +} + +message ListMyVotesRequest { + string snap_id_filter = 1; +} + +message ListMyVotesResponse { + repeated Vote votes = 1; +} + +message GetSnapVotesRequest { + string snap_id = 1; +} + +message GetSnapVotesResponse { + repeated Vote votes = 1; +} + +message Vote { + string snap_id = 1; + int32 snap_revision = 2; + bool vote_up = 3; + google.protobuf.Timestamp timestamp = 4; +} + +message VoteRequest { + string snap_id = 1; + int32 snap_revision = 2; + bool vote_up = 3; +} + +// Common messages +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/chart/entities.rs b/src/features/chart/entities.rs index 2b065ca..edcbf48 100644 --- a/src/features/chart/entities.rs +++ b/src/features/chart/entities.rs @@ -1,7 +1,7 @@ //! Contains struct definitions for the charting feature for ratings. use crate::features::{ common::entities::{calculate_band, Rating, VoteSummary}, - pb::chart as pb, + pb::protos as pb, }; use sqlx::FromRow; diff --git a/src/features/chart/infrastructure.rs b/src/features/chart/infrastructure.rs index 17bded7..f03db36 100644 --- a/src/features/chart/infrastructure.rs +++ b/src/features/chart/infrastructure.rs @@ -6,7 +6,7 @@ use crate::{ features::{ chart::errors::ChartError, common::entities::VoteSummary, - pb::chart::{Category, Timeframe}, + pb::protos::{Category, Timeframe}, }, }; use sqlx::QueryBuilder; @@ -47,9 +47,9 @@ pub(crate) async fn get_votes_summary( if let Some(category) = category { builder .push( - r#" + r#" WHERE votes.snap_id IN ( - SELECT snap_categories.snap_id FROM snap_categories + SELECT snap_categories.snap_id FROM snap_categories WHERE snap_categories.category = "#, ) .push_bind(category) diff --git a/src/features/chart/service/grpc.rs b/src/features/chart/service/grpc.rs index dd2701b..5e592d8 100644 --- a/src/features/chart/service/grpc.rs +++ b/src/features/chart/service/grpc.rs @@ -3,7 +3,7 @@ use crate::{ app::AppContext, features::{ chart::{errors::ChartError, service::ChartService, use_cases}, - pb::chart::{chart_server::Chart, Category, GetChartRequest, GetChartResponse, Timeframe}, + pb::protos::{chart_server::Chart, Category, GetChartRequest, GetChartResponse, Timeframe}, }, }; use tonic::{Request, Response, Status}; diff --git a/src/features/chart/service/mod.rs b/src/features/chart/service/mod.rs index 70537b8..cb222db 100644 --- a/src/features/chart/service/mod.rs +++ b/src/features/chart/service/mod.rs @@ -2,7 +2,7 @@ //! //! [`Chart`]: crate::features::chart::entities::Chart -use crate::features::pb::chart::chart_server::ChartServer; +use crate::features::pb::protos::chart_server::ChartServer; mod grpc; diff --git a/src/features/chart/use_cases.rs b/src/features/chart/use_cases.rs index 04d12e6..19307cf 100644 --- a/src/features/chart/use_cases.rs +++ b/src/features/chart/use_cases.rs @@ -4,7 +4,7 @@ use crate::{ app::AppContext, features::{ chart::{entities::Chart, errors::ChartError, infrastructure::get_votes_summary}, - pb::chart::{Category, Timeframe}, + pb::protos::{Category, Timeframe}, }, }; use tracing::error; diff --git a/src/features/common/entities.rs b/src/features/common/entities.rs index 67f03e7..207f1a4 100644 --- a/src/features/common/entities.rs +++ b/src/features/common/entities.rs @@ -1,7 +1,7 @@ //! Common defintions used throughout the ratings service. use sqlx::FromRow; -use crate::features::pb::common as pb; +use crate::features::pb::protos as pb; /// An arbitrary fixed number of votes we've determined is below the threshold to be meaningful. const INSUFFICIENT_VOTES_QUANTITY: i64 = 25; @@ -61,8 +61,8 @@ impl PartialOrd for RatingsBand { } } -impl From for RatingsBand { - fn from(value: crate::features::pb::common::RatingsBand) -> Self { +impl From for RatingsBand { + fn from(value: crate::features::pb::protos::RatingsBand) -> Self { match value { pb::RatingsBand::VeryGood => Self::VeryGood, pb::RatingsBand::Good => Self::Good, @@ -110,12 +110,12 @@ impl Rating { } } -impl From for Rating { - fn from(value: crate::features::pb::common::Rating) -> Self { +impl From for Rating { + fn from(value: crate::features::pb::protos::Rating) -> Self { Self { snap_id: value.snap_id, total_votes: value.total_votes, - ratings_band: crate::features::pb::common::RatingsBand::try_from(value.ratings_band) + ratings_band: crate::features::pb::protos::RatingsBand::try_from(value.ratings_band) .unwrap() .into(), } diff --git a/src/features/pb.rs b/src/features/pb.rs index d20971e..d549807 100644 --- a/src/features/pb.rs +++ b/src/features/pb.rs @@ -4,26 +4,8 @@ #![allow(missing_docs)] #![allow(clippy::missing_docs_in_private_items)] -pub mod app { - //! Contains protobufs relating to the app features - - include!("../../proto/ratings.features.app.rs"); -} - -pub mod common { - //! Contains common protobufs - - include!("../../proto/ratings.features.common.rs"); -} - -pub mod user { - //! Contains user protobufs - - include!("../../proto/ratings.features.user.rs"); -} - -pub mod chart { +pub mod protos { //! Contains chart protobufs - include!("../../proto/ratings.features.chart.rs"); + include!("../protos/ratings.rs"); } diff --git a/src/features/rating/service/grpc.rs b/src/features/rating/service/grpc.rs index 3742c58..888c7c1 100644 --- a/src/features/rating/service/grpc.rs +++ b/src/features/rating/service/grpc.rs @@ -2,7 +2,7 @@ use crate::app::AppContext; use crate::features::{ - pb::app::{app_server::App, GetRatingRequest, GetRatingResponse}, + pb::protos::{app_server::App, GetRatingRequest, GetRatingResponse}, rating::{service::RatingService, use_cases}, }; use tonic::{Request, Response, Status}; diff --git a/src/features/rating/service/mod.rs b/src/features/rating/service/mod.rs index b815e30..a0e5eb6 100644 --- a/src/features/rating/service/mod.rs +++ b/src/features/rating/service/mod.rs @@ -1,5 +1,5 @@ //! Contains generation and definitions for the [`AppService`] -use crate::features::pb::app::app_server::AppServer; +use crate::features::pb::protos::app_server::AppServer; mod grpc; diff --git a/src/features/user/entities.rs b/src/features/user/entities.rs index 888f359..4a448b1 100644 --- a/src/features/user/entities.rs +++ b/src/features/user/entities.rs @@ -3,7 +3,7 @@ use sqlx::FromRow; use time::OffsetDateTime; -use crate::features::pb::user; +use crate::features::pb::protos; /// A hash of a given user client. pub type ClientHash = String; @@ -51,13 +51,13 @@ pub struct Vote { impl Vote { /// Converts this vote into its wire component for transfer over the network. - pub(crate) fn into_protobuf_vote(self) -> user::Vote { + pub(crate) fn into_protobuf_vote(self) -> protos::Vote { let timestamp = Some(prost_types::Timestamp { seconds: self.timestamp.unix_timestamp(), nanos: 0, }); - user::Vote { + protos::Vote { snap_id: self.snap_id, snap_revision: self.snap_revision as i32, vote_up: self.vote_up, diff --git a/src/features/user/infrastructure.rs b/src/features/user/infrastructure.rs index a50c776..7672ddf 100644 --- a/src/features/user/infrastructure.rs +++ b/src/features/user/infrastructure.rs @@ -9,7 +9,7 @@ use tracing::error; use crate::{ app::AppContext, features::{ - pb::chart::Category, + pb::protos::Category, user::{ entities::{User, Vote}, errors::UserError, @@ -304,7 +304,7 @@ mod test { use snapd::SnapdClient; - use crate::features::pb::chart::Category; + use crate::features::pb::protos::Category; use super::snapd_categories_by_snap_id; const TESTING_SNAP_ID: &str = "3Iwi803Tk3KQwyD6jFiAJdlq8MLgBIoD"; diff --git a/src/features/user/service/grpc.rs b/src/features/user/service/grpc.rs index 419681b..86bc0aa 100644 --- a/src/features/user/service/grpc.rs +++ b/src/features/user/service/grpc.rs @@ -5,7 +5,7 @@ use tonic::{Request, Response, Status}; use crate::{ app::AppContext, features::{ - pb::user::{ + pb::protos::{ user_server::User, AuthenticateRequest, AuthenticateResponse, GetSnapVotesRequest, GetSnapVotesResponse, ListMyVotesRequest, ListMyVotesResponse, VoteRequest, }, diff --git a/src/features/user/service/mod.rs b/src/features/user/service/mod.rs index 091c188..dddc34d 100644 --- a/src/features/user/service/mod.rs +++ b/src/features/user/service/mod.rs @@ -1,7 +1,7 @@ //! Definitions and utilities for building the [`UserService`] for handling [`User`] data. //! //! [`User`]: crate::features::user::entities::User -use crate::features::pb::user::user_server::UserServer; +use crate::features::pb::protos::user_server::UserServer; mod grpc; diff --git a/src/protos/ratings.features.rs b/src/protos/ratings.features.rs new file mode 100644 index 0000000..2ea8b5b --- /dev/null +++ b/src/protos/ratings.features.rs @@ -0,0 +1,1424 @@ +// This file is @generated by prost-build. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetRatingRequest { + #[prost(string, tag = "1")] + pub snap_id: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetRatingResponse { + #[prost(message, optional, tag = "1")] + pub rating: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetChartRequest { + #[prost(enumeration = "Timeframe", tag = "1")] + pub timeframe: i32, + #[prost(enumeration = "Category", optional, tag = "2")] + pub category: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetChartResponse { + #[prost(enumeration = "Timeframe", tag = "1")] + pub timeframe: i32, + #[prost(message, repeated, tag = "2")] + pub ordered_chart_data: ::prost::alloc::vec::Vec, + #[prost(enumeration = "Category", optional, tag = "3")] + pub category: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ChartData { + #[prost(float, tag = "1")] + pub raw_rating: f32, + #[prost(message, optional, tag = "2")] + pub rating: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct AuthenticateRequest { + #[prost(string, tag = "1")] + pub id: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct AuthenticateResponse { + #[prost(string, tag = "1")] + pub token: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ListMyVotesRequest { + #[prost(string, tag = "1")] + pub snap_id_filter: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ListMyVotesResponse { + #[prost(message, repeated, tag = "1")] + pub votes: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetSnapVotesRequest { + #[prost(string, tag = "1")] + pub snap_id: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetSnapVotesResponse { + #[prost(message, repeated, tag = "1")] + pub votes: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Vote { + #[prost(string, tag = "1")] + pub snap_id: ::prost::alloc::string::String, + #[prost(int32, tag = "2")] + pub snap_revision: i32, + #[prost(bool, tag = "3")] + pub vote_up: bool, + #[prost(message, optional, tag = "4")] + pub timestamp: ::core::option::Option<::prost_types::Timestamp>, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct VoteRequest { + #[prost(string, tag = "1")] + pub snap_id: ::prost::alloc::string::String, + #[prost(int32, tag = "2")] + pub snap_revision: i32, + #[prost(bool, tag = "3")] + pub vote_up: bool, +} +/// Common messages +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Rating { + #[prost(string, tag = "1")] + pub snap_id: ::prost::alloc::string::String, + #[prost(uint64, tag = "2")] + pub total_votes: u64, + #[prost(enumeration = "RatingsBand", tag = "3")] + pub ratings_band: i32, +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum Timeframe { + Unspecified = 0, + Week = 1, + Month = 2, +} +impl Timeframe { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Timeframe::Unspecified => "TIMEFRAME_UNSPECIFIED", + Timeframe::Week => "TIMEFRAME_WEEK", + Timeframe::Month => "TIMEFRAME_MONTH", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "TIMEFRAME_UNSPECIFIED" => Some(Self::Unspecified), + "TIMEFRAME_WEEK" => Some(Self::Week), + "TIMEFRAME_MONTH" => Some(Self::Month), + _ => None, + } + } +} +#[derive(sqlx::Type, strum::EnumString)] +#[strum(serialize_all = "kebab_case", ascii_case_insensitive)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum Category { + ArtAndDesign = 0, + BookAndReference = 1, + Development = 2, + DevicesAndIot = 3, + Education = 4, + Entertainment = 5, + Featured = 6, + Finance = 7, + Games = 8, + HealthAndFitness = 9, + MusicAndAudio = 10, + NewsAndWeather = 11, + Personalisation = 12, + PhotoAndVideo = 13, + Productivity = 14, + Science = 15, + Security = 16, + ServerAndCloud = 17, + Social = 18, + Utilities = 19, +} +impl Category { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Category::ArtAndDesign => "ART_AND_DESIGN", + Category::BookAndReference => "BOOK_AND_REFERENCE", + Category::Development => "DEVELOPMENT", + Category::DevicesAndIot => "DEVICES_AND_IOT", + Category::Education => "EDUCATION", + Category::Entertainment => "ENTERTAINMENT", + Category::Featured => "FEATURED", + Category::Finance => "FINANCE", + Category::Games => "GAMES", + Category::HealthAndFitness => "HEALTH_AND_FITNESS", + Category::MusicAndAudio => "MUSIC_AND_AUDIO", + Category::NewsAndWeather => "NEWS_AND_WEATHER", + Category::Personalisation => "PERSONALISATION", + Category::PhotoAndVideo => "PHOTO_AND_VIDEO", + Category::Productivity => "PRODUCTIVITY", + Category::Science => "SCIENCE", + Category::Security => "SECURITY", + Category::ServerAndCloud => "SERVER_AND_CLOUD", + Category::Social => "SOCIAL", + Category::Utilities => "UTILITIES", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "ART_AND_DESIGN" => Some(Self::ArtAndDesign), + "BOOK_AND_REFERENCE" => Some(Self::BookAndReference), + "DEVELOPMENT" => Some(Self::Development), + "DEVICES_AND_IOT" => Some(Self::DevicesAndIot), + "EDUCATION" => Some(Self::Education), + "ENTERTAINMENT" => Some(Self::Entertainment), + "FEATURED" => Some(Self::Featured), + "FINANCE" => Some(Self::Finance), + "GAMES" => Some(Self::Games), + "HEALTH_AND_FITNESS" => Some(Self::HealthAndFitness), + "MUSIC_AND_AUDIO" => Some(Self::MusicAndAudio), + "NEWS_AND_WEATHER" => Some(Self::NewsAndWeather), + "PERSONALISATION" => Some(Self::Personalisation), + "PHOTO_AND_VIDEO" => Some(Self::PhotoAndVideo), + "PRODUCTIVITY" => Some(Self::Productivity), + "SCIENCE" => Some(Self::Science), + "SECURITY" => Some(Self::Security), + "SERVER_AND_CLOUD" => Some(Self::ServerAndCloud), + "SOCIAL" => Some(Self::Social), + "UTILITIES" => Some(Self::Utilities), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum RatingsBand { + VeryGood = 0, + Good = 1, + Neutral = 2, + Poor = 3, + VeryPoor = 4, + InsufficientVotes = 5, +} +impl RatingsBand { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + RatingsBand::VeryGood => "VERY_GOOD", + RatingsBand::Good => "GOOD", + RatingsBand::Neutral => "NEUTRAL", + RatingsBand::Poor => "POOR", + RatingsBand::VeryPoor => "VERY_POOR", + RatingsBand::InsufficientVotes => "INSUFFICIENT_VOTES", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "VERY_GOOD" => Some(Self::VeryGood), + "GOOD" => Some(Self::Good), + "NEUTRAL" => Some(Self::Neutral), + "POOR" => Some(Self::Poor), + "VERY_POOR" => Some(Self::VeryPoor), + "INSUFFICIENT_VOTES" => Some(Self::InsufficientVotes), + _ => None, + } + } +} +/// Generated client implementations. +pub mod app_client { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + use tonic::codegen::http::Uri; + /// App service + #[derive(Debug, Clone)] + pub struct AppClient { + inner: tonic::client::Grpc, + } + impl AppClient { + /// Attempt to create a new client by connecting to a given endpoint. + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; + Ok(Self::new(conn)) + } + } + impl AppClient + where + T: tonic::client::GrpcService, + T::Error: Into, + T::ResponseBody: Body + Send + 'static, + ::Error: Into + Send, + { + pub fn new(inner: T) -> Self { + let inner = tonic::client::Grpc::new(inner); + Self { inner } + } + pub fn with_origin(inner: T, origin: Uri) -> Self { + let inner = tonic::client::Grpc::with_origin(inner, origin); + Self { inner } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> AppClient> + where + F: tonic::service::Interceptor, + T::ResponseBody: Default, + T: tonic::codegen::Service< + http::Request, + Response = http::Response< + >::ResponseBody, + >, + >, + , + >>::Error: Into + Send + Sync, + { + AppClient::new(InterceptedService::new(inner, interceptor)) + } + /// Compress requests with the given encoding. + /// + /// This requires the server to support it otherwise it might respond with an + /// error. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.send_compressed(encoding); + self + } + /// Enable decompressing responses. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.accept_compressed(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_decoding_message_size(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_encoding_message_size(limit); + self + } + pub async fn get_rating( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/ratings.features.App/GetRating", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("ratings.features.App", "GetRating")); + self.inner.unary(req, path, codec).await + } + } +} +/// Generated client implementations. +pub mod chart_client { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + use tonic::codegen::http::Uri; + /// Chart service + #[derive(Debug, Clone)] + pub struct ChartClient { + inner: tonic::client::Grpc, + } + impl ChartClient { + /// Attempt to create a new client by connecting to a given endpoint. + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; + Ok(Self::new(conn)) + } + } + impl ChartClient + where + T: tonic::client::GrpcService, + T::Error: Into, + T::ResponseBody: Body + Send + 'static, + ::Error: Into + Send, + { + pub fn new(inner: T) -> Self { + let inner = tonic::client::Grpc::new(inner); + Self { inner } + } + pub fn with_origin(inner: T, origin: Uri) -> Self { + let inner = tonic::client::Grpc::with_origin(inner, origin); + Self { inner } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> ChartClient> + where + F: tonic::service::Interceptor, + T::ResponseBody: Default, + T: tonic::codegen::Service< + http::Request, + Response = http::Response< + >::ResponseBody, + >, + >, + , + >>::Error: Into + Send + Sync, + { + ChartClient::new(InterceptedService::new(inner, interceptor)) + } + /// Compress requests with the given encoding. + /// + /// This requires the server to support it otherwise it might respond with an + /// error. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.send_compressed(encoding); + self + } + /// Enable decompressing responses. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.accept_compressed(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_decoding_message_size(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_encoding_message_size(limit); + self + } + pub async fn get_chart( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/ratings.features.Chart/GetChart", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("ratings.features.Chart", "GetChart")); + self.inner.unary(req, path, codec).await + } + } +} +/// Generated client implementations. +pub mod user_client { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + use tonic::codegen::http::Uri; + /// User service + #[derive(Debug, Clone)] + pub struct UserClient { + inner: tonic::client::Grpc, + } + impl UserClient { + /// Attempt to create a new client by connecting to a given endpoint. + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; + Ok(Self::new(conn)) + } + } + impl UserClient + where + T: tonic::client::GrpcService, + T::Error: Into, + T::ResponseBody: Body + Send + 'static, + ::Error: Into + Send, + { + pub fn new(inner: T) -> Self { + let inner = tonic::client::Grpc::new(inner); + Self { inner } + } + pub fn with_origin(inner: T, origin: Uri) -> Self { + let inner = tonic::client::Grpc::with_origin(inner, origin); + Self { inner } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> UserClient> + where + F: tonic::service::Interceptor, + T::ResponseBody: Default, + T: tonic::codegen::Service< + http::Request, + Response = http::Response< + >::ResponseBody, + >, + >, + , + >>::Error: Into + Send + Sync, + { + UserClient::new(InterceptedService::new(inner, interceptor)) + } + /// Compress requests with the given encoding. + /// + /// This requires the server to support it otherwise it might respond with an + /// error. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.send_compressed(encoding); + self + } + /// Enable decompressing responses. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.accept_compressed(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_decoding_message_size(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_encoding_message_size(limit); + self + } + pub async fn authenticate( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/ratings.features.User/Authenticate", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("ratings.features.User", "Authenticate")); + self.inner.unary(req, path, codec).await + } + pub async fn delete( + &mut self, + request: impl tonic::IntoRequest<()>, + ) -> std::result::Result, tonic::Status> { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/ratings.features.User/Delete", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("ratings.features.User", "Delete")); + self.inner.unary(req, path, codec).await + } + pub async fn vote( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result, tonic::Status> { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/ratings.features.User/Vote", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("ratings.features.User", "Vote")); + self.inner.unary(req, path, codec).await + } + pub async fn list_my_votes( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/ratings.features.User/ListMyVotes", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("ratings.features.User", "ListMyVotes")); + self.inner.unary(req, path, codec).await + } + pub async fn get_snap_votes( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/ratings.features.User/GetSnapVotes", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("ratings.features.User", "GetSnapVotes")); + self.inner.unary(req, path, codec).await + } + } +} +/// Generated server implementations. +pub mod app_server { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + /// Generated trait containing gRPC methods that should be implemented for use with AppServer. + #[async_trait] + pub trait App: Send + Sync + 'static { + async fn get_rating( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + } + /// App service + #[derive(Debug)] + pub struct AppServer { + inner: _Inner, + accept_compression_encodings: EnabledCompressionEncodings, + send_compression_encodings: EnabledCompressionEncodings, + max_decoding_message_size: Option, + max_encoding_message_size: Option, + } + struct _Inner(Arc); + impl AppServer { + pub fn new(inner: T) -> Self { + Self::from_arc(Arc::new(inner)) + } + pub fn from_arc(inner: Arc) -> Self { + let inner = _Inner(inner); + Self { + inner, + accept_compression_encodings: Default::default(), + send_compression_encodings: Default::default(), + max_decoding_message_size: None, + max_encoding_message_size: None, + } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService + where + F: tonic::service::Interceptor, + { + InterceptedService::new(Self::new(inner), interceptor) + } + /// Enable decompressing requests with the given encoding. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.accept_compression_encodings.enable(encoding); + self + } + /// Compress responses with the given encoding, if the client supports it. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.send_compression_encodings.enable(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.max_decoding_message_size = Some(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.max_encoding_message_size = Some(limit); + self + } + } + impl tonic::codegen::Service> for AppServer + where + T: App, + B: Body + Send + 'static, + B::Error: Into + Send + 'static, + { + type Response = http::Response; + type Error = std::convert::Infallible; + type Future = BoxFuture; + fn poll_ready( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: http::Request) -> Self::Future { + let inner = self.inner.clone(); + match req.uri().path() { + "/ratings.features.App/GetRating" => { + #[allow(non_camel_case_types)] + struct GetRatingSvc(pub Arc); + impl tonic::server::UnaryService + for GetRatingSvc { + type Response = super::GetRatingResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::get_rating(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = GetRatingSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } + } + } + } + impl Clone for AppServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { + inner, + accept_compression_encodings: self.accept_compression_encodings, + send_compression_encodings: self.send_compression_encodings, + max_decoding_message_size: self.max_decoding_message_size, + max_encoding_message_size: self.max_encoding_message_size, + } + } + } + impl Clone for _Inner { + fn clone(&self) -> Self { + Self(Arc::clone(&self.0)) + } + } + impl std::fmt::Debug for _Inner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } + } + impl tonic::server::NamedService for AppServer { + const NAME: &'static str = "ratings.features.App"; + } +} +/// Generated server implementations. +pub mod chart_server { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + /// Generated trait containing gRPC methods that should be implemented for use with ChartServer. + #[async_trait] + pub trait Chart: Send + Sync + 'static { + async fn get_chart( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + } + /// Chart service + #[derive(Debug)] + pub struct ChartServer { + inner: _Inner, + accept_compression_encodings: EnabledCompressionEncodings, + send_compression_encodings: EnabledCompressionEncodings, + max_decoding_message_size: Option, + max_encoding_message_size: Option, + } + struct _Inner(Arc); + impl ChartServer { + pub fn new(inner: T) -> Self { + Self::from_arc(Arc::new(inner)) + } + pub fn from_arc(inner: Arc) -> Self { + let inner = _Inner(inner); + Self { + inner, + accept_compression_encodings: Default::default(), + send_compression_encodings: Default::default(), + max_decoding_message_size: None, + max_encoding_message_size: None, + } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService + where + F: tonic::service::Interceptor, + { + InterceptedService::new(Self::new(inner), interceptor) + } + /// Enable decompressing requests with the given encoding. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.accept_compression_encodings.enable(encoding); + self + } + /// Compress responses with the given encoding, if the client supports it. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.send_compression_encodings.enable(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.max_decoding_message_size = Some(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.max_encoding_message_size = Some(limit); + self + } + } + impl tonic::codegen::Service> for ChartServer + where + T: Chart, + B: Body + Send + 'static, + B::Error: Into + Send + 'static, + { + type Response = http::Response; + type Error = std::convert::Infallible; + type Future = BoxFuture; + fn poll_ready( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: http::Request) -> Self::Future { + let inner = self.inner.clone(); + match req.uri().path() { + "/ratings.features.Chart/GetChart" => { + #[allow(non_camel_case_types)] + struct GetChartSvc(pub Arc); + impl tonic::server::UnaryService + for GetChartSvc { + type Response = super::GetChartResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::get_chart(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = GetChartSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } + } + } + } + impl Clone for ChartServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { + inner, + accept_compression_encodings: self.accept_compression_encodings, + send_compression_encodings: self.send_compression_encodings, + max_decoding_message_size: self.max_decoding_message_size, + max_encoding_message_size: self.max_encoding_message_size, + } + } + } + impl Clone for _Inner { + fn clone(&self) -> Self { + Self(Arc::clone(&self.0)) + } + } + impl std::fmt::Debug for _Inner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } + } + impl tonic::server::NamedService for ChartServer { + const NAME: &'static str = "ratings.features.Chart"; + } +} +/// Generated server implementations. +pub mod user_server { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + /// Generated trait containing gRPC methods that should be implemented for use with UserServer. + #[async_trait] + pub trait User: Send + Sync + 'static { + async fn authenticate( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + async fn delete( + &self, + request: tonic::Request<()>, + ) -> std::result::Result, tonic::Status>; + async fn vote( + &self, + request: tonic::Request, + ) -> std::result::Result, tonic::Status>; + async fn list_my_votes( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + async fn get_snap_votes( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + } + /// User service + #[derive(Debug)] + pub struct UserServer { + inner: _Inner, + accept_compression_encodings: EnabledCompressionEncodings, + send_compression_encodings: EnabledCompressionEncodings, + max_decoding_message_size: Option, + max_encoding_message_size: Option, + } + struct _Inner(Arc); + impl UserServer { + pub fn new(inner: T) -> Self { + Self::from_arc(Arc::new(inner)) + } + pub fn from_arc(inner: Arc) -> Self { + let inner = _Inner(inner); + Self { + inner, + accept_compression_encodings: Default::default(), + send_compression_encodings: Default::default(), + max_decoding_message_size: None, + max_encoding_message_size: None, + } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService + where + F: tonic::service::Interceptor, + { + InterceptedService::new(Self::new(inner), interceptor) + } + /// Enable decompressing requests with the given encoding. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.accept_compression_encodings.enable(encoding); + self + } + /// Compress responses with the given encoding, if the client supports it. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.send_compression_encodings.enable(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.max_decoding_message_size = Some(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.max_encoding_message_size = Some(limit); + self + } + } + impl tonic::codegen::Service> for UserServer + where + T: User, + B: Body + Send + 'static, + B::Error: Into + Send + 'static, + { + type Response = http::Response; + type Error = std::convert::Infallible; + type Future = BoxFuture; + fn poll_ready( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: http::Request) -> Self::Future { + let inner = self.inner.clone(); + match req.uri().path() { + "/ratings.features.User/Authenticate" => { + #[allow(non_camel_case_types)] + struct AuthenticateSvc(pub Arc); + impl tonic::server::UnaryService + for AuthenticateSvc { + type Response = super::AuthenticateResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::authenticate(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = AuthenticateSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/ratings.features.User/Delete" => { + #[allow(non_camel_case_types)] + struct DeleteSvc(pub Arc); + impl tonic::server::UnaryService<()> for DeleteSvc { + type Response = (); + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call(&mut self, request: tonic::Request<()>) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::delete(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = DeleteSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/ratings.features.User/Vote" => { + #[allow(non_camel_case_types)] + struct VoteSvc(pub Arc); + impl tonic::server::UnaryService + for VoteSvc { + type Response = (); + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::vote(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = VoteSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/ratings.features.User/ListMyVotes" => { + #[allow(non_camel_case_types)] + struct ListMyVotesSvc(pub Arc); + impl tonic::server::UnaryService + for ListMyVotesSvc { + type Response = super::ListMyVotesResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::list_my_votes(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = ListMyVotesSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/ratings.features.User/GetSnapVotes" => { + #[allow(non_camel_case_types)] + struct GetSnapVotesSvc(pub Arc); + impl tonic::server::UnaryService + for GetSnapVotesSvc { + type Response = super::GetSnapVotesResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::get_snap_votes(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = GetSnapVotesSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } + } + } + } + impl Clone for UserServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { + inner, + accept_compression_encodings: self.accept_compression_encodings, + send_compression_encodings: self.send_compression_encodings, + max_decoding_message_size: self.max_decoding_message_size, + max_encoding_message_size: self.max_encoding_message_size, + } + } + } + impl Clone for _Inner { + fn clone(&self) -> Self { + Self(Arc::clone(&self.0)) + } + } + impl std::fmt::Debug for _Inner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } + } + impl tonic::server::NamedService for UserServer { + const NAME: &'static str = "ratings.features.User"; + } +} diff --git a/src/protos/ratings.rs b/src/protos/ratings.rs new file mode 100644 index 0000000..63f3619 --- /dev/null +++ b/src/protos/ratings.rs @@ -0,0 +1,1407 @@ +// This file is @generated by prost-build. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetRatingRequest { + #[prost(string, tag = "1")] + pub snap_id: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetRatingResponse { + #[prost(message, optional, tag = "1")] + pub rating: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetChartRequest { + #[prost(enumeration = "Timeframe", tag = "1")] + pub timeframe: i32, + #[prost(enumeration = "Category", optional, tag = "2")] + pub category: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetChartResponse { + #[prost(enumeration = "Timeframe", tag = "1")] + pub timeframe: i32, + #[prost(message, repeated, tag = "2")] + pub ordered_chart_data: ::prost::alloc::vec::Vec, + #[prost(enumeration = "Category", optional, tag = "3")] + pub category: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ChartData { + #[prost(float, tag = "1")] + pub raw_rating: f32, + #[prost(message, optional, tag = "2")] + pub rating: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct AuthenticateRequest { + #[prost(string, tag = "1")] + pub id: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct AuthenticateResponse { + #[prost(string, tag = "1")] + pub token: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ListMyVotesRequest { + #[prost(string, tag = "1")] + pub snap_id_filter: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ListMyVotesResponse { + #[prost(message, repeated, tag = "1")] + pub votes: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetSnapVotesRequest { + #[prost(string, tag = "1")] + pub snap_id: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GetSnapVotesResponse { + #[prost(message, repeated, tag = "1")] + pub votes: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Vote { + #[prost(string, tag = "1")] + pub snap_id: ::prost::alloc::string::String, + #[prost(int32, tag = "2")] + pub snap_revision: i32, + #[prost(bool, tag = "3")] + pub vote_up: bool, + #[prost(message, optional, tag = "4")] + pub timestamp: ::core::option::Option<::prost_types::Timestamp>, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct VoteRequest { + #[prost(string, tag = "1")] + pub snap_id: ::prost::alloc::string::String, + #[prost(int32, tag = "2")] + pub snap_revision: i32, + #[prost(bool, tag = "3")] + pub vote_up: bool, +} +/// Common messages +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Rating { + #[prost(string, tag = "1")] + pub snap_id: ::prost::alloc::string::String, + #[prost(uint64, tag = "2")] + pub total_votes: u64, + #[prost(enumeration = "RatingsBand", tag = "3")] + pub ratings_band: i32, +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum Timeframe { + Unspecified = 0, + Week = 1, + Month = 2, +} +impl Timeframe { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Timeframe::Unspecified => "TIMEFRAME_UNSPECIFIED", + Timeframe::Week => "TIMEFRAME_WEEK", + Timeframe::Month => "TIMEFRAME_MONTH", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "TIMEFRAME_UNSPECIFIED" => Some(Self::Unspecified), + "TIMEFRAME_WEEK" => Some(Self::Week), + "TIMEFRAME_MONTH" => Some(Self::Month), + _ => None, + } + } +} +#[derive(sqlx::Type, strum::EnumString)] +#[strum(serialize_all = "kebab_case", ascii_case_insensitive)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum Category { + ArtAndDesign = 0, + BookAndReference = 1, + Development = 2, + DevicesAndIot = 3, + Education = 4, + Entertainment = 5, + Featured = 6, + Finance = 7, + Games = 8, + HealthAndFitness = 9, + MusicAndAudio = 10, + NewsAndWeather = 11, + Personalisation = 12, + PhotoAndVideo = 13, + Productivity = 14, + Science = 15, + Security = 16, + ServerAndCloud = 17, + Social = 18, + Utilities = 19, +} +impl Category { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Category::ArtAndDesign => "ART_AND_DESIGN", + Category::BookAndReference => "BOOK_AND_REFERENCE", + Category::Development => "DEVELOPMENT", + Category::DevicesAndIot => "DEVICES_AND_IOT", + Category::Education => "EDUCATION", + Category::Entertainment => "ENTERTAINMENT", + Category::Featured => "FEATURED", + Category::Finance => "FINANCE", + Category::Games => "GAMES", + Category::HealthAndFitness => "HEALTH_AND_FITNESS", + Category::MusicAndAudio => "MUSIC_AND_AUDIO", + Category::NewsAndWeather => "NEWS_AND_WEATHER", + Category::Personalisation => "PERSONALISATION", + Category::PhotoAndVideo => "PHOTO_AND_VIDEO", + Category::Productivity => "PRODUCTIVITY", + Category::Science => "SCIENCE", + Category::Security => "SECURITY", + Category::ServerAndCloud => "SERVER_AND_CLOUD", + Category::Social => "SOCIAL", + Category::Utilities => "UTILITIES", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "ART_AND_DESIGN" => Some(Self::ArtAndDesign), + "BOOK_AND_REFERENCE" => Some(Self::BookAndReference), + "DEVELOPMENT" => Some(Self::Development), + "DEVICES_AND_IOT" => Some(Self::DevicesAndIot), + "EDUCATION" => Some(Self::Education), + "ENTERTAINMENT" => Some(Self::Entertainment), + "FEATURED" => Some(Self::Featured), + "FINANCE" => Some(Self::Finance), + "GAMES" => Some(Self::Games), + "HEALTH_AND_FITNESS" => Some(Self::HealthAndFitness), + "MUSIC_AND_AUDIO" => Some(Self::MusicAndAudio), + "NEWS_AND_WEATHER" => Some(Self::NewsAndWeather), + "PERSONALISATION" => Some(Self::Personalisation), + "PHOTO_AND_VIDEO" => Some(Self::PhotoAndVideo), + "PRODUCTIVITY" => Some(Self::Productivity), + "SCIENCE" => Some(Self::Science), + "SECURITY" => Some(Self::Security), + "SERVER_AND_CLOUD" => Some(Self::ServerAndCloud), + "SOCIAL" => Some(Self::Social), + "UTILITIES" => Some(Self::Utilities), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum RatingsBand { + VeryGood = 0, + Good = 1, + Neutral = 2, + Poor = 3, + VeryPoor = 4, + InsufficientVotes = 5, +} +impl RatingsBand { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + RatingsBand::VeryGood => "VERY_GOOD", + RatingsBand::Good => "GOOD", + RatingsBand::Neutral => "NEUTRAL", + RatingsBand::Poor => "POOR", + RatingsBand::VeryPoor => "VERY_POOR", + RatingsBand::InsufficientVotes => "INSUFFICIENT_VOTES", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "VERY_GOOD" => Some(Self::VeryGood), + "GOOD" => Some(Self::Good), + "NEUTRAL" => Some(Self::Neutral), + "POOR" => Some(Self::Poor), + "VERY_POOR" => Some(Self::VeryPoor), + "INSUFFICIENT_VOTES" => Some(Self::InsufficientVotes), + _ => None, + } + } +} +/// Generated client implementations. +pub mod app_client { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + use tonic::codegen::http::Uri; + /// App service + #[derive(Debug, Clone)] + pub struct AppClient { + inner: tonic::client::Grpc, + } + impl AppClient { + /// Attempt to create a new client by connecting to a given endpoint. + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; + Ok(Self::new(conn)) + } + } + impl AppClient + where + T: tonic::client::GrpcService, + T::Error: Into, + T::ResponseBody: Body + Send + 'static, + ::Error: Into + Send, + { + pub fn new(inner: T) -> Self { + let inner = tonic::client::Grpc::new(inner); + Self { inner } + } + pub fn with_origin(inner: T, origin: Uri) -> Self { + let inner = tonic::client::Grpc::with_origin(inner, origin); + Self { inner } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> AppClient> + where + F: tonic::service::Interceptor, + T::ResponseBody: Default, + T: tonic::codegen::Service< + http::Request, + Response = http::Response< + >::ResponseBody, + >, + >, + , + >>::Error: Into + Send + Sync, + { + AppClient::new(InterceptedService::new(inner, interceptor)) + } + /// Compress requests with the given encoding. + /// + /// This requires the server to support it otherwise it might respond with an + /// error. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.send_compressed(encoding); + self + } + /// Enable decompressing responses. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.accept_compressed(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_decoding_message_size(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_encoding_message_size(limit); + self + } + pub async fn get_rating( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static("/ratings.App/GetRating"); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("ratings.App", "GetRating")); + self.inner.unary(req, path, codec).await + } + } +} +/// Generated client implementations. +pub mod chart_client { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + use tonic::codegen::http::Uri; + /// Chart service + #[derive(Debug, Clone)] + pub struct ChartClient { + inner: tonic::client::Grpc, + } + impl ChartClient { + /// Attempt to create a new client by connecting to a given endpoint. + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; + Ok(Self::new(conn)) + } + } + impl ChartClient + where + T: tonic::client::GrpcService, + T::Error: Into, + T::ResponseBody: Body + Send + 'static, + ::Error: Into + Send, + { + pub fn new(inner: T) -> Self { + let inner = tonic::client::Grpc::new(inner); + Self { inner } + } + pub fn with_origin(inner: T, origin: Uri) -> Self { + let inner = tonic::client::Grpc::with_origin(inner, origin); + Self { inner } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> ChartClient> + where + F: tonic::service::Interceptor, + T::ResponseBody: Default, + T: tonic::codegen::Service< + http::Request, + Response = http::Response< + >::ResponseBody, + >, + >, + , + >>::Error: Into + Send + Sync, + { + ChartClient::new(InterceptedService::new(inner, interceptor)) + } + /// Compress requests with the given encoding. + /// + /// This requires the server to support it otherwise it might respond with an + /// error. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.send_compressed(encoding); + self + } + /// Enable decompressing responses. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.accept_compressed(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_decoding_message_size(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_encoding_message_size(limit); + self + } + pub async fn get_chart( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static("/ratings.Chart/GetChart"); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("ratings.Chart", "GetChart")); + self.inner.unary(req, path, codec).await + } + } +} +/// Generated client implementations. +pub mod user_client { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + use tonic::codegen::http::Uri; + /// User service + #[derive(Debug, Clone)] + pub struct UserClient { + inner: tonic::client::Grpc, + } + impl UserClient { + /// Attempt to create a new client by connecting to a given endpoint. + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; + Ok(Self::new(conn)) + } + } + impl UserClient + where + T: tonic::client::GrpcService, + T::Error: Into, + T::ResponseBody: Body + Send + 'static, + ::Error: Into + Send, + { + pub fn new(inner: T) -> Self { + let inner = tonic::client::Grpc::new(inner); + Self { inner } + } + pub fn with_origin(inner: T, origin: Uri) -> Self { + let inner = tonic::client::Grpc::with_origin(inner, origin); + Self { inner } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> UserClient> + where + F: tonic::service::Interceptor, + T::ResponseBody: Default, + T: tonic::codegen::Service< + http::Request, + Response = http::Response< + >::ResponseBody, + >, + >, + , + >>::Error: Into + Send + Sync, + { + UserClient::new(InterceptedService::new(inner, interceptor)) + } + /// Compress requests with the given encoding. + /// + /// This requires the server to support it otherwise it might respond with an + /// error. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.send_compressed(encoding); + self + } + /// Enable decompressing responses. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.accept_compressed(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_decoding_message_size(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_encoding_message_size(limit); + self + } + pub async fn authenticate( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/ratings.User/Authenticate", + ); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("ratings.User", "Authenticate")); + self.inner.unary(req, path, codec).await + } + pub async fn delete( + &mut self, + request: impl tonic::IntoRequest<()>, + ) -> std::result::Result, tonic::Status> { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static("/ratings.User/Delete"); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("ratings.User", "Delete")); + self.inner.unary(req, path, codec).await + } + pub async fn vote( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result, tonic::Status> { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static("/ratings.User/Vote"); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("ratings.User", "Vote")); + self.inner.unary(req, path, codec).await + } + pub async fn list_my_votes( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static("/ratings.User/ListMyVotes"); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("ratings.User", "ListMyVotes")); + self.inner.unary(req, path, codec).await + } + pub async fn get_snap_votes( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/ratings.User/GetSnapVotes", + ); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("ratings.User", "GetSnapVotes")); + self.inner.unary(req, path, codec).await + } + } +} +/// Generated server implementations. +pub mod app_server { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + /// Generated trait containing gRPC methods that should be implemented for use with AppServer. + #[async_trait] + pub trait App: Send + Sync + 'static { + async fn get_rating( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + } + /// App service + #[derive(Debug)] + pub struct AppServer { + inner: _Inner, + accept_compression_encodings: EnabledCompressionEncodings, + send_compression_encodings: EnabledCompressionEncodings, + max_decoding_message_size: Option, + max_encoding_message_size: Option, + } + struct _Inner(Arc); + impl AppServer { + pub fn new(inner: T) -> Self { + Self::from_arc(Arc::new(inner)) + } + pub fn from_arc(inner: Arc) -> Self { + let inner = _Inner(inner); + Self { + inner, + accept_compression_encodings: Default::default(), + send_compression_encodings: Default::default(), + max_decoding_message_size: None, + max_encoding_message_size: None, + } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService + where + F: tonic::service::Interceptor, + { + InterceptedService::new(Self::new(inner), interceptor) + } + /// Enable decompressing requests with the given encoding. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.accept_compression_encodings.enable(encoding); + self + } + /// Compress responses with the given encoding, if the client supports it. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.send_compression_encodings.enable(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.max_decoding_message_size = Some(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.max_encoding_message_size = Some(limit); + self + } + } + impl tonic::codegen::Service> for AppServer + where + T: App, + B: Body + Send + 'static, + B::Error: Into + Send + 'static, + { + type Response = http::Response; + type Error = std::convert::Infallible; + type Future = BoxFuture; + fn poll_ready( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: http::Request) -> Self::Future { + let inner = self.inner.clone(); + match req.uri().path() { + "/ratings.App/GetRating" => { + #[allow(non_camel_case_types)] + struct GetRatingSvc(pub Arc); + impl tonic::server::UnaryService + for GetRatingSvc { + type Response = super::GetRatingResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::get_rating(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = GetRatingSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } + } + } + } + impl Clone for AppServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { + inner, + accept_compression_encodings: self.accept_compression_encodings, + send_compression_encodings: self.send_compression_encodings, + max_decoding_message_size: self.max_decoding_message_size, + max_encoding_message_size: self.max_encoding_message_size, + } + } + } + impl Clone for _Inner { + fn clone(&self) -> Self { + Self(Arc::clone(&self.0)) + } + } + impl std::fmt::Debug for _Inner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } + } + impl tonic::server::NamedService for AppServer { + const NAME: &'static str = "ratings.App"; + } +} +/// Generated server implementations. +pub mod chart_server { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + /// Generated trait containing gRPC methods that should be implemented for use with ChartServer. + #[async_trait] + pub trait Chart: Send + Sync + 'static { + async fn get_chart( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + } + /// Chart service + #[derive(Debug)] + pub struct ChartServer { + inner: _Inner, + accept_compression_encodings: EnabledCompressionEncodings, + send_compression_encodings: EnabledCompressionEncodings, + max_decoding_message_size: Option, + max_encoding_message_size: Option, + } + struct _Inner(Arc); + impl ChartServer { + pub fn new(inner: T) -> Self { + Self::from_arc(Arc::new(inner)) + } + pub fn from_arc(inner: Arc) -> Self { + let inner = _Inner(inner); + Self { + inner, + accept_compression_encodings: Default::default(), + send_compression_encodings: Default::default(), + max_decoding_message_size: None, + max_encoding_message_size: None, + } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService + where + F: tonic::service::Interceptor, + { + InterceptedService::new(Self::new(inner), interceptor) + } + /// Enable decompressing requests with the given encoding. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.accept_compression_encodings.enable(encoding); + self + } + /// Compress responses with the given encoding, if the client supports it. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.send_compression_encodings.enable(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.max_decoding_message_size = Some(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.max_encoding_message_size = Some(limit); + self + } + } + impl tonic::codegen::Service> for ChartServer + where + T: Chart, + B: Body + Send + 'static, + B::Error: Into + Send + 'static, + { + type Response = http::Response; + type Error = std::convert::Infallible; + type Future = BoxFuture; + fn poll_ready( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: http::Request) -> Self::Future { + let inner = self.inner.clone(); + match req.uri().path() { + "/ratings.Chart/GetChart" => { + #[allow(non_camel_case_types)] + struct GetChartSvc(pub Arc); + impl tonic::server::UnaryService + for GetChartSvc { + type Response = super::GetChartResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::get_chart(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = GetChartSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } + } + } + } + impl Clone for ChartServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { + inner, + accept_compression_encodings: self.accept_compression_encodings, + send_compression_encodings: self.send_compression_encodings, + max_decoding_message_size: self.max_decoding_message_size, + max_encoding_message_size: self.max_encoding_message_size, + } + } + } + impl Clone for _Inner { + fn clone(&self) -> Self { + Self(Arc::clone(&self.0)) + } + } + impl std::fmt::Debug for _Inner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } + } + impl tonic::server::NamedService for ChartServer { + const NAME: &'static str = "ratings.Chart"; + } +} +/// Generated server implementations. +pub mod user_server { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + /// Generated trait containing gRPC methods that should be implemented for use with UserServer. + #[async_trait] + pub trait User: Send + Sync + 'static { + async fn authenticate( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + async fn delete( + &self, + request: tonic::Request<()>, + ) -> std::result::Result, tonic::Status>; + async fn vote( + &self, + request: tonic::Request, + ) -> std::result::Result, tonic::Status>; + async fn list_my_votes( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + async fn get_snap_votes( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + } + /// User service + #[derive(Debug)] + pub struct UserServer { + inner: _Inner, + accept_compression_encodings: EnabledCompressionEncodings, + send_compression_encodings: EnabledCompressionEncodings, + max_decoding_message_size: Option, + max_encoding_message_size: Option, + } + struct _Inner(Arc); + impl UserServer { + pub fn new(inner: T) -> Self { + Self::from_arc(Arc::new(inner)) + } + pub fn from_arc(inner: Arc) -> Self { + let inner = _Inner(inner); + Self { + inner, + accept_compression_encodings: Default::default(), + send_compression_encodings: Default::default(), + max_decoding_message_size: None, + max_encoding_message_size: None, + } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService + where + F: tonic::service::Interceptor, + { + InterceptedService::new(Self::new(inner), interceptor) + } + /// Enable decompressing requests with the given encoding. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.accept_compression_encodings.enable(encoding); + self + } + /// Compress responses with the given encoding, if the client supports it. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.send_compression_encodings.enable(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.max_decoding_message_size = Some(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.max_encoding_message_size = Some(limit); + self + } + } + impl tonic::codegen::Service> for UserServer + where + T: User, + B: Body + Send + 'static, + B::Error: Into + Send + 'static, + { + type Response = http::Response; + type Error = std::convert::Infallible; + type Future = BoxFuture; + fn poll_ready( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: http::Request) -> Self::Future { + let inner = self.inner.clone(); + match req.uri().path() { + "/ratings.User/Authenticate" => { + #[allow(non_camel_case_types)] + struct AuthenticateSvc(pub Arc); + impl tonic::server::UnaryService + for AuthenticateSvc { + type Response = super::AuthenticateResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::authenticate(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = AuthenticateSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/ratings.User/Delete" => { + #[allow(non_camel_case_types)] + struct DeleteSvc(pub Arc); + impl tonic::server::UnaryService<()> for DeleteSvc { + type Response = (); + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call(&mut self, request: tonic::Request<()>) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::delete(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = DeleteSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/ratings.User/Vote" => { + #[allow(non_camel_case_types)] + struct VoteSvc(pub Arc); + impl tonic::server::UnaryService + for VoteSvc { + type Response = (); + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::vote(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = VoteSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/ratings.User/ListMyVotes" => { + #[allow(non_camel_case_types)] + struct ListMyVotesSvc(pub Arc); + impl tonic::server::UnaryService + for ListMyVotesSvc { + type Response = super::ListMyVotesResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::list_my_votes(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = ListMyVotesSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/ratings.User/GetSnapVotes" => { + #[allow(non_camel_case_types)] + struct GetSnapVotesSvc(pub Arc); + impl tonic::server::UnaryService + for GetSnapVotesSvc { + type Response = super::GetSnapVotesResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::get_snap_votes(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = GetSnapVotesSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } + } + } + } + impl Clone for UserServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { + inner, + accept_compression_encodings: self.accept_compression_encodings, + send_compression_encodings: self.send_compression_encodings, + max_decoding_message_size: self.max_decoding_message_size, + max_encoding_message_size: self.max_encoding_message_size, + } + } + } + impl Clone for _Inner { + fn clone(&self) -> Self { + Self(Arc::clone(&self.0)) + } + } + impl std::fmt::Debug for _Inner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } + } + impl tonic::server::NamedService for UserServer { + const NAME: &'static str = "ratings.User"; + } +} diff --git a/tests/chart.rs b/tests/chart.rs index 3496cc0..4d38910 100644 --- a/tests/chart.rs +++ b/tests/chart.rs @@ -7,7 +7,7 @@ use rand::{thread_rng, Rng}; use ratings::{ features::{ common::entities::{calculate_band, VoteSummary}, - pb::chart::{Category, ChartData, Timeframe}, + pb::protos::{Category, ChartData, Timeframe}, }, utils::{Config, Infrastructure}, }; diff --git a/tests/helpers/client/app.rs b/tests/helpers/client/app.rs index 0c27bda..3da6c30 100644 --- a/tests/helpers/client/app.rs +++ b/tests/helpers/client/app.rs @@ -1,9 +1,9 @@ use tonic::async_trait; use tonic::{metadata::MetadataValue, transport::Endpoint, Request, Response, Status}; -use ratings::features::pb::app::{GetRatingRequest, GetRatingResponse}; +use ratings::features::pb::protos::{GetRatingRequest, GetRatingResponse}; -use ratings::features::pb::app::app_client as pb; +use ratings::features::pb::protos::app_client as pb; use super::Client; diff --git a/tests/helpers/client/chart.rs b/tests/helpers/client/chart.rs index 70cb20f..1de53ea 100644 --- a/tests/helpers/client/chart.rs +++ b/tests/helpers/client/chart.rs @@ -2,8 +2,8 @@ use tonic::metadata::MetadataValue; use tonic::transport::Endpoint; use tonic::{async_trait, Request, Response, Status}; -use ratings::features::pb::chart::{chart_client as pb, Category, Timeframe}; -use ratings::features::pb::chart::{GetChartRequest, GetChartResponse}; +use ratings::features::pb::protos::{chart_client as pb, Category, Timeframe}; +use ratings::features::pb::protos::{GetChartRequest, GetChartResponse}; use super::Client; diff --git a/tests/helpers/client/user.rs b/tests/helpers/client/user.rs index 940cef9..31d80f9 100644 --- a/tests/helpers/client/user.rs +++ b/tests/helpers/client/user.rs @@ -2,8 +2,8 @@ use tonic::metadata::MetadataValue; use tonic::transport::Endpoint; use tonic::{async_trait, Request, Response, Status}; -use ratings::features::pb::user::user_client as pb; -use ratings::features::pb::user::{ +use ratings::features::pb::protos::user_client as pb; +use ratings::features::pb::protos::{ AuthenticateRequest, AuthenticateResponse, GetSnapVotesRequest, GetSnapVotesResponse, VoteRequest, }; diff --git a/tests/helpers/vote_generator.rs b/tests/helpers/vote_generator.rs index 001e973..a3961f8 100644 --- a/tests/helpers/vote_generator.rs +++ b/tests/helpers/vote_generator.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use super::client::*; use crate::helpers; use futures::future::join_all; -use ratings::features::pb::user::{AuthenticateResponse, VoteRequest}; +use ratings::features::pb::protos::{AuthenticateResponse, VoteRequest}; use thiserror::Error; use tonic::Status; diff --git a/tests/voting.rs b/tests/voting.rs index a9c58d6..fe627b9 100644 --- a/tests/voting.rs +++ b/tests/voting.rs @@ -5,7 +5,7 @@ use helpers::client::*; use ratings::{ features::{ common::entities::{Rating, RatingsBand, VoteSummary}, - pb::user::VoteRequest, + pb::protos::VoteRequest, }, utils::Config, }; @@ -246,7 +246,7 @@ async fn check_upvote(world: &mut VotingWorld, direction: Direction) { .ratings_band; let band = - ratings::features::pb::common::RatingsBand::try_from(band).expect("Unknown ratings band"); + ratings::features::pb::protos::RatingsBand::try_from(band).expect("Unknown ratings band"); direction.check_and_apply_band(&mut world.rating.ratings_band, band.into()); }