Add create game and list games endpoints

This commit is contained in:
Miguel de la Cruz 2021-09-13 22:45:08 +02:00
parent 38c7229216
commit 2d2cd288f2
4 changed files with 76 additions and 1 deletions

23
server/app/game.go Normal file
View file

@ -0,0 +1,23 @@
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)
}
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
}