Skip to content

Commit

Permalink
similar game ids added to game model
Browse files Browse the repository at this point in the history
game page related posts and similar games changed to recommended
  • Loading branch information
erkamkavak committed Dec 25, 2023
1 parent 437eb3a commit 6cbd348
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
22 changes: 18 additions & 4 deletions app/mobile/lib/data/models/game_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Game {
final int gameId;
final String title;
final String description;

String? developers;
List<String>? genres;
List<String>? platforms;
Expand All @@ -21,6 +21,7 @@ class Game {
String? creationDate;
final String gamePicture;

List<int> similarGameIds;
List<Game> similarGameList;
List<Post> relatedPosts;
String? status;
Expand All @@ -42,6 +43,7 @@ class Game {
this.creationDate,
required this.gamePicture,
this.developers,
this.similarGameIds = const [],
this.similarGameList = const [],
this.relatedPosts = const [],
this.status,
Expand All @@ -53,8 +55,12 @@ class Game {
gameId: json['gameId'],
title: json['title'],
description: json['description'],
genres: json["genres"] != null ? List<String>.from(json["genres"].map((x) => x)) : [],
platforms: json["platforms"] != null ? List<String>.from(json["platforms"].map((x) => x)) : [],
genres: json["genres"] != null
? List<String>.from(json["genres"].map((x) => x))
: [],
platforms: json["platforms"] != null
? List<String>.from(json["platforms"].map((x) => x))
: [],
playerNumber: json['playerNumber'],
releaseYear: json['releaseYear'],
universe: json['universe'],
Expand All @@ -66,7 +72,13 @@ class Game {
creationDate: json['creationDate'],
gamePicture: json['gamePicture'],
status: json['status'],
characters: json['characters'] != null ? List<Character>.from(json["characters"].map((x) => Character.fromJson(x))) : []
characters: json['characters'] != null
? List<Character>.from(
json["characters"].map((x) => Character.fromJson(x)))
: [],
similarGameIds: json['similarGames'] != null
? List<int>.from(json["similarGames"].map((x) => x))
: [],
);
}

Expand All @@ -78,6 +90,7 @@ class Game {
'genres': genres,
'platforms': platforms,
'playerNumber': playerNumber,
'releaseYear': releaseYear,
'universe': universe,
'mechanics': mechanics,
'playtime': playtime,
Expand All @@ -88,6 +101,7 @@ class Game {
'gamePicture': gamePicture,
'status': status,
'characters': characters,
'similarGames': similarGameIds,
};
}
}
13 changes: 10 additions & 3 deletions app/mobile/lib/presentation/pages/game_wiki_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,18 @@ class _GameWikiPageState extends State<GameWikiPage>

Future<Game> loadGame(int gameId) async {
Game game = await gameService.getGame(gameId);
List<Post> postList = await postService.getPosts();
List<Game> similarGames = await gameService.getGames();
List<Post> postList = await postService.getPostsByGame(gameId);
if (game.similarGameIds.isEmpty) {
game.similarGameList = await gameService.getRecommendedGames();
} else {
List<Game> allGames = await gameService.getGames();
List<Game> similarGames = allGames
.where((element) => game.similarGameIds.contains(element.gameId))
.toList();
game.similarGameList = similarGames;
}

game.relatedPosts = postList;
game.similarGameList = similarGames;

return game;
}
Expand Down

0 comments on commit 6cbd348

Please sign in to comment.