From f81508535a4d525149055ffccd77f04949fc456a Mon Sep 17 00:00:00 2001 From: Christian Raphael Heryanto <christian.raphael@ui.ac.id> Date: Fri, 28 Mar 2025 15:27:39 +0800 Subject: [PATCH] Create Notification service struct skeleton. --- README.md | 9 +++++++++ src/controller/mod.rs | 4 ++-- src/controller/notification.rs | 6 ++++++ src/service/mod.rs | 1 + src/service/notification.rs | 15 +++++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/controller/notification.rs create mode 100644 src/service/notification.rs diff --git a/README.md b/README.md index 7e0fc90..b2bf967 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 b511e77..6d4d97c 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 0000000..0fa74ed --- /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 e69de29..b92750c 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 0000000..fd6b9cd --- /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 {} -- GitLab