diff --git a/README.md b/README.md index 7e0fc90a6f1204f027d6bd86f449e2de09b46e7c..b2bf96719e6568d704a8d8a5a84548da3cc14911 100644 --- a/README.md +++ b/README.md @@ -86,4 +86,13 @@ This is the place for you to write reflections: #### Reflection Subscriber-1 +##### RwLock vs Mutex + +Read-write Lock (RwLock) allows multiple threads to read the notification, which is impossible with Mutex. This allows multiple API requests to view notifications concurrently without blocking each other. + +##### Static variables in Rust vs Java + +Static variables in Rust guarantess Memory Safety and thread safety during compile time. +Unlike Java, Rust's approach doesn't allow static mutability as it might cause potential data races. + #### Reflection Subscriber-2 diff --git a/src/controller/mod.rs b/src/controller/mod.rs index b511e7728fb221d6569cef381e67591ab196459b..6d4d97cf7405e3354b43edee0c7916ba2031eba8 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -1,8 +1,8 @@ use rocket::fairing::AdHoc; +pub mod notification; pub fn route_stage() -> AdHoc { return AdHoc::on_ignite("Initializing controller routes...", |rocket| async { - rocket - .mount("/", routes![]) + rocket.mount("/", routes![]) }); } diff --git a/src/controller/notification.rs b/src/controller/notification.rs new file mode 100644 index 0000000000000000000000000000000000000000..0fa74ed62c181f07ec2edfda73a5249a9b820e97 --- /dev/null +++ b/src/controller/notification.rs @@ -0,0 +1,6 @@ +use rocket::serde::json::Json; + +use crate::model::notification::Notification; +use crate::model::subscriber::SubscriberRequest; +use crate::service::notification::NotificationService; +use bambangshop_receiver::Result; diff --git a/src/service/mod.rs b/src/service/mod.rs index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b92750cda38ca1432435b21a07d2886fe6a47a93 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -0,0 +1 @@ +pub mod notification; diff --git a/src/service/notification.rs b/src/service/notification.rs new file mode 100644 index 0000000000000000000000000000000000000000..fd6b9cd82a18756b8180d3c1c0d6a32207a671e1 --- /dev/null +++ b/src/service/notification.rs @@ -0,0 +1,15 @@ +use std::thread; + +use rocket::http::Status; +use rocket::log; +use rocket::serde::json::to_string; +use rocket::tokio; + +use crate::model::notification::Notification; +use crate::model::subscriber::SubscriberRequest; +use crate::repository::notification::NotificationRepository; +use bambangshop_receiver::{compose_error_response, Result, APP_CONFIG, REQWEST_CLIENT}; + +pub struct NotificationService; + +impl NotificationService {}