Skip to content

Commit

Permalink
chore: combining protos into one file and commiting output to src/protos
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-hagemann committed Sep 23, 2024
1 parent 692b9d1 commit 1189fc1
Show file tree
Hide file tree
Showing 27 changed files with 3,001 additions and 205 deletions.
11 changes: 3 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ use std::path::Path;

fn init_proto() -> Result<(), Box<dyn std::error::Error>> {
// 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!(
"{}/ratings_descriptor.bin",
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
Expand All @@ -28,7 +23,7 @@ fn init_proto() -> Result<(), Box<dyn std::error::Error>> {
"Category",
r#"#[strum(serialize_all = "kebab_case", ascii_case_insensitive)]"#,
)
.compile(files, &["proto"])?;
.compile(files, &["protos"])?;

Ok(())
}
Expand Down
17 changes: 0 additions & 17 deletions proto/ratings_features_app.proto

This file was deleted.

57 changes: 0 additions & 57 deletions proto/ratings_features_chart.proto

This file was deleted.

18 changes: 0 additions & 18 deletions proto/ratings_features_common.proto

This file was deleted.

53 changes: 0 additions & 53 deletions proto/ratings_features_user.proto

This file was deleted.

133 changes: 133 additions & 0 deletions protos/ratings.proto
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion src/features/chart/entities.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/features/chart/infrastructure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
features::{
chart::errors::ChartError,
common::entities::VoteSummary,
pb::chart::{Category, Timeframe},
pb::protos::{Category, Timeframe},
},
};
use sqlx::QueryBuilder;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/features/chart/service/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion src/features/chart/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/features/chart/use_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 1189fc1

Please sign in to comment.