feat: add get all games
This commit is contained in:
@@ -8,7 +8,30 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (db *DatabasePostgreSQL) GetAllGames() ([]*model.Game, error) {
|
func (db *DatabasePostgreSQL) GetAllGames() ([]*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
|
||||||
|
`
|
||||||
|
rows, err := db.session.Query(q)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
games := make([]*model.Game, 0)
|
||||||
|
for rows.Next() {
|
||||||
|
server := model.Server{}
|
||||||
|
user := model.User{}
|
||||||
|
game := model.Game{
|
||||||
|
Server: server,
|
||||||
|
}
|
||||||
|
err := rows.Scan(&game.ID, &server.ID, &user.ID, &game.CreatedAt, &game.UpdatedAt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
games = append(games, &game)
|
||||||
|
}
|
||||||
|
return games, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DatabasePostgreSQL) GetGameById(id string) (*model.Game, error) {
|
func (db *DatabasePostgreSQL) GetGameById(id string) (*model.Game, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user