feat: add sql request for getting game
This commit is contained in:
@@ -1,13 +1,37 @@
|
||||
package postgresql
|
||||
|
||||
import "hamster-tycoon/storage/model"
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/lib/pq"
|
||||
"hamster-tycoon/storage/dao"
|
||||
"hamster-tycoon/storage/model"
|
||||
)
|
||||
|
||||
func (db *DatabasePostgreSQL) GetAllGames() ([]*model.Game, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (db *DatabasePostgreSQL) GetGameById(string) (*model.Game, error) {
|
||||
return nil, nil
|
||||
q := `
|
||||
SELECT g.id, g.server_id, g.user_id, g.created_at, g.updated_at
|
||||
FROM public.game g
|
||||
WHERE g.id = $1
|
||||
`
|
||||
row := db.session.QueryRow(q, id)
|
||||
|
||||
server := model.Server{}
|
||||
user := model.User{}
|
||||
game := model.Game{
|
||||
Server: server,
|
||||
}
|
||||
err := row.Scan(&game.ID, &server.ID, &user.ID, &game.CreatedAt, &game.UpdatedAt)
|
||||
if errPq, ok := err.(*pq.Error); ok {
|
||||
return nil, handlePgError(errPq)
|
||||
}
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, dao.NewDAOError(dao.ErrTypeNotFound, err)
|
||||
}
|
||||
return &game, err
|
||||
}
|
||||
|
||||
func (db *DatabasePostgreSQL) CreateGame(*model.Game) error {
|
||||
|
||||
Reference in New Issue
Block a user