feat: add get a game service and fake database
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user