This repository has been archived on 2024-05-18. You can view files and clone it, but cannot push or open issues or pull requests.
steamServer/postgres/gamemode_store.go

43 lines
1.3 KiB
Go
Raw Normal View History

package postgres
import (
"fmt"
"git.snrd.de/Spaenny/steamServer"
"github.com/jmoiron/sqlx"
2021-09-24 13:19:44 +02:00
"github.com/google/uuid"
)
type GamemodeStore struct {
*sqlx.DB
}
func (s *GamemodeStore) Gamemode(name string) (steamServer.Gamemode, error) {
var g steamServer.Gamemode
if err := s.Get(&g, `SELECT * FROM gamemodes WHERE name = $1`, name); err != nil {
return steamServer.Gamemode{}, fmt.Errorf("error getting gamemode id: %w", err)
}
return g, nil
}
func (s *GamemodeStore) Gamemodes() ([]steamServer.Gamemode, error) {
var gg []steamServer.Gamemode
var query = `SELECT * FROM public.gamemodes ORDER BY CASE name WHEN 'Deathmatch' THEN 1 WHEN 'MGE' THEN 2 WHEN 'Jumpserver' THEN 3 WHEN 'Casual' THEN 4 END`
if err := s.Select(&gg, query); err != nil {
return []steamServer.Gamemode{}, fmt.Errorf("error gettings servers: %w", err)
}
return gg, nil
}
2021-09-24 13:19:44 +02:00
func (s *GamemodeStore) GamemodeCount(region_id uuid.UUID) ([]steamServer.GamemodeCount, error) {
var c []steamServer.GamemodeCount
var query = `SELECT DISTINCT servers.gamemode_id, COUNT(DISTINCT servers.id)
FROM servers, gamemodes
WHERE servers.region_id = $1
GROUP BY servers.gamemode_id`
if err := s.Select(&c, query, region_id); err != nil {
return c, fmt.Errorf("error getting gamemode count: %w", err)
}
return c, nil
}