add missing path property handling
This commit is contained in:
@@ -34,7 +34,7 @@ func (db *DatabasePostgreSQL) GetAllGames() ([]*model.Game, error) {
|
||||
return games, nil
|
||||
}
|
||||
|
||||
func (db *DatabasePostgreSQL) GetGameById(id string) (*model.Game, error) {
|
||||
func (db *DatabasePostgreSQL) GetGameByID(id string) (*model.Game, error) {
|
||||
q := `
|
||||
SELECT g.id, g.server_id, g.user_id, g.created_at, g.updated_at
|
||||
FROM public.game g
|
||||
@@ -88,6 +88,47 @@ func (db *DatabasePostgreSQL) DeleteGame(id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *DatabasePostgreSQL) GetHamstersOfGame(gameID string) ([]*model.Hamster, error) {
|
||||
q := `
|
||||
SELECT id, created_at, updated_at, name, number, sexe, age, father_id, mother_id, hunger_level, thirst_level, weight, height, alive, sold, gestation, gestation_period, gestation_cooldown, gestation_father_id
|
||||
FROM public.Hamster h
|
||||
JOIN public.cage c
|
||||
ON c.id = h.cage_id
|
||||
JOIN public.game g
|
||||
on c.game_id = g.id
|
||||
WHERE g.id = $1
|
||||
`
|
||||
rows, err := db.session.Query(q, gameID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
hamsters := make([]*model.Hamster, 0)
|
||||
for rows.Next() {
|
||||
hamster := model.Hamster{
|
||||
Mother: &model.Hamster{},
|
||||
Father: &model.Hamster{},
|
||||
GestationFather: &model.Hamster{},
|
||||
}
|
||||
err := rows.Scan(&hamster.ID, &hamster.CreatedAt,
|
||||
&hamster.UpdatedAt, &hamster.Name,
|
||||
&hamster.Number, &hamster.Sexe,
|
||||
&hamster.Age, &hamster.Father.ID,
|
||||
&hamster.Mother.ID, &hamster.HungerLevel,
|
||||
&hamster.ThirstLevel, &hamster.Weight,
|
||||
&hamster.Height, &hamster.Alive,
|
||||
&hamster.Sold, &hamster.Gestation,
|
||||
&hamster.GestationPeriod, &hamster.GestationCooldown,
|
||||
&hamster.GestationFather.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hamsters = append(hamsters, &hamster)
|
||||
}
|
||||
return hamsters, nil
|
||||
}
|
||||
|
||||
func (db *DatabasePostgreSQL) UpdateGame(*model.Game) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user