refactor: changed name of LeaderboardEntry at LeaderboardRepository to LeaderboardEntryData

pull/78/head
RuiAlonso 4 years ago
parent d5f41277c8
commit cfd87beff0

@ -9,7 +9,7 @@ abstract class LeaderboardEvent extends Equatable {
}
/// {@template top_10_fetched}
/// Request the top 10 [LeaderboardEntry]s.
/// Request the top 10 [LeaderboardEntryData]s.
/// {endtemplate}
class Top10Fetched extends LeaderboardEvent {
/// {@macro top_10_fetched}
@ -20,7 +20,7 @@ class Top10Fetched extends LeaderboardEvent {
}
/// {@template leaderboard_entry_added}
/// Writes a new [LeaderboardEntry].
/// Writes a new [LeaderboardEntryData].
///
/// Should be added when a player finishes a game.
/// {endtemplate}
@ -28,8 +28,8 @@ class LeaderboardEntryAdded extends LeaderboardEvent {
/// {@macro leaderboard_entry_added}
const LeaderboardEntryAdded({required this.entry});
/// [LeaderboardEntry] to be written to the remote storage.
final LeaderboardEntry entry;
/// [LeaderboardEntryData] to be written to the remote storage.
final LeaderboardEntryData entry;
@override
List<Object?> get props => [entry];

@ -40,7 +40,7 @@ class LeaderboardState extends Equatable {
final LeaderboardRanking ranking;
/// List of top-ranked players.
final List<LeaderboardEntry> leaderboard;
final List<LeaderboardEntryData> leaderboard;
@override
List<Object> get props => [status, ranking, leaderboard];
@ -48,7 +48,7 @@ class LeaderboardState extends Equatable {
LeaderboardState copyWith({
LeaderboardStatus? status,
LeaderboardRanking? ranking,
List<LeaderboardEntry>? leaderboard,
List<LeaderboardEntryData>? leaderboard,
}) {
return LeaderboardState(
status: status ?? this.status,

@ -83,9 +83,9 @@ class LeaderboardRepository {
final FirebaseFirestore _firebaseFirestore;
/// Acquires top 10 [LeaderboardEntry]s.
Future<List<LeaderboardEntry>> fetchTop10Leaderboard() async {
final leaderboardEntries = <LeaderboardEntry>[];
/// Acquires top 10 [LeaderboardEntryData]s.
Future<List<LeaderboardEntryData>> fetchTop10Leaderboard() async {
final leaderboardEntries = <LeaderboardEntryData>[];
late List<QueryDocumentSnapshot> documents;
try {
@ -103,7 +103,7 @@ class LeaderboardRepository {
final data = document.data() as Map<String, dynamic>?;
if (data != null) {
try {
leaderboardEntries.add(LeaderboardEntry.fromJson(data));
leaderboardEntries.add(LeaderboardEntryData.fromJson(data));
} catch (error, stackTrace) {
throw LeaderboardDeserializationException(error, stackTrace);
}
@ -115,7 +115,9 @@ class LeaderboardRepository {
/// Adds player's score entry to the leaderboard and gets their
/// [LeaderboardRanking].
Future<LeaderboardRanking> addLeaderboardEntry(LeaderboardEntry entry) async {
Future<LeaderboardRanking> addLeaderboardEntry(
LeaderboardEntryData entry,
) async {
late DocumentReference entryReference;
try {
entryReference = await _firebaseFirestore

@ -1,19 +1,19 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'leaderboard_entry.dart';
part of 'leaderboard_entry_data.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
LeaderboardEntry _$LeaderboardEntryFromJson(Map<String, dynamic> json) =>
LeaderboardEntry(
LeaderboardEntryData _$LeaderboardEntryFromJson(Map<String, dynamic> json) =>
LeaderboardEntryData(
playerInitials: json['playerInitials'] as String,
score: json['score'] as int,
character: $enumDecode(_$CharacterTypeEnumMap, json['character']),
);
Map<String, dynamic> _$LeaderboardEntryToJson(LeaderboardEntry instance) =>
Map<String, dynamic> _$LeaderboardEntryToJson(LeaderboardEntryData instance) =>
<String, dynamic>{
'playerInitials': instance.playerInitials,
'score': instance.score,

@ -3,7 +3,7 @@ import 'package:json_annotation/json_annotation.dart';
part 'leaderboard_entry.g.dart';
/// Google character type associated with a [LeaderboardEntry].
/// Google character type associated with a [LeaderboardEntryData].
enum CharacterType {
/// Dash character.
dash,
@ -18,7 +18,7 @@ enum CharacterType {
dino,
}
/// {@template leaderboard_entry}
/// {@template leaderboard_entry_data}
/// A model representing a leaderboard entry containing the player's initials,
/// score, and chosen character.
///
@ -34,42 +34,42 @@ enum CharacterType {
/// ```
/// {@endtemplate}
@JsonSerializable()
class LeaderboardEntry extends Equatable {
/// {@macro leaderboard_entry}
const LeaderboardEntry({
class LeaderboardEntryData extends Equatable {
/// {@macro leaderboard_entry_data}
const LeaderboardEntryData({
required this.playerInitials,
required this.score,
required this.character,
});
/// Factory which converts a [Map] into a [LeaderboardEntry].
factory LeaderboardEntry.fromJson(Map<String, dynamic> json) {
/// Factory which converts a [Map] into a [LeaderboardEntryData].
factory LeaderboardEntryData.fromJson(Map<String, dynamic> json) {
return _$LeaderboardEntryFromJson(json);
}
/// Converts the [LeaderboardEntry] to [Map].
/// Converts the [LeaderboardEntryData] to [Map].
Map<String, dynamic> toJson() => _$LeaderboardEntryToJson(this);
/// Player's chosen initials for [LeaderboardEntry].
/// Player's chosen initials for [LeaderboardEntryData].
///
/// Example: 'ABC'.
@JsonKey(name: 'playerInitials')
final String playerInitials;
/// Score for [LeaderboardEntry].
/// Score for [LeaderboardEntryData].
///
/// Example: 1500.
@JsonKey(name: 'score')
final int score;
/// [CharacterType] for [LeaderboardEntry].
/// [CharacterType] for [LeaderboardEntryData].
///
/// Example: [CharacterType.dash].
@JsonKey(name: 'character')
final CharacterType character;
/// An empty [LeaderboardEntry] object.
static const empty = LeaderboardEntry(
/// An empty [LeaderboardEntryData] object.
static const empty = LeaderboardEntryData(
playerInitials: '',
score: 0,
character: CharacterType.dash,

@ -2,17 +2,17 @@ import 'package:equatable/equatable.dart';
import 'package:leaderboard_repository/leaderboard_repository.dart';
/// {@template leaderboard_ranking}
/// Contains [ranking] for a single [LeaderboardEntry] and the number of players
/// the [ranking] is [outOf].
/// Contains [ranking] for a single [LeaderboardEntryData] and the number of
/// players the [ranking] is [outOf].
/// {@endtemplate}
class LeaderboardRanking extends Equatable {
/// {@macro leaderboard_ranking}
const LeaderboardRanking({required this.ranking, required this.outOf});
/// Place ranking by score for a [LeaderboardEntry].
/// Place ranking by score for a [LeaderboardEntryData].
final int ranking;
/// Number of [LeaderboardEntry]s at the time of score entry.
/// Number of [LeaderboardEntryData]s at the time of score entry.
final int outOf;
@override

@ -1,2 +1,2 @@
export 'leaderboard_entry.dart';
export 'leaderboard_entry_data.dart';
export 'leaderboard_ranking.dart';

@ -57,7 +57,7 @@ void main() {
final top10Leaderboard = top10Scores
.map(
(score) => LeaderboardEntry(
(score) => LeaderboardEntryData(
playerInitials: 'user$score',
score: score,
character: CharacterType.dash,
@ -144,7 +144,7 @@ void main() {
entryScore,
1000,
];
final leaderboardEntry = LeaderboardEntry(
final leaderboardEntry = LeaderboardEntryData(
playerInitials: 'ABC',
score: entryScore,
character: CharacterType.dash,

@ -9,21 +9,21 @@ void main() {
'character': 'dash',
};
const leaderboardEntry = LeaderboardEntry(
const leaderboardEntry = LeaderboardEntryData(
playerInitials: 'ABC',
score: 1500,
character: CharacterType.dash,
);
test('can be instantiated', () {
const leaderboardEntry = LeaderboardEntry.empty;
const leaderboardEntry = LeaderboardEntryData.empty;
expect(leaderboardEntry, isNotNull);
});
test('supports value equality.', () {
const leaderboardEntry = LeaderboardEntry.empty;
const leaderboardEntry2 = LeaderboardEntry.empty;
const leaderboardEntry = LeaderboardEntryData.empty;
const leaderboardEntry2 = LeaderboardEntryData.empty;
expect(leaderboardEntry, equals(leaderboardEntry2));
});
@ -33,7 +33,7 @@ void main() {
});
test('can be obtained from json', () {
final leaderboardEntryFrom = LeaderboardEntry.fromJson(data);
final leaderboardEntryFrom = LeaderboardEntryData.fromJson(data);
expect(leaderboardEntry, equals(leaderboardEntryFrom));
});

@ -42,7 +42,7 @@ void main() {
final top10Leaderboard = top10Scores
.map(
(score) => LeaderboardEntry(
(score) => LeaderboardEntryData(
playerInitials: 'user$score',
score: score,
character: CharacterType.dash,
@ -101,7 +101,7 @@ void main() {
});
group('LeaderboardEntryAdded', () {
final leaderboardEntry = LeaderboardEntry(
final leaderboardEntry = LeaderboardEntryData(
playerInitials: 'ABC',
score: 1500,
character: CharacterType.dash,

@ -20,7 +20,7 @@ void main() {
});
group('LeaderboardEntryAdded', () {
const leaderboardEntry = LeaderboardEntry(
const leaderboardEntry = LeaderboardEntryData(
playerInitials: 'ABC',
score: 1500,
character: CharacterType.dash,

@ -25,7 +25,7 @@ void main() {
});
group('copyWith', () {
const leaderboardEntry = LeaderboardEntry(
const leaderboardEntry = LeaderboardEntryData(
playerInitials: 'ABC',
score: 1500,
character: CharacterType.dash,

Loading…
Cancel
Save