-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
961d3e9
commit e64f2c1
Showing
28 changed files
with
796 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,5 @@ app.*.map.json | |
/android/app/profile | ||
/android/app/release | ||
|
||
.env | ||
.env | ||
*.g.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
typedef ErrorLogger = Future<void> Function( | ||
String errorType, | ||
dynamic error, [ | ||
StackTrace? stackTrace, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
abstract class NBAppException {} | ||
|
||
class UnknownException extends NBAppException {} | ||
|
||
class BackendException extends NBAppException {} | ||
|
||
class DataMappingException extends NBAppException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class GameStatus { | ||
GameStatus({ | ||
required this.isFinished, | ||
required this.isHalfTime, | ||
this.clock, | ||
}); | ||
|
||
final String? clock; | ||
final bool isHalfTime; | ||
final bool isFinished; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:domain/model/game_status.dart'; | ||
import 'package:domain/model/team.dart'; | ||
import 'package:domain/model/team_score.dart'; | ||
|
||
class GameSummary { | ||
GameSummary({ | ||
required this.date, | ||
required this.period, | ||
required this.gameStatus, | ||
required this.id, | ||
required this.arenaName, | ||
required this.homeTeam, | ||
required this.visitorTeam, | ||
required this.homeTeamScore, | ||
required this.visitorTeamScore, | ||
}); | ||
|
||
final String id; | ||
final DateTime date; | ||
final int period; | ||
final GameStatus gameStatus; | ||
final String arenaName; | ||
final Team homeTeam; | ||
final Team visitorTeam; | ||
final TeamScore homeTeamScore; | ||
final TeamScore visitorTeamScore; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Team { | ||
Team({ | ||
required this.id, | ||
required this.name, | ||
required this.nickName, | ||
required this.code, | ||
required this.logoUrl, | ||
}); | ||
|
||
final String id; | ||
final String name; | ||
final String nickName; | ||
final String code; | ||
final String logoUrl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class TeamScore { | ||
TeamScore({ | ||
required this.wins, | ||
required this.loses, | ||
required this.points, | ||
}); | ||
|
||
final int wins; | ||
final int loses; | ||
final int points; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:domain/model/game_summary.dart'; | ||
|
||
abstract class GameDataRepository { | ||
Future<List<GameSummary>> getLiveGames(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:domain/model/game_summary.dart'; | ||
import 'package:domain/repository/game_repository.dart'; | ||
import 'package:domain/use_case/use_case.dart'; | ||
|
||
class GetLiveGamesUC extends UseCase<void, List<GameSummary>> { | ||
GetLiveGamesUC({ | ||
required super.errorLogger, | ||
required GameDataRepository repository, | ||
}) : _repository = repository; | ||
|
||
final GameDataRepository _repository; | ||
|
||
@override | ||
Future<List<GameSummary>> getRawFuture(void params) => | ||
_repository.getLiveGames(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:domain/error_logger.dart'; | ||
import 'package:domain/exceptions.dart'; | ||
|
||
abstract class UseCase<Param, Return> { | ||
const UseCase({ | ||
required this.errorLogger, | ||
}); | ||
|
||
final ErrorLogger errorLogger; | ||
|
||
Future<Return> getRawFuture(Param params); | ||
|
||
Future<Return> getFuture(Param params) async { | ||
try { | ||
return await getRawFuture(params); | ||
} catch (e, stackTrace) { | ||
errorLogger('Domain level error', e, stackTrace); | ||
|
||
if (e is! NBAppException) { | ||
throw UnknownException(); | ||
} else { | ||
rethrow; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:domain/exceptions.dart'; | ||
import 'package:domain/model/game_status.dart'; | ||
import 'package:nbapp/data/remote/model/game_status_rm.dart'; | ||
|
||
extension GameStatusRMtoDM on GameStatusRM { | ||
GameStatus toDM() { | ||
try { | ||
return GameStatus( | ||
clock: clock, | ||
isFinished: long == 'Finished', | ||
isHalfTime: halftime, | ||
); | ||
} catch (_) { | ||
throw DataMappingException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:domain/exceptions.dart'; | ||
import 'package:domain/model/game_summary.dart'; | ||
import 'package:nbapp/data/mapper/game_status_mapper.dart'; | ||
import 'package:nbapp/data/mapper/team_mapper.dart'; | ||
import 'package:nbapp/data/mapper/team_scores_mapper.dart'; | ||
import 'package:nbapp/data/remote/model/game_summary_rm.dart'; | ||
|
||
extension GameSummaryRMtoDM on GameSummaryRM { | ||
GameSummary toDM() { | ||
try { | ||
return GameSummary( | ||
date: DateTime.parse(date.start), | ||
period: periods.current, | ||
gameStatus: status.toDM(), | ||
id: id, | ||
arenaName: arena.name, | ||
homeTeam: teams.home.toDM(), | ||
visitorTeam: teams.visitors.toDM(), | ||
homeTeamScore: scores.home.toDM(), | ||
visitorTeamScore: scores.visitors.toDM(), | ||
); | ||
} catch (_) { | ||
throw DataMappingException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:domain/model/team.dart'; | ||
import 'package:nbapp/data/remote/model/team_rm.dart'; | ||
|
||
extension TeamMapper on TeamRM { | ||
Team toDM() => Team( | ||
id: id, | ||
name: name, | ||
code: code, | ||
logoUrl: logo, | ||
nickName: nickname, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:domain/model/team_score.dart'; | ||
import 'package:nbapp/data/remote/model/team_score_rm.dart'; | ||
|
||
extension TeamScoresMapper on TeamScoreRM { | ||
TeamScore toDM() => TeamScore( | ||
wins: win, | ||
loses: loss, | ||
points: points, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'arena_rm.g.dart'; | ||
|
||
@JsonSerializable() | ||
class ArenaRM { | ||
ArenaRM( | ||
this.city, | ||
this.name, | ||
this.state, | ||
this.country, | ||
); | ||
|
||
final String city; | ||
final String name; | ||
final String state; | ||
final String country; | ||
|
||
factory ArenaRM.fromJson(Map<String, dynamic> json) => | ||
_$ArenaRMFromJson(json); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'date_rm.g.dart'; | ||
|
||
@JsonSerializable() | ||
class DateRM { | ||
DateRM( | ||
this.start, | ||
this.end, | ||
this.duration, | ||
); | ||
|
||
final String start; | ||
final String end; | ||
final String duration; | ||
|
||
factory DateRM.fromJson(Map<String, dynamic> json) => _$DateRMFromJson(json); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'game_status_rm.g.dart'; | ||
|
||
@JsonSerializable() | ||
class GameStatusRM { | ||
GameStatusRM( | ||
this.clock, | ||
this.halftime, | ||
this.long, | ||
); | ||
|
||
final String? clock; | ||
final bool halftime; | ||
final String long; | ||
|
||
factory GameStatusRM.fromJson(Map<String, dynamic> json) => | ||
_$GameStatusRMFromJson(json); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:nbapp/data/remote/model/arena_rm.dart'; | ||
import 'package:nbapp/data/remote/model/date_rm.dart'; | ||
import 'package:nbapp/data/remote/model/game_status_rm.dart'; | ||
import 'package:nbapp/data/remote/model/periods_rm.dart'; | ||
import 'package:nbapp/data/remote/model/scores_rm.dart'; | ||
import 'package:nbapp/data/remote/model/teams_rm.dart'; | ||
|
||
part 'game_summary_rm.g.dart'; | ||
|
||
@JsonSerializable() | ||
class GameSummaryRM { | ||
GameSummaryRM( | ||
this.id, | ||
this.date, | ||
this.status, | ||
this.periods, | ||
this.arena, | ||
this.teams, | ||
this.scores, | ||
); | ||
|
||
final String id; | ||
final DateRM date; | ||
final GameStatusRM status; | ||
final PeriodsRM periods; | ||
final ArenaRM arena; | ||
final TeamsRM teams; | ||
final ScoresRM scores; | ||
|
||
factory GameSummaryRM.fromJson(Map<String, dynamic> json) => | ||
_$GameSummaryRMFromJson(json); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'periods_rm.g.dart'; | ||
|
||
@JsonSerializable() | ||
class PeriodsRM { | ||
PeriodsRM( | ||
this.current, | ||
this.total, | ||
this.endOfPeriod, | ||
); | ||
|
||
final int current; | ||
final int total; | ||
final bool endOfPeriod; | ||
|
||
factory PeriodsRM.fromJson(Map<String, dynamic> json) => | ||
_$PeriodsRMFromJson(json); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:nbapp/data/remote/model/team_score_rm.dart'; | ||
|
||
part 'scores_rm.g.dart'; | ||
|
||
@JsonSerializable() | ||
class ScoresRM { | ||
ScoresRM( | ||
this.visitors, | ||
this.home, | ||
); | ||
|
||
final TeamScoreRM visitors; | ||
final TeamScoreRM home; | ||
|
||
factory ScoresRM.fromJson(Map<String, dynamic> json) => | ||
_$ScoresRMFromJson(json); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'team_rm.g.dart'; | ||
|
||
@JsonSerializable() | ||
class TeamRM { | ||
TeamRM( | ||
this.id, | ||
this.name, | ||
this.nickname, | ||
this.code, | ||
this.logo, | ||
); | ||
|
||
final String id; | ||
final String name; | ||
final String nickname; | ||
final String code; | ||
final String logo; | ||
|
||
factory TeamRM.fromJson(Map<String, dynamic> json) => _$TeamRMFromJson(json); | ||
} |
Oops, something went wrong.