| | 1 | == Admin Manages Genres |
| | 2 | |
| | 3 | === Actor: **Admin** |
| | 4 | An admin adds a new genre to the platform or removes an existing one that is no longer needed. |
| | 5 | |
| | 6 | **1.** The admin navigates to the "Manage Genres" section in the admin dashboard. |
| | 7 | |
| | 8 | **2.** The system displays all existing genres and their usage counts. |
| | 9 | {{{#!sql |
| | 10 | SELECT g.genre_id, g.name, COUNT(hg.story_id) AS stories_using_genre |
| | 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 g.name ASC; |
| | 15 | }}} |
| | 16 | |
| | 17 | **3.** The admin selects "Add New Genre" and enters the genre name. |
| | 18 | |
| | 19 | **4.** The system checks if the genre already exists. |
| | 20 | {{{#!sql |
| | 21 | SELECT * FROM GENRE |
| | 22 | WHERE LOWER(name) = LOWER('Science Fiction'); |
| | 23 | }}} |
| | 24 | |
| | 25 | **5.** The genre does not exist, so the system inserts it. |
| | 26 | {{{#!sql |
| | 27 | INSERT INTO GENRE (name) |
| | 28 | VALUES ('Science Fiction'); |
| | 29 | }}} |
| | 30 | |
| | 31 | **6.** The admin also decides to delete an unused genre. |
| | 32 | |
| | 33 | **7.** The system checks if any stories are currently using that genre before deleting. |
| | 34 | {{{#!sql |
| | 35 | SELECT COUNT(*) AS usage_count |
| | 36 | FROM HAS_GENRE |
| | 37 | WHERE genre_id = 10; |
| | 38 | }}} |
| | 39 | |
| | 40 | **8.** Since no stories use it, the system deletes the genre. |
| | 41 | {{{#!sql |
| | 42 | DELETE FROM GENRE |
| | 43 | WHERE genre_id = 10; |
| | 44 | }}} |
| | 45 | |
| | 46 | **9.** The system confirms both changes and refreshes the genre list. |