Best pokememes for user listing
This commit is contained in:
@@ -12,10 +12,12 @@ type GettersInterface interface {
|
||||
Init()
|
||||
// Player
|
||||
GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool)
|
||||
GetPlayerByID(player_id int) (dbmapping.Player, bool)
|
||||
// Profile
|
||||
GetProfile(player_id int) (dbmapping.Profile, bool)
|
||||
// Pokememes
|
||||
GetPokememes() ([]dbmapping.PokememeFull, bool)
|
||||
GetBestPokememes(player_id int) ([]dbmapping.PokememeFull, bool)
|
||||
GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool)
|
||||
// Possibilities
|
||||
PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int)
|
||||
|
@@ -11,6 +11,17 @@ 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)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return player_raw, false
|
||||
}
|
||||
|
||||
return player_raw, 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)
|
||||
|
@@ -11,16 +11,12 @@ import (
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
func (g *Getters) GetPokememes() ([]dbmapping.PokememeFull, bool) {
|
||||
// Internal functions
|
||||
|
||||
func (g *Getters) formFullPokememes(pokememes []dbmapping.Pokememe) ([]dbmapping.PokememeFull, bool) {
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
pokememes := []dbmapping.Pokememe{}
|
||||
err := c.Db.Select(&pokememes, "SELECT * FROM pokememes ORDER BY grade asc, name asc");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
elements := []dbmapping.Element{}
|
||||
err = c.Db.Select(&elements, "SELECT * FROM elements");
|
||||
err := c.Db.Select(&elements, "SELECT * FROM elements");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
@@ -79,6 +75,48 @@ func (g *Getters) GetPokememes() ([]dbmapping.PokememeFull, bool) {
|
||||
return pokememes_full, true
|
||||
}
|
||||
|
||||
// External functions
|
||||
|
||||
func (g *Getters) GetPokememes() ([]dbmapping.PokememeFull, bool) {
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
pokememes := []dbmapping.Pokememe{}
|
||||
err := c.Db.Select(&pokememes, "SELECT * FROM pokememes ORDER BY grade asc, name asc");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
|
||||
pokememes_full, ok := g.formFullPokememes(pokememes)
|
||||
return pokememes_full, ok
|
||||
}
|
||||
|
||||
func (g *Getters) GetBestPokememes(player_id int) ([]dbmapping.PokememeFull, bool) {
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
player_raw, ok := g.GetPlayerByID(player_id)
|
||||
if !ok {
|
||||
return pokememes_full, ok
|
||||
}
|
||||
profile_raw, ok := g.GetProfile(player_id)
|
||||
if !ok {
|
||||
return pokememes_full, ok
|
||||
}
|
||||
|
||||
if player_raw.League_id == 0 {
|
||||
return pokememes_full, false
|
||||
}
|
||||
|
||||
// TODO: make it more complicated
|
||||
pokememes := []dbmapping.Pokememe{}
|
||||
err := c.Db.Select(&pokememes, c.Db.Rebind("SELECT p.* FROM pokememes p, pokememes_elements pe, elements e WHERE e.league_id = ? AND p.grade = ? AND pe.element_id = e.id AND pe.pokememe_id = p.id ORDER BY p.attack DESC"), player_raw.League_id, profile_raw.Level_id + 1)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
|
||||
pokememes_full, ok = g.formFullPokememes(pokememes)
|
||||
return pokememes_full, ok
|
||||
}
|
||||
|
||||
func (g *Getters) GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool) {
|
||||
pokememe_full := dbmapping.PokememeFull{}
|
||||
pokememe := dbmapping.Pokememe{}
|
||||
|
@@ -10,9 +10,9 @@ import (
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
func (g *Getters) GetProfile(profile_id int) (dbmapping.Profile, bool) {
|
||||
func (g *Getters) GetProfile(player_id int) (dbmapping.Profile, bool) {
|
||||
profile_raw := dbmapping.Profile{}
|
||||
err := c.Db.Get(&profile_raw, c.Db.Rebind("SELECT * FROM profiles WHERE player_id=? ORDER BY created_at DESC LIMIT 1"), profile_id)
|
||||
err := c.Db.Get(&profile_raw, c.Db.Rebind("SELECT * FROM profiles WHERE player_id=? ORDER BY created_at DESC LIMIT 1"), player_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return profile_raw, false
|
||||
|
Reference in New Issue
Block a user