feat: refactor code
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/// آمار بازیِ کاربر (در صورت قفل بودن، null است).
|
||||
class ProfileStats {
|
||||
final int games;
|
||||
final int wins;
|
||||
final int losses;
|
||||
final int kotMade;
|
||||
final int kotReceived;
|
||||
final int cuts;
|
||||
final int hakemCount;
|
||||
const ProfileStats({
|
||||
required this.games,
|
||||
required this.wins,
|
||||
required this.losses,
|
||||
required this.kotMade,
|
||||
required this.kotReceived,
|
||||
required this.cuts,
|
||||
required this.hakemCount,
|
||||
});
|
||||
}
|
||||
|
||||
/// موجودیتِ کاملِ پروفایل (نام/آواتار + خلاصهی اقتصادی + آمار).
|
||||
class ProfileEntity {
|
||||
final String name;
|
||||
final String avatar;
|
||||
final String mobile;
|
||||
final int level;
|
||||
final int trophies;
|
||||
final int xpInto;
|
||||
final int xpNext;
|
||||
final bool vip;
|
||||
final ProfileStats? stats; // null یعنی قفل (غیر VIP)
|
||||
|
||||
const ProfileEntity({
|
||||
required this.name,
|
||||
required this.avatar,
|
||||
required this.mobile,
|
||||
required this.level,
|
||||
required this.trophies,
|
||||
required this.xpInto,
|
||||
required this.xpNext,
|
||||
required this.vip,
|
||||
required this.stats,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import '../../../../core/resources/data_state.dart';
|
||||
import '../../../../core/usecase/use_case.dart';
|
||||
import '../entities/profile_entity.dart';
|
||||
|
||||
abstract class ProfileRepository {
|
||||
Future<DataState<ProfileEntity>> getProfile();
|
||||
Future<DataState<String>> updateProfile(ProfileParams params);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import '../../../../core/resources/data_state.dart';
|
||||
import '../../../../core/usecase/use_case.dart';
|
||||
import '../entities/profile_entity.dart';
|
||||
import '../repository/profile_repository.dart';
|
||||
|
||||
class GetProfileUseCase implements UseCase<DataState<ProfileEntity>, NoParams> {
|
||||
final ProfileRepository repository;
|
||||
GetProfileUseCase(this.repository);
|
||||
|
||||
@override
|
||||
Future<DataState<ProfileEntity>> call(NoParams params) =>
|
||||
repository.getProfile();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import '../../../../core/resources/data_state.dart';
|
||||
import '../../../../core/usecase/use_case.dart';
|
||||
import '../repository/profile_repository.dart';
|
||||
|
||||
class SaveProfileUseCase implements UseCase<DataState<String>, ProfileParams> {
|
||||
final ProfileRepository repository;
|
||||
SaveProfileUseCase(this.repository);
|
||||
|
||||
@override
|
||||
Future<DataState<String>> call(ProfileParams params) =>
|
||||
repository.updateProfile(params);
|
||||
}
|
||||
Reference in New Issue
Block a user