-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3c03f3
commit 17af0cf
Showing
18 changed files
with
494 additions
and
207 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
syntax = "proto3"; | ||
|
||
package helloworld; | ||
import "google/protobuf/struct.proto"; | ||
|
||
// The greeting service definition. | ||
service Greeter { | ||
// Sends a greeting | ||
rpc SayHello (HelloRequest) returns (HelloReply) {} | ||
package services.notifications.v1; | ||
|
||
service NotificationsService { | ||
rpc ShouldSendNotification (ShouldSendNotificationRequest) returns (ShouldSendNotificationResponse) {} | ||
} | ||
|
||
enum NotificationChannel { | ||
PUSH = 0; | ||
} | ||
|
||
// The request message containing the user's name. | ||
message HelloRequest { | ||
string name = 1; | ||
enum NotificationCategory { | ||
CIRCLES = 0; | ||
PAYMENTS = 1; | ||
} | ||
|
||
// The response message containing the greetings. | ||
message HelloReply { | ||
string message = 1; | ||
message ShouldSendNotificationRequest { | ||
string user_id = 1; | ||
NotificationChannel channel = 2; | ||
NotificationCategory category = 3; | ||
} | ||
|
||
message ShouldSendNotificationResponse { | ||
string user_id = 1; | ||
bool should_send = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct GrpcServerConfig { | ||
#[serde(default = "default_port")] | ||
pub listen_port: u16, | ||
} | ||
|
||
impl Default for GrpcServerConfig { | ||
fn default() -> Self { | ||
Self { | ||
listen_port: default_port(), | ||
} | ||
} | ||
} | ||
|
||
fn default_port() -> u16 { | ||
2478 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
mod config; | ||
mod server; | ||
|
||
use crate::app::*; | ||
|
||
pub use config::*; | ||
pub use server::*; | ||
|
||
pub async fn run_server(config: GrpcServerConfig, app: NotificationsApp) -> anyhow::Result<()> { | ||
server::start(config, app).await?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::app::ApplicationError; | ||
use crate::primitives::{UserNotificationCategory, UserNotificationChannel}; | ||
|
||
impl From<i32> for UserNotificationCategory { | ||
fn from(category: i32) -> Self { | ||
match category { | ||
0 => UserNotificationCategory::Circles, | ||
1 => UserNotificationCategory::Payments, | ||
_ => unimplemented!(), | ||
} | ||
} | ||
} | ||
|
||
impl From<i32> for UserNotificationChannel { | ||
fn from(channel: i32) -> Self { | ||
match channel { | ||
0 => UserNotificationChannel::Push, | ||
_ => unimplemented!(), | ||
} | ||
} | ||
} | ||
|
||
impl From<ApplicationError> for tonic::Status { | ||
fn from(err: ApplicationError) -> Self { | ||
match err { | ||
_ => tonic::Status::internal(err.to_string()), | ||
} | ||
} | ||
} |
Oops, something went wrong.