Commit b2e05ed
authored
[Feature] Add advertisement click functionality to ads-java service (#112)
This pull request introduces changes to the ad management system,
including backend enhancements for handling ad clicks, frontend updates
for improved ad display and interactivity, and the addition of ad pages
for "Cool Hats", "Discount Clothing", and "Nice Bags". Below is a
summary of the most important changes:
### Backend Enhancements for Ad Management:
* Added a new `clickUrl` field to the `Advertisement` entity and updated
the `Advertisement` class to include a new constructor and getter/setter
methods for this field. This allows ads to have specific URLs for
redirection.
[[1]](diffhunk://#diff-983021bedc2f12a394677367bd55d4d052dc282657421cccb78303d8a8ceebe8R12)
[[2]](diffhunk://#diff-983021bedc2f12a394677367bd55d4d052dc282657421cccb78303d8a8ceebe8R21-R34)
* Implemented a new `/click/{id}` endpoint in the `AdsJavaApplication`
class to handle ad clicks. This endpoint logs the click, retrieves the
ad by its ID, and redirects the user to the associated `clickUrl` or a
default URL if none is set.
* Enhanced the database initialization logic to include meaningful
`clickUrl` values for ads and ensure existing ads are updated with the
correct URLs.
### Frontend Updates for Ad Interactivity:
* Updated the `Ad` component in `Ad.tsx` to include a `handleAdClick`
function that redirects users to the backend click endpoint when an ad
is clicked. The ad banner now includes a `cursor-pointer` style and a
`title` attribute for better user experience.
[[1]](diffhunk://#diff-a8bb7ae2ac5ae758f047db6aaf17c2826457375226c6387413b27a1a6f26e358R49-R56)
[[2]](diffhunk://#diff-a8bb7ae2ac5ae758f047db6aaf17c2826457375226c6387413b27a1a6f26e358L64-R86)
* Refactored the `Ad` component to use a proper TypeScript interface
(`Advertisement`) for better type safety and clarity.
* Added pages for "Cool Hats", "Discount Clothing", and "Nice Bags".
## How to test
1. Checkout this branch.
2. Run `docker compose -f docker-compose.dev.yml up -d`
3. Navigate to `http://localhost` and click on the ads to ensure all
three ads work as expectedFile tree
8 files changed
+523
-23
lines changed- services
- ads/java/src/main/java/adsjava
- backend
- frontend
- components/common/Ad
- pages
8 files changed
+523
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
Lines changed: 113 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| |||
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 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 | + | |
53 | 79 | | |
54 | 80 | | |
55 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
56 | 113 | | |
57 | 114 | | |
58 | 115 | | |
| |||
95 | 152 | | |
96 | 153 | | |
97 | 154 | | |
98 | | - | |
99 | | - | |
100 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
101 | 205 | | |
102 | 206 | | |
103 | 207 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
25 | 32 | | |
| 33 | + | |
| 34 | + | |
26 | 35 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
252 | 255 | | |
253 | 256 | | |
254 | 257 | | |
| |||
301 | 304 | | |
302 | 305 | | |
303 | 306 | | |
| 307 | + | |
304 | 308 | | |
| 309 | + | |
| 310 | + | |
305 | 311 | | |
306 | 312 | | |
307 | 313 | | |
| |||
341 | 347 | | |
342 | 348 | | |
343 | 349 | | |
| 350 | + | |
| 351 | + | |
344 | 352 | | |
345 | 353 | | |
346 | 354 | | |
| |||
498 | 506 | | |
499 | 507 | | |
500 | 508 | | |
501 | | - | |
502 | | - | |
503 | 509 | | |
504 | 510 | | |
505 | 511 | | |
| |||
683 | 689 | | |
684 | 690 | | |
685 | 691 | | |
| 692 | + | |
686 | 693 | | |
687 | 694 | | |
688 | 695 | | |
| |||
714 | 721 | | |
715 | 722 | | |
716 | 723 | | |
717 | | - | |
718 | 724 | | |
719 | 725 | | |
720 | 726 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
| 10 | + | |
8 | 11 | | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | | - | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
30 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
38 | 51 | | |
39 | 52 | | |
40 | 53 | | |
41 | 54 | | |
42 | 55 | | |
43 | 56 | | |
44 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
45 | 73 | | |
46 | 74 | | |
47 | 75 | | |
| |||
61 | 89 | | |
62 | 90 | | |
63 | 91 | | |
64 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
65 | 97 | | |
66 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
67 | 103 | | |
68 | 104 | | |
69 | 105 | | |
| |||
0 commit comments