diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-04-24 18:38:48 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-04-24 18:38:48 +0300 |
| commit | 9f8f895aebdb310508125cac153198d6f5b732c7 (patch) | |
| tree | d76ce39c9163d1dd36d8b9bcee7491c9eb7fcd77 /backend | |
| parent | feat: db transaction for record submission (#33) (diff) | |
| download | lphub-9f8f895aebdb310508125cac153198d6f5b732c7.tar.gz lphub-9f8f895aebdb310508125cac153198d6f5b732c7.tar.bz2 lphub-9f8f895aebdb310508125cac153198d6f5b732c7.zip | |
feat: change username to user_name
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/controllers/homeController.go | 6 | ||||
| -rw-r--r-- | backend/controllers/loginController.go | 2 | ||||
| -rw-r--r-- | backend/controllers/userController.go | 8 | ||||
| -rw-r--r-- | backend/database/init.sql | 2 | ||||
| -rw-r--r-- | backend/middleware/auth.go | 2 | ||||
| -rw-r--r-- | backend/models/models.go | 6 |
6 files changed, 13 insertions, 13 deletions
diff --git a/backend/controllers/homeController.go b/backend/controllers/homeController.go index 539d2c4..577f61a 100644 --- a/backend/controllers/homeController.go +++ b/backend/controllers/homeController.go | |||
| @@ -29,7 +29,7 @@ func Home(c *gin.Context) { | |||
| 29 | // @Failure 400 {object} models.Response | 29 | // @Failure 400 {object} models.Response |
| 30 | // @Router /demo [get] | 30 | // @Router /demo [get] |
| 31 | func Rankings(c *gin.Context) { | 31 | func Rankings(c *gin.Context) { |
| 32 | rows, err := database.DB.Query(`SELECT steam_id, username FROM users;`) | 32 | rows, err := database.DB.Query(`SELECT steam_id, user_name FROM users;`) |
| 33 | if err != nil { | 33 | if err != nil { |
| 34 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 34 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 35 | return | 35 | return |
| @@ -56,7 +56,7 @@ func Rankings(c *gin.Context) { | |||
| 56 | if uniqueSingleUserRecords == totalSingleMaps { | 56 | if uniqueSingleUserRecords == totalSingleMaps { |
| 57 | var ranking models.UserRanking | 57 | var ranking models.UserRanking |
| 58 | ranking.UserID = userID | 58 | ranking.UserID = userID |
| 59 | ranking.Username = username | 59 | ranking.UserName = username |
| 60 | sql := `SELECT DISTINCT map_id, score_count FROM records_sp WHERE user_id = $1 ORDER BY map_id, score_count;` | 60 | sql := `SELECT DISTINCT map_id, score_count FROM records_sp WHERE user_id = $1 ORDER BY map_id, score_count;` |
| 61 | rows, err := database.DB.Query(sql, userID) | 61 | rows, err := database.DB.Query(sql, userID) |
| 62 | if err != nil { | 62 | if err != nil { |
| @@ -90,7 +90,7 @@ func Rankings(c *gin.Context) { | |||
| 90 | if uniqueMultiUserRecords == totalMultiMaps { | 90 | if uniqueMultiUserRecords == totalMultiMaps { |
| 91 | var ranking models.UserRanking | 91 | var ranking models.UserRanking |
| 92 | ranking.UserID = userID | 92 | ranking.UserID = userID |
| 93 | ranking.Username = username | 93 | ranking.UserName = username |
| 94 | sql := `SELECT DISTINCT map_id, score_count FROM records_mp WHERE host_id = $1 OR partner_id = $2 ORDER BY map_id, score_count;` | 94 | sql := `SELECT DISTINCT map_id, score_count FROM records_mp WHERE host_id = $1 OR partner_id = $2 ORDER BY map_id, score_count;` |
| 95 | rows, err := database.DB.Query(sql, userID, userID) | 95 | rows, err := database.DB.Query(sql, userID, userID) |
| 96 | if err != nil { | 96 | if err != nil { |
diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go index 6c0453b..4de4c00 100644 --- a/backend/controllers/loginController.go +++ b/backend/controllers/loginController.go | |||
| @@ -56,7 +56,7 @@ func Login(c *gin.Context) { | |||
| 56 | user.LocCountryCode = "XX" | 56 | user.LocCountryCode = "XX" |
| 57 | } | 57 | } |
| 58 | // Insert new user to database | 58 | // Insert new user to database |
| 59 | database.DB.Exec(`INSERT INTO users (steam_id, username, avatar_link, country_code) | 59 | database.DB.Exec(`INSERT INTO users (steam_id, user_name, avatar_link, country_code) |
| 60 | VALUES ($1, $2, $3, $4)`, steamID, user.PersonaName, user.AvatarFull, user.LocCountryCode) | 60 | VALUES ($1, $2, $3, $4)`, steamID, user.PersonaName, user.AvatarFull, user.LocCountryCode) |
| 61 | } | 61 | } |
| 62 | // Generate JWT token | 62 | // Generate JWT token |
diff --git a/backend/controllers/userController.go b/backend/controllers/userController.go index dcae2ed..5ad800d 100644 --- a/backend/controllers/userController.go +++ b/backend/controllers/userController.go | |||
| @@ -88,7 +88,7 @@ func Profile(c *gin.Context) { | |||
| 88 | Data: models.ProfileResponse{ | 88 | Data: models.ProfileResponse{ |
| 89 | Profile: true, | 89 | Profile: true, |
| 90 | SteamID: user.(models.User).SteamID, | 90 | SteamID: user.(models.User).SteamID, |
| 91 | Username: user.(models.User).Username, | 91 | UserName: user.(models.User).UserName, |
| 92 | AvatarLink: user.(models.User).AvatarLink, | 92 | AvatarLink: user.(models.User).AvatarLink, |
| 93 | CountryCode: user.(models.User).CountryCode, | 93 | CountryCode: user.(models.User).CountryCode, |
| 94 | ScoresSP: scoresSP, | 94 | ScoresSP: scoresSP, |
| @@ -120,7 +120,7 @@ func FetchUser(c *gin.Context) { | |||
| 120 | // Check if user exists | 120 | // Check if user exists |
| 121 | var user models.User | 121 | var user models.User |
| 122 | err := database.DB.QueryRow(`SELECT * FROM users WHERE steam_id = $1;`, id).Scan( | 122 | err := database.DB.QueryRow(`SELECT * FROM users WHERE steam_id = $1;`, id).Scan( |
| 123 | &user.SteamID, &user.Username, &user.AvatarLink, &user.CountryCode, | 123 | &user.SteamID, &user.UserName, &user.AvatarLink, &user.CountryCode, |
| 124 | &user.CreatedAt, &user.UpdatedAt) | 124 | &user.CreatedAt, &user.UpdatedAt) |
| 125 | if user.SteamID == "" { | 125 | if user.SteamID == "" { |
| 126 | // User does not exist | 126 | // User does not exist |
| @@ -190,7 +190,7 @@ func FetchUser(c *gin.Context) { | |||
| 190 | Data: models.ProfileResponse{ | 190 | Data: models.ProfileResponse{ |
| 191 | Profile: true, | 191 | Profile: true, |
| 192 | SteamID: user.SteamID, | 192 | SteamID: user.SteamID, |
| 193 | Username: user.Username, | 193 | UserName: user.UserName, |
| 194 | AvatarLink: user.AvatarLink, | 194 | AvatarLink: user.AvatarLink, |
| 195 | CountryCode: user.CountryCode, | 195 | CountryCode: user.CountryCode, |
| 196 | ScoresSP: scoresSP, | 196 | ScoresSP: scoresSP, |
| @@ -236,7 +236,7 @@ func UpdateUser(c *gin.Context) { | |||
| 236 | Data: models.ProfileResponse{ | 236 | Data: models.ProfileResponse{ |
| 237 | Profile: true, | 237 | Profile: true, |
| 238 | SteamID: user.(models.User).SteamID, | 238 | SteamID: user.(models.User).SteamID, |
| 239 | Username: profile.PersonaName, | 239 | UserName: profile.PersonaName, |
| 240 | AvatarLink: profile.AvatarFull, | 240 | AvatarLink: profile.AvatarFull, |
| 241 | CountryCode: profile.LocCountryCode, | 241 | CountryCode: profile.LocCountryCode, |
| 242 | }, | 242 | }, |
diff --git a/backend/database/init.sql b/backend/database/init.sql index 53c9262..81461c2 100644 --- a/backend/database/init.sql +++ b/backend/database/init.sql | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | CREATE TABLE users ( | 1 | CREATE TABLE users ( |
| 2 | steam_id TEXT, | 2 | steam_id TEXT, |
| 3 | username TEXT NOT NULL, | 3 | user_name TEXT NOT NULL, |
| 4 | avatar_link TEXT NOT NULL, | 4 | avatar_link TEXT NOT NULL, |
| 5 | country_code CHAR(2) NOT NULL, | 5 | country_code CHAR(2) NOT NULL, |
| 6 | created_at TIMESTAMP NOT NULL DEFAULT now(), | 6 | created_at TIMESTAMP NOT NULL DEFAULT now(), |
diff --git a/backend/middleware/auth.go b/backend/middleware/auth.go index b5ad762..cd00a30 100644 --- a/backend/middleware/auth.go +++ b/backend/middleware/auth.go | |||
| @@ -37,7 +37,7 @@ func CheckAuth(c *gin.Context) { | |||
| 37 | // Get user from DB | 37 | // Get user from DB |
| 38 | var user models.User | 38 | var user models.User |
| 39 | database.DB.QueryRow(`SELECT * FROM users WHERE steam_id = $1;`, claims["sub"]).Scan( | 39 | database.DB.QueryRow(`SELECT * FROM users WHERE steam_id = $1;`, claims["sub"]).Scan( |
| 40 | &user.SteamID, &user.Username, &user.AvatarLink, | 40 | &user.SteamID, &user.UserName, &user.AvatarLink, |
| 41 | &user.CountryCode, &user.CreatedAt, &user.UpdatedAt) | 41 | &user.CountryCode, &user.CreatedAt, &user.UpdatedAt) |
| 42 | if user.SteamID == "" { | 42 | if user.SteamID == "" { |
| 43 | c.Next() | 43 | c.Next() |
diff --git a/backend/models/models.go b/backend/models/models.go index b9ea9f0..3b1c58d 100644 --- a/backend/models/models.go +++ b/backend/models/models.go | |||
| @@ -16,7 +16,7 @@ type LoginResponse struct { | |||
| 16 | 16 | ||
| 17 | type User struct { | 17 | type User struct { |
| 18 | SteamID string `json:"steam_id"` | 18 | SteamID string `json:"steam_id"` |
| 19 | Username string `json:"username"` | 19 | UserName string `json:"user_name"` |
| 20 | AvatarLink string `json:"avatar_link"` | 20 | AvatarLink string `json:"avatar_link"` |
| 21 | CountryCode string `json:"country_code"` | 21 | CountryCode string `json:"country_code"` |
| 22 | CreatedAt time.Time `json:"created_at"` | 22 | CreatedAt time.Time `json:"created_at"` |
| @@ -88,7 +88,7 @@ type RecordRequest struct { | |||
| 88 | 88 | ||
| 89 | type UserRanking struct { | 89 | type UserRanking struct { |
| 90 | UserID string `json:"user_id"` | 90 | UserID string `json:"user_id"` |
| 91 | Username string `json:"username"` | 91 | UserName string `json:"user_name"` |
| 92 | TotalScore int `json:"total_score"` | 92 | TotalScore int `json:"total_score"` |
| 93 | } | 93 | } |
| 94 | 94 | ||
| @@ -100,7 +100,7 @@ type RankingsResponse struct { | |||
| 100 | type ProfileResponse struct { | 100 | type ProfileResponse struct { |
| 101 | Profile bool `json:"profile"` | 101 | Profile bool `json:"profile"` |
| 102 | SteamID string `json:"steam_id"` | 102 | SteamID string `json:"steam_id"` |
| 103 | Username string `json:"username"` | 103 | UserName string `json:"user_name"` |
| 104 | AvatarLink string `json:"avatar_link"` | 104 | AvatarLink string `json:"avatar_link"` |
| 105 | CountryCode string `json:"country_code"` | 105 | CountryCode string `json:"country_code"` |
| 106 | ScoresSP []ScoreResponse `json:"scores_sp"` | 106 | ScoresSP []ScoreResponse `json:"scores_sp"` |