c'est très moche et sa sert a rien
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
f49ef5bac5
commit
7b8aea0e57
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
import 'package:bowl_in/model/ApiManager/GameService.dart';
|
||||||
|
import 'package:bowl_in/model/ApiManager/UserService.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
import '../GameDetail.dart';
|
||||||
|
import '../IGameManager.dart';
|
||||||
|
import '../IManager.dart';
|
||||||
|
import '../IUserManager.dart';
|
||||||
|
|
||||||
|
class ApiManager extends IManager {
|
||||||
|
final httpClient = http.Client();
|
||||||
|
final int userId = 1;
|
||||||
|
|
||||||
|
late IUserManager _userMgr;
|
||||||
|
late IGameManager _gameMgr;
|
||||||
|
|
||||||
|
ApiManager() {
|
||||||
|
_userMgr = UserService(this);
|
||||||
|
_gameMgr = GameService(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<GameDetail> _gameDetails = [];
|
||||||
|
|
||||||
|
List<GameDetail> get gameDetails => _gameDetails;
|
||||||
|
|
||||||
|
set gameDetails(List<GameDetail> gameDetails) {
|
||||||
|
_gameDetails = gameDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
import 'package:bowl_in/model/ApiManager/ApiManager.dart';
|
||||||
|
|
||||||
|
import '../IAuthManager.dart';
|
||||||
|
|
||||||
|
class AuthService extends IAuthManager {
|
||||||
|
final ApiManager parent;
|
||||||
|
|
||||||
|
AuthService(this.parent);
|
||||||
|
@override
|
||||||
|
bool verifiedUser(String mail, String password) {
|
||||||
|
// TODO: implement verifiedUser
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
/* AuthManager(this.parent);
|
||||||
|
// Methods
|
||||||
|
bool verifiedUser(String mail, String password) {
|
||||||
|
for (var user in parent.players) {
|
||||||
|
if (user is User && user.mail == mail) {
|
||||||
|
parent.userCurrent = user as User;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}*/
|
||||||
|
}
|
@ -0,0 +1,192 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:bowl_in/model/ApiManager/responceFactory/GameFactory.dart';
|
||||||
|
import 'package:bowl_in/model/ApiManager/responceFactory/UserFactory.dart';
|
||||||
|
|
||||||
|
import '../GameDetail.dart';
|
||||||
|
import '../IGameManager.dart';
|
||||||
|
import '../Player.dart';
|
||||||
|
import '../User.dart';
|
||||||
|
import 'ApiManager.dart';
|
||||||
|
|
||||||
|
class GameService extends IGameManager {
|
||||||
|
|
||||||
|
var url = Uri.parse('http:localhost:8080/games');
|
||||||
|
|
||||||
|
final ApiManager parent;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
GameService(this.parent){
|
||||||
|
_initGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
_initGame() async {
|
||||||
|
parent.gameDetails = await parent.database.readGameDetail();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
@override
|
||||||
|
Future<GameDetail> getGameById(int id) async {
|
||||||
|
try{
|
||||||
|
var response = await parent.httpClient.get(Uri.parse('${url}/$id'));
|
||||||
|
if (response.statusCode == 200){
|
||||||
|
var decodedResponse = jsonDecode(response.body);
|
||||||
|
return GameFactory.toModel(decodedResponse);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error occurred while fetching count isint 200 ');
|
||||||
|
throw Exception('Http failded but not implented');
|
||||||
|
}
|
||||||
|
}catch(error){
|
||||||
|
print('Error occurred while fetching count for game: $error');
|
||||||
|
throw Exception('Http failded but not implented');;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<GameDetail>> getGamesByPlayerId(int id) async {
|
||||||
|
return _getGames(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<GameDetail>> _getGames(dynamic player) async {
|
||||||
|
// Récupérer l'ID du joueur si un joueur a été passé en paramètre
|
||||||
|
int playerId = player is User ? player.id : player;
|
||||||
|
|
||||||
|
// Effectuer l'appel API pour récupérer les détails des jeux pour ce joueur
|
||||||
|
var response = await parent.httpClient.get(Uri.parse('${url}/$playerId/players'));
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
// Décoder la réponse JSON en une liste de détails de jeu
|
||||||
|
var decodedResponse = jsonDecode(response.body) as List<dynamic>;
|
||||||
|
return decodedResponse.map((game) => GameDetail.fromJson(game)).toList();
|
||||||
|
} else {
|
||||||
|
throw Exception('Failed to retrieve game details');
|
||||||
|
}
|
||||||
|
var response = await parent.httpClient.get(Uri.parse('${url}/$id/players'));
|
||||||
|
if (response.statusCode == 200){
|
||||||
|
var decodedResponse = jsonDecode(response.body);
|
||||||
|
return decodedResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<GameDetail>> getGamesByPlayer(Player user) async {
|
||||||
|
return _getGames(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<GameDetail>> getGamesByPlayers(List<Player> users) async {
|
||||||
|
List<GameDetail> games = [];
|
||||||
|
List<String> playerIds = users.map((player) => player.name).toList();
|
||||||
|
|
||||||
|
try{
|
||||||
|
var response = await parent.httpClient.get(Uri.parse('${url}/$id/players'));
|
||||||
|
if (response.statusCode == 200){
|
||||||
|
var decodedResponse = jsonDecode(response.body);
|
||||||
|
return decodedResponse;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error occurred while fetching count isint 200 ');
|
||||||
|
throw Exception('Http failded but not implented');
|
||||||
|
}
|
||||||
|
}catch(error){
|
||||||
|
print('Error occurred while fetching count for game: $error');
|
||||||
|
throw Exception('Http failded but not implented');;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<Player>> getPlayersByIdGame(int id) async {
|
||||||
|
try{
|
||||||
|
var response = await parent.httpClient.get(Uri.parse('${url}/$id/players'));
|
||||||
|
if (response.statusCode == 200){
|
||||||
|
var decodedResponse = jsonDecode(response.body) as List<dynamic>;
|
||||||
|
List<Player> players = decodedResponse
|
||||||
|
.map((userJson) => UserFactory.toModel(userJson))
|
||||||
|
.toList();
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error occurred while fetching count isint 200 ');
|
||||||
|
throw Exception('Http failded but not implented');
|
||||||
|
}
|
||||||
|
}catch(error){
|
||||||
|
print('Error occurred while fetching count for game: $error');
|
||||||
|
throw Exception('Http failded but not implented');;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Map<Player, int>> getRankByIdGame(int id) async {
|
||||||
|
try{
|
||||||
|
var response = await parent.httpClient.get(Uri.parse('${url}/$id/rank'));
|
||||||
|
if (response.statusCode == 200){
|
||||||
|
var decodedResponse = jsonDecode(response.body);
|
||||||
|
return decodedResponse;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error occurred while fetching count isint 200 ');
|
||||||
|
throw Exception('Http failded but not implented');
|
||||||
|
}
|
||||||
|
}catch(error){
|
||||||
|
print('Error occurred while fetching count for game: $error');
|
||||||
|
throw Exception('Http failded but not implented');;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
addGame(GameDetail gd) async {
|
||||||
|
try{
|
||||||
|
var response = await parent.httpClient.post(url, body : GameFactory.toJson(gd));
|
||||||
|
if (response.statusCode == 200){
|
||||||
|
var decodedResponse = jsonDecode(response.body);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error occurred while fetching count isint 200 ');
|
||||||
|
throw Exception('Http failded but not implented');
|
||||||
|
}
|
||||||
|
}catch(error){
|
||||||
|
print('Error occurred while fetching count for game: $error');
|
||||||
|
throw Exception('Http failded but not implented');;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Future<void> createGame(User user) async {
|
||||||
|
final db = await instance.database;
|
||||||
|
|
||||||
|
await db.transaction((txn) async {
|
||||||
|
for (var game in user.games) {
|
||||||
|
await txn.insert(tableGame, GameMapper.toJson(game, user));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Future<void> createGameDetail(GameDetail gameDetail) async {
|
||||||
|
final db = await instance.database;
|
||||||
|
|
||||||
|
await db.transaction((txn) async {
|
||||||
|
await txn.insert(tableGameDetail, GameDetailMapper.toJson(gameDetail));
|
||||||
|
});
|
||||||
|
}*/
|
||||||
|
|
||||||
|
@override
|
||||||
|
getNextId() async {
|
||||||
|
try{
|
||||||
|
var response = await parent.httpClient.get(Uri.parse('${url}/count'));
|
||||||
|
if (response.statusCode == 200){
|
||||||
|
var decodedResponse = jsonDecode(response.body);
|
||||||
|
return decodedResponse;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error occurred while fetching count isint 200 ');
|
||||||
|
throw Exception('Http failded but not implented');
|
||||||
|
}
|
||||||
|
}catch(error){
|
||||||
|
print('Error occurred while fetching count for game: $error');
|
||||||
|
throw Exception('Http failded but not implented');;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
import 'package:bowl_in/model/ApiManager/ApiManager.dart';
|
||||||
|
import 'package:bowl_in/model/ApiManager/AuthService.dart';
|
||||||
|
import 'package:bowl_in/model/ApiManager/responceFactory/UserFactory.dart';
|
||||||
|
import 'package:bowl_in/model/Player.dart';
|
||||||
|
|
||||||
|
import 'package:bowl_in/model/User.dart';
|
||||||
|
|
||||||
|
import '../IAuthManager.dart';
|
||||||
|
import '../IUserManager.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class UserService extends IUserManager {
|
||||||
|
var url = Uri.parse('https://localhost:8443/users');
|
||||||
|
|
||||||
|
late IAuthManager _authMgr;
|
||||||
|
final ApiManager parent;
|
||||||
|
|
||||||
|
UserService(this.parent) : super(AuthService(parent)){
|
||||||
|
_initUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
_initUser() async {
|
||||||
|
try {
|
||||||
|
var user = await getUserById(parent.userId);
|
||||||
|
parent.userCurrent = user;
|
||||||
|
}catch(error){
|
||||||
|
User user2 = User(0, "Unknown", "./assets/images/image_user_pink.png", "", [], []);
|
||||||
|
parent.userCurrent = user2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<User> getRankingWithFriends() {
|
||||||
|
// TODO: implement getRankingWithFriends
|
||||||
|
List<User> sortedPlayers = List.from(parent.userCurrent.friends);
|
||||||
|
sortedPlayers.sort((a, b) => b.stat.highscore.compareTo(a.stat.highscore));
|
||||||
|
return sortedPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<User> getUserById(int id) async {
|
||||||
|
try{
|
||||||
|
var response = await parent.httpClient.get(Uri.parse('${url}/$id'));
|
||||||
|
if (response.statusCode == 200){
|
||||||
|
var decodedResponse = jsonDecode(response.body);
|
||||||
|
print(decodedResponse);
|
||||||
|
return UserFactory.toModel(decodedResponse);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error occurred while fetching user by ID isint 200 ');
|
||||||
|
throw Exception('Http failded but not implented');
|
||||||
|
}
|
||||||
|
}catch(error){
|
||||||
|
print('Error occurred while fetching user by ID: $error');
|
||||||
|
throw Exception('Http failded but not implented');;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<Player>> getUsersByName(String name) async {
|
||||||
|
// TODO: implement getUsersByName
|
||||||
|
throw UnimplementedError();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
saveUser(User user) async {
|
||||||
|
var response = await parent.httpClient.post(url, body : UserFactory.toJson(user));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
class StatsFields {
|
||||||
|
static final List<String> values = [
|
||||||
|
id, user, nbVictories, nbGames
|
||||||
|
];
|
||||||
|
|
||||||
|
static final String id = 'id';
|
||||||
|
static final String user = 'user';
|
||||||
|
static final String nbVictories = 'nbVictories';
|
||||||
|
static final String nbGames = 'nbGames';
|
||||||
|
static final String highscore = 'highscore';
|
||||||
|
static final String nbStrikes = 'nbStrikes';
|
||||||
|
static final String nbSpares = 'nbSpares';
|
||||||
|
static final String avgScore = 'avgScore';
|
||||||
|
static final String avgPinsPerRound = 'avgPinsPerRound';
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
|||||||
|
class UserFields {
|
||||||
|
static final List<String> values = [
|
||||||
|
id, name, image, mail
|
||||||
|
];
|
||||||
|
|
||||||
|
static final String id = 'id';
|
||||||
|
static final String name = 'name';
|
||||||
|
static final String image = 'image';
|
||||||
|
static final String mail = 'mail';
|
||||||
|
static final String password = 'password';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
|||||||
|
import 'package:bowl_in/model/GameDetail.dart';
|
||||||
|
|
||||||
|
import '../../Game.dart';
|
||||||
|
import '../../Player.dart';
|
||||||
|
import '../../User.dart';
|
||||||
|
|
||||||
|
class GameFactory {
|
||||||
|
static Map<String, dynamic> toJson(Game game, User user,) {
|
||||||
|
return {
|
||||||
|
GameFields.id: game.id,
|
||||||
|
GameFields.date: game.date.toIso8601String(),
|
||||||
|
GameFields.pointsCurrentUser: game.pointsCurrentUser,
|
||||||
|
GameFields.userId: user.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, dynamic> toJsonDetails(GameDetail game) {
|
||||||
|
return {
|
||||||
|
GameFields.id: game.id,
|
||||||
|
GameFields.date: game.date.toIso8601String(),
|
||||||
|
GameFields.pointsCurrentUser: game.pointsCurrentUser,
|
||||||
|
GameFields.userId: user.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static Game toModel(Map<String, dynamic> json, List<Player> players) {
|
||||||
|
return Game(
|
||||||
|
json[GameFields.id],
|
||||||
|
DateTime.parse(json[GameFields.date]),
|
||||||
|
json[GameFields.pointsCurrentUser],
|
||||||
|
players
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
import '../../Stat.dart';
|
||||||
|
import '../../User.dart';
|
||||||
|
import '../fields/StatsField.dart';
|
||||||
|
|
||||||
|
class StatsFactory {
|
||||||
|
static Stat fromJson(Map<String, dynamic> json) {
|
||||||
|
return Stat(
|
||||||
|
json[StatsFields.nbVictories],
|
||||||
|
json[StatsFields.nbGames],
|
||||||
|
json[StatsFields.highscore],
|
||||||
|
json[StatsFields.nbStrikes],
|
||||||
|
json[StatsFields.nbSpares],
|
||||||
|
0,
|
||||||
|
json[StatsFields.avgScore],
|
||||||
|
json[StatsFields.avgPinsPerRound]
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
static Map<String, dynamic> toJson(Stat stat, User user) {
|
||||||
|
return {
|
||||||
|
StatsFields.user: user.id,
|
||||||
|
StatsFields.nbVictories:stat.nbVictory,
|
||||||
|
StatsFields.nbGames: stat.nbGames,
|
||||||
|
StatsFields.highscore: stat.highscore,
|
||||||
|
StatsFields.nbStrikes: stat.nbStrikes,
|
||||||
|
StatsFields.nbSpares: stat.nbSpares,
|
||||||
|
StatsFields.avgScore:stat.avgScore,
|
||||||
|
StatsFields.avgPinsPerRound: stat.avgPinsPerRound
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
import 'package:bowl_in/model/User.dart';
|
||||||
|
|
||||||
|
import '../fields/UserField.dart';
|
||||||
|
import 'StatsFactory.dart';
|
||||||
|
|
||||||
|
class UserFactory {
|
||||||
|
static User toModel(Map<String, dynamic> json) {
|
||||||
|
return User.withStat(
|
||||||
|
json['id'],
|
||||||
|
json['name'],
|
||||||
|
json['photoProfile'],
|
||||||
|
json['email'],
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
StatsFactory.fromJson(json['stats'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, dynamic> toJson(User user) {
|
||||||
|
return {
|
||||||
|
UserFields.id: user.id,
|
||||||
|
UserFields.name: user.name,
|
||||||
|
UserFields.password:'000',
|
||||||
|
UserFields.image: user.image,
|
||||||
|
UserFields.mail: user.mail,
|
||||||
|
'stats': StatsFactory.toJson(user.stat, user),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue