Skip to content

Commit

Permalink
refactor: updating protos to use common defs
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-hagemann committed Nov 24, 2023
1 parent e845067 commit 7e9009b
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 36 deletions.
19 changes: 3 additions & 16 deletions proto/ratings_features_app.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package ratings.features.app;

import "ratings_features_common.proto";

service App {
rpc GetRating (GetRatingRequest) returns (GetRatingResponse) {}
}
Expand All @@ -11,20 +13,5 @@ message GetRatingRequest {
}

message GetRatingResponse {
Rating rating = 1;
}

message Rating {
string snap_id = 1;
uint64 total_votes = 2;
RatingsBand ratings_band = 3;
}

enum RatingsBand {
VERY_GOOD = 0;
GOOD = 1;
NEUTRAL = 2;
POOR = 3;
VERY_POOR = 4;
INSUFFICIENT_VOTES = 5;
ratings.features.common.Rating rating = 1;
}
18 changes: 4 additions & 14 deletions proto/ratings_features_chart.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package ratings.features.chart;

import "ratings_features_common.proto";

service Chart {
rpc GetChart (GetChartRequest) returns (GetChartResponse) {}
}
Expand All @@ -16,24 +18,12 @@ message GetChartResponse {
}

message ChartData {
string app = 1;
uint64 total_up_votes = 2;
uint64 total_down_votes = 3;
float rating = 4;
RatingsBand rating_band = 5;
float raw_rating = 1;
ratings.features.common.Rating rating = 2;
}

enum Timeframe {
TIMEFRAME_UNSPECIFIED = 0;
TIMEFRAME_WEEK = 1;
TIMEFRAME_MONTH = 2;
}

enum RatingsBand {
VERY_GOOD = 0;
GOOD = 1;
NEUTRAL = 2;
POOR = 3;
VERY_POOR = 4;
INSUFFICIENT_VOTES = 5;
}
18 changes: 18 additions & 0 deletions proto/ratings_features_common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package ratings.features.common;

message Rating {
string snap_id = 1;
uint64 total_votes = 2;
RatingsBand ratings_band = 3;
}

enum RatingsBand {
VERY_GOOD = 0;
GOOD = 1;
NEUTRAL = 2;
POOR = 3;
VERY_POOR = 4;
INSUFFICIENT_VOTES = 5;
}
4 changes: 2 additions & 2 deletions src/features/app/infrastructure.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::app::AppContext;
use crate::{app::AppContext, features::common::entities::Vote};
use sqlx::Row;
use tracing::error;

use super::{entities::Vote, errors::AppError};
use super::errors::AppError;

pub(crate) async fn get_votes_by_snap_id(
app_ctx: &AppContext,
Expand Down
1 change: 0 additions & 1 deletion src/features/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod entities;
mod errors;
mod infrastructure;
pub mod interface;
Expand Down
4 changes: 2 additions & 2 deletions src/features/app/use_cases.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::app::AppContext;
use crate::{app::AppContext, features::common::entities::Rating};
use tracing::error;

use super::{entities::Rating, errors::AppError, infrastructure::get_votes_by_snap_id};
use super::{errors::AppError, infrastructure::get_votes_by_snap_id};

pub async fn get_rating(app_ctx: &AppContext, snap_id: String) -> Result<Rating, AppError> {
let votes = get_votes_by_snap_id(app_ctx, &snap_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use sqlx::FromRow;

use super::interface::protobuf;
pub mod protobuf {
tonic::include_proto!("ratings.features.common");
}

const INSUFFICIENT_VOTES_QUANTITY: usize = 25;

Expand Down
1 change: 1 addition & 0 deletions src/features/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod entities;
1 change: 1 addition & 0 deletions src/features/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod app;
mod common;
pub mod user;

0 comments on commit 7e9009b

Please sign in to comment.