From 9f8f895aebdb310508125cac153198d6f5b732c7 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 24 Apr 2023 18:38:48 +0300 Subject: feat: change username to user_name --- backend/controllers/homeController.go | 6 +++--- backend/controllers/loginController.go | 2 +- backend/controllers/userController.go | 8 ++++---- backend/database/init.sql | 2 +- backend/middleware/auth.go | 2 +- backend/models/models.go | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) (limited to 'backend') 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) { // @Failure 400 {object} models.Response // @Router /demo [get] func Rankings(c *gin.Context) { - rows, err := database.DB.Query(`SELECT steam_id, username FROM users;`) + rows, err := database.DB.Query(`SELECT steam_id, user_name FROM users;`) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return @@ -56,7 +56,7 @@ func Rankings(c *gin.Context) { if uniqueSingleUserRecords == totalSingleMaps { var ranking models.UserRanking ranking.UserID = userID - ranking.Username = username + ranking.UserName = username sql := `SELECT DISTINCT map_id, score_count FROM records_sp WHERE user_id = $1 ORDER BY map_id, score_count;` rows, err := database.DB.Query(sql, userID) if err != nil { @@ -90,7 +90,7 @@ func Rankings(c *gin.Context) { if uniqueMultiUserRecords == totalMultiMaps { var ranking models.UserRanking ranking.UserID = userID - ranking.Username = username + ranking.UserName = username sql := `SELECT DISTINCT map_id, score_count FROM records_mp WHERE host_id = $1 OR partner_id = $2 ORDER BY map_id, score_count;` rows, err := database.DB.Query(sql, userID, userID) 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) { user.LocCountryCode = "XX" } // Insert new user to database - database.DB.Exec(`INSERT INTO users (steam_id, username, avatar_link, country_code) + database.DB.Exec(`INSERT INTO users (steam_id, user_name, avatar_link, country_code) VALUES ($1, $2, $3, $4)`, steamID, user.PersonaName, user.AvatarFull, user.LocCountryCode) } // 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) { Data: models.ProfileResponse{ Profile: true, SteamID: user.(models.User).SteamID, - Username: user.(models.User).Username, + UserName: user.(models.User).UserName, AvatarLink: user.(models.User).AvatarLink, CountryCode: user.(models.User).CountryCode, ScoresSP: scoresSP, @@ -120,7 +120,7 @@ func FetchUser(c *gin.Context) { // Check if user exists var user models.User err := database.DB.QueryRow(`SELECT * FROM users WHERE steam_id = $1;`, id).Scan( - &user.SteamID, &user.Username, &user.AvatarLink, &user.CountryCode, + &user.SteamID, &user.UserName, &user.AvatarLink, &user.CountryCode, &user.CreatedAt, &user.UpdatedAt) if user.SteamID == "" { // User does not exist @@ -190,7 +190,7 @@ func FetchUser(c *gin.Context) { Data: models.ProfileResponse{ Profile: true, SteamID: user.SteamID, - Username: user.Username, + UserName: user.UserName, AvatarLink: user.AvatarLink, CountryCode: user.CountryCode, ScoresSP: scoresSP, @@ -236,7 +236,7 @@ func UpdateUser(c *gin.Context) { Data: models.ProfileResponse{ Profile: true, SteamID: user.(models.User).SteamID, - Username: profile.PersonaName, + UserName: profile.PersonaName, AvatarLink: profile.AvatarFull, CountryCode: profile.LocCountryCode, }, 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 @@ CREATE TABLE users ( steam_id TEXT, - username TEXT NOT NULL, + user_name TEXT NOT NULL, avatar_link TEXT NOT NULL, country_code CHAR(2) NOT NULL, 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) { // Get user from DB var user models.User database.DB.QueryRow(`SELECT * FROM users WHERE steam_id = $1;`, claims["sub"]).Scan( - &user.SteamID, &user.Username, &user.AvatarLink, + &user.SteamID, &user.UserName, &user.AvatarLink, &user.CountryCode, &user.CreatedAt, &user.UpdatedAt) if user.SteamID == "" { 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 { type User struct { SteamID string `json:"steam_id"` - Username string `json:"username"` + UserName string `json:"user_name"` AvatarLink string `json:"avatar_link"` CountryCode string `json:"country_code"` CreatedAt time.Time `json:"created_at"` @@ -88,7 +88,7 @@ type RecordRequest struct { type UserRanking struct { UserID string `json:"user_id"` - Username string `json:"username"` + UserName string `json:"user_name"` TotalScore int `json:"total_score"` } @@ -100,7 +100,7 @@ type RankingsResponse struct { type ProfileResponse struct { Profile bool `json:"profile"` SteamID string `json:"steam_id"` - Username string `json:"username"` + UserName string `json:"user_name"` AvatarLink string `json:"avatar_link"` CountryCode string `json:"country_code"` ScoresSP []ScoreResponse `json:"scores_sp"` -- cgit v1.2.3