| | 1 | == Regular User Likes a Story |
| | 2 | |
| | 3 | === Authors: **Regular User** |
| | 4 | A regular user likes a published story on the platform, and the writer receives a notification about it. |
| | 5 | |
| | 6 | **1.** The regular user browses the platform and opens a published story. |
| | 7 | |
| | 8 | **2.** The system displays the story details along with the current like count. |
| | 9 | {{{#!sql |
| | 10 | SELECT s.story_id, s.short_description, COUNT(l.user_id) AS total_likes |
| | 11 | FROM STORY s |
| | 12 | LEFT JOIN LIKES l ON s.story_id = l.story_id |
| | 13 | WHERE s.story_id = 1 |
| | 14 | GROUP BY s.story_id; |
| | 15 | }}} |
| | 16 | |
| | 17 | **3.** The user clicks the "Like" button on the story. |
| | 18 | |
| | 19 | **4.** The system checks if the user has already liked the story to prevent duplicates. |
| | 20 | {{{#!sql |
| | 21 | SELECT * FROM LIKES |
| | 22 | WHERE user_id = 4 AND story_id = 1; |
| | 23 | }}} |
| | 24 | |
| | 25 | **5.** The system inserts a new like record. |
| | 26 | {{{#!sql |
| | 27 | INSERT INTO LIKES (user_id, story_id, created_at) |
| | 28 | VALUES (4, 1, CURRENT_TIMESTAMP); |
| | 29 | }}} |
| | 30 | |
| | 31 | **6.** The system creates a notification for the writer. |
| | 32 | {{{#!sql |
| | 33 | INSERT INTO NOTIFICATION (content, is_read, created_at) |
| | 34 | VALUES ('Sara liked your story "The Chronicles of Eldoria"', FALSE, CURRENT_TIMESTAMP); |
| | 35 | }}} |
| | 36 | |
| | 37 | **7.** The system creates a notification for the writer. |
| | 38 | {{{#!sql |
| | 39 | INSERT INTO CONTENT_TYPE (notification_id, content_type) |
| | 40 | VALUES (1, 'like'); |
| | 41 | }}} |
| | 42 | |
| | 43 | **8.** The system creates a notification for the writer. |
| | 44 | {{{#!sql |
| | 45 | INSERT INTO NOTIFY (user_id, story_id, notification_id) |
| | 46 | VALUES (2, 1, 1); |
| | 47 | }}} |
| | 48 | |
| | 49 | **9.** The system updates the like count displayed on the story page. |