|
@ -1,9 +1,13 @@ |
|
|
package de.fd.fh.server.game; |
|
|
package de.fd.fh.server.game; |
|
|
|
|
|
|
|
|
import com.mongodb.MongoClient; |
|
|
import com.mongodb.MongoClient; |
|
|
|
|
|
import de.fd.fh.server.user.UserId; |
|
|
import dev.morphia.Datastore; |
|
|
import dev.morphia.Datastore; |
|
|
import dev.morphia.Key; |
|
|
import dev.morphia.Key; |
|
|
import dev.morphia.Morphia; |
|
|
import dev.morphia.Morphia; |
|
|
|
|
|
import dev.morphia.query.Query; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
public class GameRepository |
|
|
public class GameRepository |
|
|
{ |
|
|
{ |
|
@ -11,7 +15,7 @@ public class GameRepository |
|
|
|
|
|
|
|
|
public GameRepository() |
|
|
public GameRepository() |
|
|
{ |
|
|
{ |
|
|
System.out.println("AccessRepo"); |
|
|
|
|
|
|
|
|
System.out.println("GameRepo"); |
|
|
final Morphia morphia = new Morphia(); |
|
|
final Morphia morphia = new Morphia(); |
|
|
|
|
|
|
|
|
morphia.mapPackage("de.fd.fh.server.game"); |
|
|
morphia.mapPackage("de.fd.fh.server.game"); |
|
@ -35,4 +39,15 @@ public class GameRepository |
|
|
return datastore.createQuery(Game.class) |
|
|
return datastore.createQuery(Game.class) |
|
|
.field("id.identifier").equal(gameId.getIdentifier()).first(); |
|
|
.field("id.identifier").equal(gameId.getIdentifier()).first(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Game> findRunningGamesOfPlayer(final UserId userId) |
|
|
|
|
|
{ |
|
|
|
|
|
final Query<Game> query = datastore.createQuery(Game.class); |
|
|
|
|
|
query.or( |
|
|
|
|
|
query.criteria("whitePlayer.identifier").equal(userId.getIdentifier()), |
|
|
|
|
|
query.criteria("blackPlayer.identifier").equal(userId.getIdentifier())); |
|
|
|
|
|
query.and(query.criteria("winner").doesNotExist()); |
|
|
|
|
|
|
|
|
|
|
|
return query.find().toList(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |