Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.

Commit

Permalink
steam_user fix
Browse files Browse the repository at this point in the history
  • Loading branch information
roby2014 committed Mar 3, 2022
1 parent fb6cd1e commit 977055d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
7 changes: 5 additions & 2 deletions controller/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions model/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down Expand Up @@ -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');
Expand Down
13 changes: 6 additions & 7 deletions model/steam_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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())
Expand All @@ -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())
Expand Down
1 change: 0 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ func PlayerSummariesToSteamUser(user *steam_go.PlayerSummaries) model.SteamUser
PrimaryClanID: user.PrimaryClanId,
TimeCreated: user.TimeCreated,
LocCountryCode: user.LocCountryCode,
GameID: user.GameId,
}
}

0 comments on commit 977055d

Please sign in to comment.