From 1774bc072ad3b5064cd50604100f945bde0ffa5c Mon Sep 17 00:00:00 2001 From: rafliesa <rflisaa@gmail.com> Date: Fri, 28 Mar 2025 00:46:16 +0700 Subject: [PATCH] Reflection Publisher-1 --- README.md | 87 +++++-------------------------------------------------- 1 file changed, 7 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 3043f06..52100ea 100644 --- a/README.md +++ b/README.md @@ -1,83 +1,10 @@ -# BambangShop Publisher App -Tutorial and Example for Advanced Programming 2024 - Faculty of Computer Science, Universitas Indonesia +# Reflection Publisher-1 ---- +## 1. In the Observer pattern diagram explained by the Head First Design Pattern book, Subscriber is defined as an interface. Explain based on your understanding of Observer design patterns, do we still need an interface (or trait in Rust) in this BambangShop case, or a single Model struct is enough? +Tujuan Subscriber didefinisikan sebagai interface adalah untuk mendukung banyak implementasi dari observer. Hal ini juga memastikan bahwa setiap observer dapat dinotify secara seragam oleh publisher tanpa perlu mengetahui jenis spesifik dari observer.<br>Pada kasus bambangshop, tergantung tujuan apakah kita berniat menambah observer selai User di masa yang akan datang. Jika iya, alangkah baiknya kita tetap menggunakan interface/trait supaya memungkinkan kita menambah observer selain User di masa depan. Tetapi jika tidak, tidak perlu menggunakan interface/trait karena akan membuat struktur kode justru menjadi lebih kompleks. -## About this Project -In this repository, we have provided you a REST (REpresentational State Transfer) API project using Rocket web framework. +## 2. id in Program and url in Subscriber is intended to be unique. Explain based on your understanding, is using Vec (list) sufficient or using DashMap (map/dictionary) like we currently use is necessary for this case? +Kita bisa saja menggunakan Vec (list) untuk kasus ini. Namun, drawback terbesarnya ada pada kompleksitas waktunya. Jika kita hanya menggunakan Vect (list), kita tidak bisa secara langsung memverifikasi keunikan id dan url yang sedang diinsert. Sehingga butuh looping untuk mengecek satu persatu elemen yang memakan waktu O(N). Sedangkan dengan DashMap ( What a cute name :> ), kita dapat melakukan hal tersebut dengan kompleksitas rata-rata O(1) karena kita dapat langsung mengetahui apakah index yg digenerate oleh hash sudah ditempati atau belum. -This project consists of four modules: -1. `controller`: this module contains handler functions used to receive request and send responses. - In Model-View-Controller (MVC) pattern, this is the Controller part. -2. `model`: this module contains structs that serve as data containers. - In MVC pattern, this is the Model part. -3. `service`: this module contains structs with business logic methods. - In MVC pattern, this is also the Model part. -4. `repository`: this module contains structs that serve as databases and methods to access the databases. - You can use methods of the struct to get list of objects, or operating an object (create, read, update, delete). - -This repository provides a basic functionality that makes BambangShop work: ability to create, read, and delete `Product`s. -This repository already contains a functioning `Product` model, repository, service, and controllers that you can try right away. - -As this is an Observer Design Pattern tutorial repository, you need to implement another feature: `Notification`. -This feature will notify creation, promotion, and deletion of a product, to external subscribers that are interested of a certain product type. -The subscribers are another Rocket instances, so the notification will be sent using HTTP POST request to each subscriber's `receive notification` address. - -## API Documentations - -You can download the Postman Collection JSON here: https://ristek.link/AdvProgWeek7Postman - -After you download the Postman Collection, you can try the endpoints inside "BambangShop Publisher" folder. -This Postman collection also contains endpoints that you need to implement later on (the `Notification` feature). - -Postman is an installable client that you can use to test web endpoints using HTTP request. -You can also make automated functional testing scripts for REST API projects using this client. -You can install Postman via this website: https://www.postman.com/downloads/ - -## How to Run in Development Environment -1. Set up environment variables first by creating `.env` file. - Here is the example of `.env` file: - ```bash - APP_INSTANCE_ROOT_URL="http://localhost:8000" - ``` - Here are the details of each environment variable: - | variable | type | description | - |-----------------------|--------|------------------------------------------------------------| - | APP_INSTANCE_ROOT_URL | string | URL address where this publisher instance can be accessed. | -2. Use `cargo run` to run this app. - (You might want to use `cargo check` if you only need to verify your work without running the app.) - -## Mandatory Checklists (Publisher) -- [ ] Clone https://gitlab.com/ichlaffterlalu/bambangshop to a new repository. -- **STAGE 1: Implement models and repositories** - - [ ] Commit: `Create Subscriber model struct.` - - [ ] Commit: `Create Notification model struct.` - - [ ] Commit: `Create Subscriber database and Subscriber repository struct skeleton.` - - [ ] Commit: `Implement add function in Subscriber repository.` - - [ ] Commit: `Implement list_all function in Subscriber repository.` - - [ ] Commit: `Implement delete function in Subscriber repository.` - - [ ] Write answers of your learning module's "Reflection Publisher-1" questions in this README. -- **STAGE 2: Implement services and controllers** - - [ ] Commit: `Create Notification service struct skeleton.` - - [ ] Commit: `Implement subscribe function in Notification service.` - - [ ] Commit: `Implement subscribe function in Notification controller.` - - [ ] Commit: `Implement unsubscribe function in Notification service.` - - [ ] Commit: `Implement unsubscribe function in Notification controller.` - - [ ] Write answers of your learning module's "Reflection Publisher-2" questions in this README. -- **STAGE 3: Implement notification mechanism** - - [ ] Commit: `Implement update method in Subscriber model to send notification HTTP requests.` - - [ ] Commit: `Implement notify function in Notification service to notify each Subscriber.` - - [ ] Commit: `Implement publish function in Program service and Program controller.` - - [ ] Commit: `Edit Product service methods to call notify after create/delete.` - - [ ] Write answers of your learning module's "Reflection Publisher-3" questions in this README. - -## Your Reflections -This is the place for you to write reflections: - -### Mandatory (Publisher) Reflections - -#### Reflection Publisher-1 - -#### Reflection Publisher-2 - -#### Reflection Publisher-3 +## 3. When programming using Rust, we are enforced by rigorous compiler constraints to make a thread-safe program. In the case of the List of Subscribers (SUBSCRIBERS) static variable, we used the DashMap external library for thread safe HashMap. Explain based on your understanding of design patterns, do we still need DashMap or we can implement Singleton pattern instead? +Kita tidak perlu menggunakan Singleton Pattern. Pada kasus ini, yang mana konkurensi diperhatikan, DashMap lebih baik dibanding dengan kita menggunakan Singleton Pattern. Hal ini karena DashMap sudah menyediakan thread safety tanpa memerlukan manual locking sehingga secara mudah memungkinkan thread untuk melakuakn r/w secara paralel dengan kompleksitas O(1). Sedangkan jika kita membuat Singleton dengan Mutex<HashMap>, setiap operasi r/w mengunci HashMap sehingga HashMap tidak dapat diakses thread lain ketika sedang dilakukan operasi. \ No newline at end of file -- GitLab