Push LocalStorage (UserManager+SaveToStorage)
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
f420a4fd5e
commit
b0d75eb10a
@ -0,0 +1,17 @@
|
||||
library LocalLib;
|
||||
|
||||
import '../IAuthManager.dart';
|
||||
import 'LocalData.dart';
|
||||
|
||||
class AuthManager extends IAuthManager {
|
||||
final LocalData parent;
|
||||
|
||||
// Constructor
|
||||
AuthManager(this.parent);
|
||||
|
||||
// Methods
|
||||
@override
|
||||
bool verifiedUser(String name, String password) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
library LocalLib;
|
||||
|
||||
import '../IGameManager.dart';
|
||||
import '../GameDetail.dart';
|
||||
import '../Player.dart';
|
||||
import '../User.dart';
|
||||
import '../Guest.dart';
|
||||
import 'LocalData.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class GameManager extends IGameManager {
|
||||
List<GameDetail> games = [];
|
||||
final LocalData parent;
|
||||
|
||||
// Constructor
|
||||
GameManager(this.parent);
|
||||
|
||||
// Methods
|
||||
@override
|
||||
GameDetail getGameById(Uuid id) {
|
||||
return GameDetail(Uuid(), DateTime.now(), Uuid(), 290, true, null,
|
||||
Guest(Uuid(), "", ""), [], []);
|
||||
}
|
||||
|
||||
@override
|
||||
List<GameDetail> getGamesByPlayerId(Uuid id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@override
|
||||
List<GameDetail> getGamesByPlayer(Player user) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@override
|
||||
List<GameDetail> getGamesByPlayers(List<Player> users) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@override
|
||||
List<User> getPlayersByIdGame(Uuid id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@override
|
||||
Map<int, Uuid> getRankByIdGame(Uuid id) {
|
||||
return {};
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
library LocalLib;
|
||||
|
||||
import '../IManager.dart';
|
||||
import '../IUserManager.dart';
|
||||
import '../IGameManager.dart';
|
||||
import '../User.dart';
|
||||
import 'UserManager.dart';
|
||||
import 'GameManager.dart';
|
||||
import 'package:localstorage/localstorage.dart';
|
||||
|
||||
class LocalData extends IManager {
|
||||
late IUserManager _userMgr;
|
||||
late IGameManager _gameMgr;
|
||||
|
||||
final LocalStorage storage = LocalStorage('local_key');
|
||||
|
||||
List<User> users = [];
|
||||
|
||||
LocalData() {
|
||||
_userMgr = UserManager(this);
|
||||
_gameMgr = GameManager(this);
|
||||
users = storage.getItem('users');
|
||||
}
|
||||
|
||||
_saveToStorage() {
|
||||
storage.setItem('users', toJSONEncodable());
|
||||
}
|
||||
|
||||
_clearStorage() async {
|
||||
await storage.clear();
|
||||
}
|
||||
|
||||
toJSONEncodable() {
|
||||
return users.map((user) {
|
||||
return user.toJSONEncodable();
|
||||
}).toList();
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
library LocalLib;
|
||||
|
||||
import '../IUserManager.dart';
|
||||
import '../IAuthManager.dart';
|
||||
import 'AuthManager.dart';
|
||||
import 'LocalData.dart';
|
||||
import '../User.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class UserManager extends IUserManager {
|
||||
final LocalData parent;
|
||||
|
||||
// Constructor
|
||||
UserManager(this.parent) : super(AuthManager(parent));
|
||||
|
||||
// Methods
|
||||
@override
|
||||
List<User> getUsersByName(String name) {
|
||||
List<User> returnList = [];
|
||||
parent.users.forEach((element) {
|
||||
if (element.name == name) {
|
||||
returnList.add(element);
|
||||
}
|
||||
});
|
||||
return returnList;
|
||||
}
|
||||
|
||||
@override
|
||||
User getUserById(Uuid id) {
|
||||
var returnUser;
|
||||
parent.users.forEach((element) {
|
||||
if (element.id == id) {
|
||||
returnUser = element;
|
||||
}
|
||||
});
|
||||
return returnUser;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue