1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101# ๐ฌ Newsletter Subscription App โ Storyblok
This is a web application that allows users to subscribe to newsletters that are focussed on different topics. The web app has two pages which are:
1. [Subscription Page](http://localhost:5173/subscription) which allows users to fill a subscription form with basic personal details and select newsletter categories
2. [Subscription List Page](http://localhost:5173/subscription/list) which allows users to view all submitted subscriptions and filter subscriptions by category
---
## ๐๏ธ Basic Repository Folder Structure
```bash
story-blok-newsletter-subscription-application/
โโโ api/
โ โโโ app/
โ โ โโโ controllers/
โ โ โ โโโ v1/
โ โ โ โโโ categories_controller.rb
โ โ โ โโโ subscriptions_controller.rb
โ โ โโโ models/
โ โ โ โโโ category.rb
โ โ โ โโโ customer.rb
โ โ โ โโโ subscription.rb
โ โ โโโ services/
โ โ โ โโโ category_service.rb
โ โ โ โโโ subscription_service.rb
โ โโโ spec/
โ โ โโโ controllers/
โ โ โโโ models/
โ โ โโโ services/
โ โ โโโ factories/
โ โโโ Dockerfile
โ โโโ docker-compose.yml
โ
โโโ frontend/
โ โโโ src/
โ โ โโโ main.ts
โ โ โโโ pages/
โ โ โ โโโ subscription/
โ โ โ โโโ components/
โ โ โ โ โโโ SubscriptionForm.vue
โ โ โ โ โโโ SubscriptionList.vue
โ โ โ โโโ service/
โ โ โ โ โโโ category.ts
โ โ โ โ โโโ subscription.ts
โ โ โ โโโ helpers/
โ โ โ โ โโโ constants.ts
โ โ โ โ โโโ validation.ts
โ โ โ โโโ types/
โ โโโ __tests__/
โ โโโ SubscriptionForm.test.ts
โ โโโ SubscriptionList.test.ts
โ โโโ utils/
โ โโโ categories-mock-data.ts
โ โโโ subscription-list-mock-data.ts
โ โโโ utils.ts
โ
โโโ README.md
```
---
## ๐ Getting Started
### Prerequisites
- Docker. You must have either [docker desktop](https://www.docker.com/products/docker-desktop) or [orb stack](https://orbstack.dev/) (recommended) installed. Note that orb stack only works on mac and linux.
- Node.js greater than or equal to v20.10.0
### โ๏ธ Setup
- Navigate to the root directory of the api folder.
- Run `docker compose build --no-cache` to build the containers.
- Run `docker compose run --rm api bundle install` to install the gem packages.
- Run `docker compose run --rm api rails db:migrate` to migrate the database.
- Run `docker compose up api -d` to start the containers.
- Launch http://localhost:3000 on your browser to confirm that the API server is running.
- Navigate to the root directory of the frontend folder.
- Run `npm install` to install dependencies.
- Run `npm run dev` to start the development server.
- Launch http://localhost:5173/subscription on your browser to confirm that the frontend server is running.
- The create subscription page url is http://localhost:5173/subscription, while the subscription list page url is http://localhost:5173/subscription/list
---
## ๐งช Running Tests
### Backend Tests
- Navigate to the root directory of the api folder.
- Run `docker compose up test` to run the tests.
### Frontend Tests
- Navigate to the root directory of the frontend folder.
- Run `npm run test` to run the tests.
---
## ๐ง Things to Improve
Here is a list of things that I would like to improve but couldn't due to time constraints:
- Add end to end tests with `Cypress`
- Add caching for the categories to prevent frequent database queries as that dataset would not change often
- Use a proper localization tool that can automatically manage translations
- Add visual feedback for loading and success/failure states
- Improve the UI rendering for the categories a customer has subscribed to on the subscription list page
- Use toasts or a proper notification library instead of using `alert()`
- Add a proper UI for visual feedback when there was an error fetching categories on the subscription and subscription list pages
- Add a not found page for visual feedback when a route that does not exist is accessed
---