Refactoring: now we respect gofmt and have some comments
This commit is contained in:
@@ -11,39 +11,42 @@ import (
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
func (g *Getters) GetPlayerByID(player_id int) (dbmapping.Player, bool) {
|
||||
player_raw := dbmapping.Player{}
|
||||
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE id=?"), player_id)
|
||||
// GetPlayerByID returns dbmapping.Player instance with given ID.
|
||||
func (g *Getters) GetPlayerByID(playerID int) (dbmapping.Player, bool) {
|
||||
playerRaw := dbmapping.Player{}
|
||||
err := c.Db.Get(&playerRaw, c.Db.Rebind("SELECT * FROM players WHERE id=?"), playerID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return player_raw, false
|
||||
return playerRaw, false
|
||||
}
|
||||
|
||||
return player_raw, true
|
||||
return playerRaw, true
|
||||
}
|
||||
|
||||
func (g *Getters) GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool) {
|
||||
player_raw := dbmapping.Player{}
|
||||
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id=?"), telegram_id)
|
||||
// GetOrCreatePlayer seeks for player in database via Telegram ID.
|
||||
// In case, when there is no player with such ID, new player will be created.
|
||||
func (g *Getters) GetOrCreatePlayer(telegramID int) (dbmapping.Player, bool) {
|
||||
playerRaw := dbmapping.Player{}
|
||||
err := c.Db.Get(&playerRaw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id=?"), telegramID)
|
||||
if err != nil {
|
||||
log.Printf("Message user not found in database.")
|
||||
log.Printf(err.Error())
|
||||
|
||||
// Create "nobody" user
|
||||
player_raw.Telegram_id = telegram_id
|
||||
player_raw.League_id = 0
|
||||
player_raw.Squad_id = 0
|
||||
player_raw.Status = "nobody"
|
||||
player_raw.Created_at = time.Now().UTC()
|
||||
player_raw.Updated_at = time.Now().UTC()
|
||||
_, err = c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :squad_id, :status, :created_at, :updated_at)", &player_raw)
|
||||
playerRaw.TelegramID = telegramID
|
||||
playerRaw.LeagueID = 0
|
||||
playerRaw.SquadID = 0
|
||||
playerRaw.Status = "nobody"
|
||||
playerRaw.CreatedAt = time.Now().UTC()
|
||||
playerRaw.UpdatedAt = time.Now().UTC()
|
||||
_, err = c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :squad_id, :status, :created_at, :updated_at)", &playerRaw)
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
return player_raw, false
|
||||
return playerRaw, false
|
||||
}
|
||||
} else {
|
||||
log.Printf("Message user found in database.")
|
||||
}
|
||||
|
||||
return player_raw, true
|
||||
return playerRaw, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user