From 3ad53aeeffec00f85bf1f3168d0e9d61c65eecb7 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 10 Jul 2023 16:06:29 +0300 Subject: feat: is_coop field on games Former-commit-id: bf3a5a262557ade646ce8e59db152be8c521ac06 --- backend/controllers/mapController.go | 4 ++-- backend/database/games.sql | 6 +++--- backend/database/init.sql | 1 + backend/models/models.go | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) (limited to 'backend') diff --git a/backend/controllers/mapController.go b/backend/controllers/mapController.go index 52b6623..11e56f6 100644 --- a/backend/controllers/mapController.go +++ b/backend/controllers/mapController.go @@ -193,7 +193,7 @@ func FetchMapLeaderboards(c *gin.Context) { // @Failure 400 {object} models.Response // @Router /games [get] func FetchGames(c *gin.Context) { - rows, err := database.DB.Query(`SELECT id, name FROM games`) + rows, err := database.DB.Query(`SELECT id, name, is_coop FROM games`) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return @@ -201,7 +201,7 @@ func FetchGames(c *gin.Context) { var games []models.Game for rows.Next() { var game models.Game - if err := rows.Scan(&game.ID, &game.Name); err != nil { + if err := rows.Scan(&game.ID, &game.Name, &game.IsCoop); err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } diff --git a/backend/database/games.sql b/backend/database/games.sql index 5e2f4ee..0c2374c 100644 --- a/backend/database/games.sql +++ b/backend/database/games.sql @@ -1,3 +1,3 @@ -INSERT INTO games(id, name) VALUES -(1, 'Portal 2 - Singleplayer'), -(2, 'Portal 2 - Cooperative'); \ No newline at end of file +INSERT INTO games(id, name, is_coop) VALUES +(1, 'Portal 2 - Singleplayer', false), +(2, 'Portal 2 - Cooperative', true); \ No newline at end of file diff --git a/backend/database/init.sql b/backend/database/init.sql index 76c3aa6..c7d098c 100644 --- a/backend/database/init.sql +++ b/backend/database/init.sql @@ -11,6 +11,7 @@ CREATE TABLE users ( CREATE TABLE games ( id SMALLSERIAL, name TEXT NOT NULL, + is_coop BOOLEAN NOT NULL, PRIMARY KEY (id) ); diff --git a/backend/models/models.go b/backend/models/models.go index 2524935..e63ff91 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -62,8 +62,9 @@ type UserRanking struct { } type Game struct { - ID int `json:"id"` - Name string `json:"name"` + ID int `json:"id"` + Name string `json:"name"` + IsCoop bool `json:"is_coop"` } type Chapter struct { -- cgit v1.2.3