From 83963bd8a7ee906b93e24afea53516bc7f19afd1 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Tue, 10 Oct 2023 19:16:06 +0300 Subject: feat: add is_disabled to chapters itself (#112) Former-commit-id: 86a6b1564e835d6c637144bf313a9cdec2fc4207 --- backend/database/chapters.sql | 34 +++++++++++++++++----------------- backend/database/init.sql | 1 + backend/handlers/map.go | 4 ++-- backend/models/models.go | 5 +++-- 4 files changed, 23 insertions(+), 21 deletions(-) (limited to 'backend') diff --git a/backend/database/chapters.sql b/backend/database/chapters.sql index 9538bed..f61d5bf 100644 --- a/backend/database/chapters.sql +++ b/backend/database/chapters.sql @@ -1,17 +1,17 @@ -INSERT INTO chapters(id, game_id, name) VALUES -(1, 1, 'Chapter 1 - The Coutesy Call'), -(2, 1, 'Chapter 2 - The Cold Boot'), -(3, 1, 'Chapter 3 - The Return'), -(4, 1, 'Chapter 4 - The Surprise'), -(5, 1, 'Chapter 5 - The Escape'), -(6, 1, 'Chapter 6 - The Fall'), -(7, 1, 'Chapter 7 - The Reunion'), -(8, 1, 'Chapter 8 - The Itch'), -(9, 1, 'Chapter 9 - The Part Where He Kills You'), -(10, 2, 'Course 0 - Introduction'), -(11, 2, 'Course 1 - Team Building'), -(12, 2, 'Course 2 - Mass And Velocity'), -(13, 2, 'Course 3 - Hard-Light Surfaces'), -(14, 2, 'Course 4 - Excursion Funnels'), -(15, 2, 'Course 5 - Mobility Gels'), -(16, 2, 'Course 6 - Art Therapy'); \ No newline at end of file +INSERT INTO chapters(id, game_id, name, is_disabled) VALUES +(1, 1, 'Chapter 1 - The Coutesy Call', false), +(2, 1, 'Chapter 2 - The Cold Boot', false), +(3, 1, 'Chapter 3 - The Return', false), +(4, 1, 'Chapter 4 - The Surprise', false), +(5, 1, 'Chapter 5 - The Escape', false), +(6, 1, 'Chapter 6 - The Fall', false), +(7, 1, 'Chapter 7 - The Reunion', false), +(8, 1, 'Chapter 8 - The Itch', false), +(9, 1, 'Chapter 9 - The Part Where He Kills You', false), +(10, 2, 'Course 0 - Introduction', true), +(11, 2, 'Course 1 - Team Building', false), +(12, 2, 'Course 2 - Mass And Velocity', false), +(13, 2, 'Course 3 - Hard-Light Surfaces', false), +(14, 2, 'Course 4 - Excursion Funnels', false), +(15, 2, 'Course 5 - Mobility Gels', false), +(16, 2, 'Course 6 - Art Therapy', false); \ No newline at end of file diff --git a/backend/database/init.sql b/backend/database/init.sql index 17a0ce5..9851ad7 100644 --- a/backend/database/init.sql +++ b/backend/database/init.sql @@ -23,6 +23,7 @@ CREATE TABLE chapters ( id SERIAL, game_id SMALLINT NOT NULL, name TEXT NOT NULL, + is_disabled BOOLEAN NOT NULL DEFAULT false, PRIMARY KEY (id), FOREIGN KEY (game_id) REFERENCES games(id) ); diff --git a/backend/handlers/map.go b/backend/handlers/map.go index d8f2ff0..8b8b9d7 100644 --- a/backend/handlers/map.go +++ b/backend/handlers/map.go @@ -365,7 +365,7 @@ func FetchChapters(c *gin.Context) { return } var response ChaptersResponse - rows, err := database.DB.Query(`SELECT c.id, c.name, g.name FROM chapters c INNER JOIN games g ON c.game_id = g.id WHERE game_id = $1`, gameID) + rows, err := database.DB.Query(`SELECT c.id, c.name, g.name, c.is_disabled FROM chapters c INNER JOIN games g ON c.game_id = g.id WHERE game_id = $1`, gameID) if err != nil { c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return @@ -374,7 +374,7 @@ func FetchChapters(c *gin.Context) { var gameName string for rows.Next() { var chapter models.Chapter - if err := rows.Scan(&chapter.ID, &chapter.Name, &gameName); err != nil { + if err := rows.Scan(&chapter.ID, &chapter.Name, &gameName, &chapter.IsDisabled); err != nil { c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } diff --git a/backend/models/models.go b/backend/models/models.go index c380a89..3aa2e9c 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -92,8 +92,9 @@ type Game struct { } type Chapter struct { - ID int `json:"id"` - Name string `json:"name"` + ID int `json:"id"` + Name string `json:"name"` + IsDisabled bool `json:"is_disabled"` } type Category struct { -- cgit v1.2.3