31 lines
638 B
Go
31 lines
638 B
Go
package service
|
|
|
|
import (
|
|
"hamster-tycoon/storage/dao"
|
|
"hamster-tycoon/storage/model"
|
|
)
|
|
|
|
type GameService struct {
|
|
serviceContext
|
|
}
|
|
|
|
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
|
|
}
|