feat: get cards from backend
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/// یک ردیف از جدولِ رتبهبندی.
|
||||
class RankEntry {
|
||||
final int rank;
|
||||
final String name;
|
||||
final String avatar;
|
||||
final int rankPoints;
|
||||
final String tier; // bronze..king
|
||||
|
||||
RankEntry.fromJson(Map<String, dynamic> j)
|
||||
: rank = (j['rank'] ?? 0) as int,
|
||||
name = (j['name'] ?? '') as String,
|
||||
avatar = (j['avatar'] ?? '') as String,
|
||||
rankPoints = (j['rank_points'] ?? 0) as int,
|
||||
tier = (j['tier'] ?? 'bronze') as String;
|
||||
}
|
||||
|
||||
/// جدولِ رتبهبندیِ فصلِ جاری.
|
||||
class Leaderboard {
|
||||
final int season;
|
||||
final List<RankEntry> entries;
|
||||
const Leaderboard(this.season, this.entries);
|
||||
|
||||
factory Leaderboard.fromJson(Map<String, dynamic> j) => Leaderboard(
|
||||
(j['season'] ?? 1) as int,
|
||||
((j['entries'] as List?) ?? [])
|
||||
.map((e) => RankEntry.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import '../../../../core/resources/data_state.dart';
|
||||
import '../entities/leaderboard.dart';
|
||||
|
||||
abstract class RankedRepository {
|
||||
Future<DataState<Leaderboard>> getLeaderboard();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import '../../../../core/resources/data_state.dart';
|
||||
import '../../../../core/usecase/use_case.dart';
|
||||
import '../entities/leaderboard.dart';
|
||||
import '../repository/ranked_repository.dart';
|
||||
|
||||
class GetLeaderboardUseCase
|
||||
implements UseCase<DataState<Leaderboard>, NoParams> {
|
||||
final RankedRepository repository;
|
||||
GetLeaderboardUseCase(this.repository);
|
||||
|
||||
@override
|
||||
Future<DataState<Leaderboard>> call(NoParams params) =>
|
||||
repository.getLeaderboard();
|
||||
}
|
||||
Reference in New Issue
Block a user