feat: add get a game service and fake database

This commit is contained in:
Jeffrey Duroyon
2020-05-11 01:00:02 +02:00
parent 3ab5c7916f
commit 8d40337a1c
4 changed files with 117 additions and 11 deletions

View File

@@ -1,6 +1,9 @@
package service
import "hamster-tycoon/storage/dao"
import (
"hamster-tycoon/storage/dao"
"hamster-tycoon/storage/model"
)
type GameService struct {
serviceContext
@@ -8,4 +11,20 @@ type GameService struct {
func NewGameService(database dao.Database) *GameService {
return &GameService{serviceContext{db: database}}
}
}
func (gs *GameService) GetAGameById(id string) (*model.Game, error) {
game, err := gs.db.GetGameById(id)
if err != nil {
if castedError, ok := err.(*dao.DAOError); ok {
switch castedError.Type {
case dao.ErrTypeNotFound:
return nil, &model.ErrNotFound
default:
return nil, &model.ErrInternalServer
}
}
return nil, &model.ErrInternalServer
}
return game, nil
}