Testing is complete!! And a nice build runner script to boot

This commit is contained in:
2025-02-05 13:16:12 -07:00
parent 4864de624c
commit 76ea825509
25 changed files with 1453 additions and 103 deletions
+12 -5
View File
@@ -8,9 +8,9 @@ final log = Logger('Db');
class Db {
static final _db = AppDatabase();
static Future<User> getUser(String uuid) {
static Future<User?> getUserById(String uuid) {
log.finer('Getting user $uuid');
return _db.managers.users.filter((f) => f.uuid.equals(uuid)).getSingle();
return _db.managers.users.filter((f) => f.uuid.equals(uuid)).getSingleOrNull();
}
static Future<User?> createUser({required String username, required String roomCode}) async {
@@ -32,14 +32,21 @@ class Db {
});
}
static Future<GameRoom> createRoom({required String roomCode}) => _db.managers.gameRooms
.createReturning(
static Future<GameRoom?> createRoom({required String roomCode}) => _db.managers.gameRooms
.createReturningOrNull(
(o) => o(createdAt: Value(DateTime.now()), status: GameStatus.open, uuid: const Uuid().v4(), code: roomCode),
)
.catchError(
(Object err) {
log.severe('Failed to create room', err, StackTrace.current);
throw Exception(err.toString());
return null;
},
);
static Future<GameRoom?> getRoomByCode(String? roomCode) async {
final room = await _db.managers.gameRooms
.filter((f) => f.code.equals(roomCode) & f.status.isIn([GameStatus.open, GameStatus.running]))
.getSingleOrNull();
return room;
}
}