| | 1 | == User Reads a Chapter |
| | 2 | |
| | 3 | === Actor: **Guest User / Regular User / Writer** |
| | 4 | A user opens and reads a specific chapter of a story, and the system records the view count for that chapter. |
| | 5 | **1.** The user selects a chapter from the story page. |
| | 6 | |
| | 7 | **2.** The system retrieves the full chapter content. |
| | 8 | {{{#!sql |
| | 9 | SELECT chapter_id, chapter_number, chapter_name, title, |
| | 10 | content, word_count, rating, published_at, view_count |
| | 11 | FROM CHAPTER |
| | 12 | WHERE chapter_id = 1 AND story_id = 1; |
| | 13 | }}} |
| | 14 | |
| | 15 | **3.** The system increments the view count for that chapter. |
| | 16 | {{{#!sql |
| | 17 | UPDATE CHAPTER |
| | 18 | SET view_count = view_count + 1, |
| | 19 | updated_at = CURRENT_TIMESTAMP |
| | 20 | WHERE chapter_id = 1; |
| | 21 | }}} |
| | 22 | |
| | 23 | **4.** The system displays navigation buttons to the previous and next chapters. |
| | 24 | {{{#!sql |
| | 25 | SELECT chapter_id, chapter_number, title |
| | 26 | FROM CHAPTER |
| | 27 | WHERE story_id = 1 |
| | 28 | AND chapter_number IN ( |
| | 29 | (SELECT chapter_number - 1 FROM CHAPTER WHERE chapter_id = 1), |
| | 30 | (SELECT chapter_number + 1 FROM CHAPTER WHERE chapter_id = 1) |
| | 31 | ) |
| | 32 | ORDER BY chapter_number ASC; |
| | 33 | }}} |
| | 34 | |
| | 35 | **5.**The user finishes reading and navigates to the next chapter. |