refactor
This commit is contained in:
@@ -2,27 +2,27 @@ import 'package:game_tracker/data/database.dart';
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
|
|
||||||
extension GroupMethods on AppDatabase {
|
extension GroupMethods on AppDatabase {
|
||||||
Future<List<GroupData>> getAllGroups() async {
|
Future<List<GroupTableData>> getAllGroups() async {
|
||||||
return await select(group).get();
|
return await select(groupTable).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<GroupData> getGroupById(String id) async {
|
Future<GroupTableData> getGroupById(String id) async {
|
||||||
return await (select(group)..where((g) => g.id.equals(id))).getSingle();
|
return await (select(groupTable)..where((g) => g.id.equals(id))).getSingle();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> addGroup(String id, String name) async {
|
Future<void> addGroup(String id, String name) async {
|
||||||
await into(group).insert(
|
await into(groupTable).insert(
|
||||||
GroupCompanion.insert(id: id, name: name),
|
GroupTableCompanion.insert(id: id, name: name),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteGroup(String id) async {
|
Future<void> deleteGroup(String id) async {
|
||||||
await (delete(group)..where((g) => g.id.equals(id))).go();
|
await (delete(groupTable)..where((g) => g.id.equals(id))).go();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateGroupname(String id, String newName) async {
|
Future<void> updateGroupname(String id, String newName) async {
|
||||||
await (update(group)..where((g) => g.id.equals(id))).write(
|
await (update(groupTable)..where((g) => g.id.equals(id))).write(
|
||||||
GroupCompanion(name: Value(newName)),
|
GroupTableCompanion(name: Value(newName)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,27 +2,27 @@ import 'package:game_tracker/data/database.dart';
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
|
|
||||||
extension UserMethods on AppDatabase {
|
extension UserMethods on AppDatabase {
|
||||||
Future<List<UserData>> getAllUsers() async {
|
Future<List<UserTableData>> getAllUsers() async {
|
||||||
return await select(user).get();
|
return await select(userTable).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<UserData> getUserById(String id) async {
|
Future<UserTableData> getUserById(String id) async {
|
||||||
return await (select(user)..where((u) => u.id.equals(id))).getSingle();
|
return await (select(userTable)..where((u) => u.id.equals(id))).getSingle();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> addUser(String id, String name) async {
|
Future<void> addUser(String id, String name) async {
|
||||||
await into(user).insert(
|
await into(userTable).insert(
|
||||||
UserCompanion.insert(id: id, name: name),
|
UserTableCompanion.insert(id: id, name: name),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteUser(String id) async {
|
Future<void> deleteUser(String id) async {
|
||||||
await (delete(user)..where((u) => u.id.equals(id))).go();
|
await (delete(userTable)..where((u) => u.id.equals(id))).go();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateUsername(String id, String newName) async {
|
Future<void> updateUsername(String id, String newName) async {
|
||||||
await (update(user)..where((u) => u.id.equals(id))).write(
|
await (update(userTable)..where((u) => u.id.equals(id))).write(
|
||||||
UserCompanion(name: Value(newName)),
|
UserTableCompanion(name: Value(newName)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,25 +2,25 @@ import 'package:game_tracker/data/database.dart';
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
|
|
||||||
extension UserGroupMethods on AppDatabase {
|
extension UserGroupMethods on AppDatabase {
|
||||||
Future<List<UserGroupData>> getAllUsersAndGroups() async {
|
Future<List<UserGroupTableData>> getAllUsersAndGroups() async {
|
||||||
return await select(userGroup).get();
|
return await select(userGroupTable).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<UserGroupData>> getUsersGroups(String userId) async {
|
Future<List<UserGroupTableData>> getUsersGroups(String userId) async {
|
||||||
return await (select(userGroup)..where((uG) => uG.userId.equals(userId))).get();
|
return await (select(userGroupTable)..where((uG) => uG.userId.equals(userId))).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<UserGroupData>> getGroupsUsers(String groupId) async {
|
Future<List<UserGroupTableData>> getGroupsUsers(String groupId) async {
|
||||||
return await (select(userGroup)..where((uG) => uG.groupId.equals(groupId))).get();
|
return await (select(userGroupTable)..where((uG) => uG.groupId.equals(groupId))).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> addUserToGroup(String userId, String groupId) async {
|
Future<void> addUserToGroup(String userId, String groupId) async {
|
||||||
await into(userGroup).insert(
|
await into(userGroupTable).insert(
|
||||||
UserGroupCompanion.insert(userId: userId, groupId: groupId),
|
UserGroupTableCompanion.insert(userId: userId, groupId: groupId),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> removeUserFromGroup(String userId, String groupId) async {
|
Future<void> removeUserFromGroup(String userId, String groupId) async {
|
||||||
await (delete(userGroup)..where((uG) => uG.userId.equals(userId) & uG.groupId.equals(groupId))).go();
|
await (delete(userGroupTable)..where((uG) => uG.userId.equals(userId) & uG.groupId.equals(groupId))).go();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user