2021-09-13 21:45:08 +01:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"git.ctrlz.es/mgdelacroix/craban/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (a *App) CreateGame(name string, userID int) (*model.Game, error) {
|
|
|
|
return a.Store.Game().Create(name, userID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) AddMember(gameID, userID int, role string) (*model.GameMember, error) {
|
|
|
|
return a.Store.Game().AddMember(gameID, userID, role)
|
|
|
|
}
|
|
|
|
|
2021-09-13 21:59:52 +01:00
|
|
|
func (a *App) ListGames() ([]*model.Game, error) {
|
|
|
|
games, err := a.Store.Game().List()
|
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
return []*model.Game{}, nil
|
|
|
|
}
|
|
|
|
return games, err
|
|
|
|
}
|
|
|
|
|
2021-09-13 21:45:08 +01:00
|
|
|
func (a *App) ListGamesForUser(userID int) ([]*model.Game, error) {
|
|
|
|
games, err := a.Store.Game().ListForUser(userID)
|
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
return []*model.Game{}, nil
|
|
|
|
}
|
|
|
|
return games, err
|
|
|
|
}
|