From 977055d6b669095d858594dec94efb8d82d802bc Mon Sep 17 00:00:00 2001 From: robyzzz Date: Thu, 3 Mar 2022 19:00:09 +0000 Subject: [PATCH] steam_user fix --- controller/login.go | 7 +++++-- model/schema.go | 5 ++--- model/steam_user.go | 13 ++++++------- utils/utils.go | 1 - 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/controller/login.go b/controller/login.go index 094bbc8..cc12d02 100644 --- a/controller/login.go +++ b/controller/login.go @@ -20,14 +20,17 @@ func Login(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, opId.AuthUrl(), http.StatusTemporaryRedirect) default: // login success + + w.Header().Set("Content-Type", "application/json") + user, err := opId.ValidateAndGetUser(config.STEAM_API_KEY) if err != nil { - utils.APIErrorRespond(w, utils.NewAPIError(http.StatusInternalServerError, err.Error())) + utils.APIErrorRespond(w, utils.NewAPIError(http.StatusInternalServerError, "ValidateAndGetUser:"+err.Error())) return } if err = CreateSteamUser(user); err != nil { - utils.APIErrorRespond(w, utils.NewAPIError(http.StatusInternalServerError, err.Error())) + utils.APIErrorRespond(w, utils.NewAPIError(http.StatusInternalServerError, "CreateSteamUser:"+err.Error())) return } diff --git a/model/schema.go b/model/schema.go index e224a85..580cb04 100644 --- a/model/schema.go +++ b/model/schema.go @@ -19,7 +19,6 @@ CREATE TABLE IF NOT EXISTS "steam_user" ( "primaryclanid" TEXT, "timecreated" INTEGER, "loccountrycode" TEXT, - "gameid" INTEGER, "created_at" TIMESTAMP, "updated_at" TIMESTAMP DEFAULT NOW() ); @@ -61,8 +60,8 @@ ALTER TABLE "player_stats" INSERT INTO steam_user(steamid, personaname, lastlogoff, profileurl, avatar, avatarmedium, - avatarfull, realname, primaryclanid, timecreated, loccountrycode, gameid, created_at) - VALUES ('steamid','bozo',123,'kkk','a', 'b', 'c', 'yes', '13', 123, 'dd', 123, NOW()); + avatarfull, realname, primaryclanid, timecreated, loccountrycode, created_at) + VALUES ('steamid','bozo',123,'kkk','a', 'b', 'c', 'yes', '13', 123, 'dd', NOW()); INSERT INTO map(name) VALUES ('xdream'); diff --git a/model/steam_user.go b/model/steam_user.go index 5ae0cb2..6ae35e1 100644 --- a/model/steam_user.go +++ b/model/steam_user.go @@ -17,7 +17,6 @@ type SteamUser struct { PrimaryClanID string `json:"primaryclanid"` TimeCreated int `json:"timecreated"` LocCountryCode string `json:"loccountrycode"` - GameID int `json:"gameid"` Created_At string `json:"created_at"` Updated_At string `json:"updated_at"` } @@ -39,11 +38,11 @@ func CreateSteamUser(user SteamUser) error { } query := `INSERT INTO steam_user(steamid, personaname, lastlogoff, profileurl, avatar, avatarmedium, - avatarfull, realname, primaryclanid, timecreated, loccountrycode, gameid, created_at) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);` + avatarfull, realname, primaryclanid, timecreated, loccountrycode, created_at) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);` _, err = db.Exec(query, user.SteamID, user.PersonaName, user.LastLogOff, user.ProfileUrl, user.Avatar, user.AvatarMedium, - user.AvatarFull, user.RealName, user.PrimaryClanID, user.TimeCreated, user.LocCountryCode, user.GameID, "NOW()") + user.AvatarFull, user.RealName, user.PrimaryClanID, user.TimeCreated, user.LocCountryCode, "NOW()") if err != nil { log.Printf("Error creating SteamUser @CreateSteamUser: %s\n", err.Error()) @@ -56,12 +55,12 @@ func CreateSteamUser(user SteamUser) error { func UpdateSteamUser(user SteamUser) error { query := `UPDATE steam_user SET personaname = $1::text, lastlogoff = $2, profileurl = $3::text, avatar = $4::text, avatarmedium = $5::text, avatarfull = $6::text, realname = $7::text, - primaryclanid = $8::text, timecreated = $9, loccountrycode = $10::text, gameid = $11, updated_at = NOW() - WHERE steamid=$12::text ;` + primaryclanid = $8::text, timecreated = $9, loccountrycode = $10::text, updated_at = NOW() + WHERE steamid=$11::text ;` _, err = db.Exec(query, user.PersonaName, user.LastLogOff, user.ProfileUrl, user.Avatar, user.AvatarMedium, user.AvatarFull, user.RealName, - user.PrimaryClanID, user.TimeCreated, user.LocCountryCode, user.GameID, user.SteamID) + user.PrimaryClanID, user.TimeCreated, user.LocCountryCode, user.SteamID) if err != nil { log.Printf("Error updating SteamUser @UpdateSteamUser: %s\n", err.Error()) diff --git a/utils/utils.go b/utils/utils.go index 461a9c6..e154908 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -42,6 +42,5 @@ func PlayerSummariesToSteamUser(user *steam_go.PlayerSummaries) model.SteamUser PrimaryClanID: user.PrimaryClanId, TimeCreated: user.TimeCreated, LocCountryCode: user.LocCountryCode, - GameID: user.GameId, } }