| | 1 | == User Views Story Details and Chapters |
| | 2 | |
| | 3 | === Actor: **Guest User / Regular User / Writer** |
| | 4 | A user opens a published story to view its full details, genres, and list of available chapters before starting to read. |
| | 5 | |
| | 6 | **1.** The user clicks on a story from the browse page or reading list. |
| | 7 | |
| | 8 | **2.** The system retrieves the full story details. |
| | 9 | {{{#!sql |
| | 10 | SELECT s.story_id, s.short_description, s.content, s.mature_content, |
| | 11 | s.image, s.created_at, u.username AS author, |
| | 12 | st.status |
| | 13 | FROM STORY s |
| | 14 | JOIN USERS u ON s.user_id = u.user_id |
| | 15 | JOIN STATUS st ON s.story_id = st.story_id |
| | 16 | WHERE s.story_id = 1 AND st.status = 'published'; |
| | 17 | }}} |
| | 18 | |
| | 19 | **3.** The system retrieves all genres assigned to the story. |
| | 20 | {{{#!sql |
| | 21 | SELECT g.name |
| | 22 | FROM GENRE g |
| | 23 | JOIN HAS_GENRE hg ON g.genre_id = hg.genre_id |
| | 24 | WHERE hg.story_id = 1; |
| | 25 | }}} |
| | 26 | |
| | 27 | **4.** The system retrieves all chapters of the story ordered by chapter number. |
| | 28 | {{{#!sql |
| | 29 | SELECT chapter_id, chapter_number, chapter_name, title, |
| | 30 | word_count, rating, published_at, view_count |
| | 31 | FROM CHAPTER |
| | 32 | WHERE story_id = 1 |
| | 33 | ORDER BY chapter_number ASC; |
| | 34 | }}} |
| | 35 | |
| | 36 | **5.** The system displays the story page with all details, genres, like and comment counts, and the chapter list. |
| | 37 | {{{#!sql |
| | 38 | SELECT COUNT(DISTINCT l.user_id) AS total_likes, |
| | 39 | COUNT(DISTINCT c.comment_id) AS total_comments |
| | 40 | FROM STORY s |
| | 41 | LEFT JOIN LIKES l ON s.story_id = l.story_id |
| | 42 | LEFT JOIN COMMENT c ON s.story_id = c.story_id |
| | 43 | WHERE s.story_id = 1 |
| | 44 | GROUP BY s.story_id; |
| | 45 | }}} |
| | 46 | |
| | 47 | **6.** The user selects a chapter to start reading. |