| | 1 | == Guest/User Browses Stories by Genre |
| | 2 | |
| | 3 | === Actor: **Regular User / Guest User** |
| | 4 | A user browses the platform filtering published stories by a specific genre to discover new content. |
| | 5 | |
| | 6 | **1.** The user navigates to the "Browse by Genre" section of the platform. |
| | 7 | |
| | 8 | **2.** The system retrieves and displays all available genres. |
| | 9 | {{{#!sql |
| | 10 | SELECT g.genre_id, g.name, COUNT(hg.story_id) AS total_stories |
| | 11 | FROM GENRE g |
| | 12 | LEFT JOIN HAS_GENRE hg ON g.genre_id = hg.genre_id |
| | 13 | GROUP BY g.genre_id |
| | 14 | ORDER BY total_stories DESC; |
| | 15 | }}} |
| | 16 | |
| | 17 | **3.** The user selects a genre, for example "Fantasy". |
| | 18 | |
| | 19 | **4.** The system retrieves all published stories that belong to that genre. |
| | 20 | {{{#!sql |
| | 21 | SELECT s.story_id, s.short_description, s.mature_content, s.image, |
| | 22 | u.username AS author, |
| | 23 | COUNT(DISTINCT l.user_id) AS total_likes, |
| | 24 | COUNT(DISTINCT c.comment_id) AS total_comments |
| | 25 | FROM STORY s |
| | 26 | JOIN HAS_GENRE hg ON s.story_id = hg.story_id |
| | 27 | JOIN GENRE g ON hg.genre_id = g.genre_id |
| | 28 | JOIN USERS u ON s.user_id = u.user_id |
| | 29 | JOIN STATUS st ON s.story_id = st.story_id |
| | 30 | LEFT JOIN LIKES l ON s.story_id = l.story_id |
| | 31 | LEFT JOIN COMMENT c ON s.story_id = c.story_id |
| | 32 | WHERE g.name = 'Fantasy' AND st.status = 'published' |
| | 33 | GROUP BY s.story_id, u.username |
| | 34 | ORDER BY total_likes DESC; |
| | 35 | }}} |
| | 36 | |
| | 37 | **5.** The system displays the filtered list of stories with their cover image, author, likes, and comment count. |
| | 38 | |
| | 39 | **6.** The user clicks on a story to view its details. |