Add getGame and listGames endpoints, client methods and initial components

This commit is contained in:
Miguel de la Cruz 2021-09-16 00:37:07 +02:00
parent ff455414f8
commit 08ab312f92
8 changed files with 136 additions and 8 deletions

View file

@ -14,6 +14,20 @@ func (a *App) AddMember(gameID, userID int, role string) (*model.GameMember, err
return a.Store.Game().AddMember(gameID, userID, role)
}
func (a *App) GetGameForUser(gameID, userID int) (*model.Game, error) {
game, err := a.Store.Game().GetByID(gameID)
if err != nil {
return nil, err
}
// ToDo: create a helper like userIsMember or
// userHasPermissionToGame instead of checking ownership
if game.UserID != userID {
return nil, nil
}
return game, nil
}
func (a *App) ListGames() ([]*model.Game, error) {
games, err := a.Store.Game().List()
if err == sql.ErrNoRows {