-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[boardgames] added boardgames function to identify all options for a …
…specific boardgame count
- Loading branch information
1 parent
e1194d9
commit ef6bee9
Showing
5 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/DictumMortuum/servus-extapi/pkg/db" | ||
"github.com/DictumMortuum/servus-extapi/pkg/model" | ||
) | ||
|
||
func GetPopularGamesForNum(req *model.Map, res *model.Map) error { | ||
DB, err := req.GetDB() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
num, err := req.GetInt64("num") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
RDB, err := req.GetRedis() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rs := []Boardgame{} | ||
err = db.CachedSelect(DB, RDB, fmt.Sprintf("GetPopularGamesForNum%d", num), &rs, fmt.Sprintf(` | ||
select | ||
g.id, | ||
g.name, | ||
g.rank, | ||
g.square200, | ||
json_extract(g.bgg_data, '$.links.boardgamemechanic') mechanics, | ||
json_extract(g.bgg_data, '$.links.boardgamedesigner') designers, | ||
json_extract(g.bgg_data, '$.links.boardgamecategory') categories, | ||
json_extract(g.bgg_data, '$.links.boardgamefamily') families, | ||
json_extract(g.bgg_data, '$.links.boardgamesubdomain') subdomains, | ||
json_extract(g.bgg_data, '$.polls.boardgameweight.averageweight') weight, | ||
json_extract(g.bgg_data, '$.stats.average') average, | ||
g.min_players, | ||
g.max_players, | ||
max(p.date) last_played, | ||
count(*) count | ||
from | ||
tboardgames g, | ||
tboardgameplays p | ||
where | ||
g.id = p.boardgame_id and | ||
g.min_players <= %d and | ||
g.max_players >= %d %s | ||
group by | ||
1 | ||
order by | ||
last_played, weight desc, count desc | ||
`, num, num, db.YearConstraint(req, "and"))) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res.Set("options", rs) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters