67 lines
2.1 KiB
Dart
67 lines
2.1 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../domain/entities/contribution.dart';
|
|
import '../../domain/entities/contribution_record.dart';
|
|
import '../../domain/usecases/contribution/get_user_contribution.dart';
|
|
import '../../domain/repositories/contribution_repository.dart';
|
|
import '../../core/di/injection.dart';
|
|
|
|
final getUserContributionUseCaseProvider = Provider<GetUserContribution>((ref) {
|
|
return getIt<GetUserContribution>();
|
|
});
|
|
|
|
final contributionRepositoryProvider = Provider<ContributionRepository>((ref) {
|
|
return getIt<ContributionRepository>();
|
|
});
|
|
|
|
final contributionProvider = FutureProvider.family<Contribution?, String>(
|
|
(ref, accountSequence) async {
|
|
final useCase = ref.watch(getUserContributionUseCaseProvider);
|
|
final result = await useCase(accountSequence);
|
|
return result.fold(
|
|
(failure) => throw Exception(failure.message),
|
|
(contribution) => contribution,
|
|
);
|
|
},
|
|
);
|
|
|
|
/// 贡献值记录请求参数
|
|
class ContributionRecordsParams {
|
|
final String accountSequence;
|
|
final int page;
|
|
final int pageSize;
|
|
|
|
const ContributionRecordsParams({
|
|
required this.accountSequence,
|
|
this.page = 1,
|
|
this.pageSize = 10,
|
|
});
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is ContributionRecordsParams &&
|
|
runtimeType == other.runtimeType &&
|
|
accountSequence == other.accountSequence &&
|
|
page == other.page &&
|
|
pageSize == other.pageSize;
|
|
|
|
@override
|
|
int get hashCode => accountSequence.hashCode ^ page.hashCode ^ pageSize.hashCode;
|
|
}
|
|
|
|
/// 贡献值记录 Provider
|
|
final contributionRecordsProvider = FutureProvider.family<ContributionRecordsPage?, ContributionRecordsParams>(
|
|
(ref, params) async {
|
|
final repository = ref.watch(contributionRepositoryProvider);
|
|
final result = await repository.getContributionRecords(
|
|
params.accountSequence,
|
|
page: params.page,
|
|
pageSize: params.pageSize,
|
|
);
|
|
return result.fold(
|
|
(failure) => throw Exception(failure.message),
|
|
(records) => records,
|
|
);
|
|
},
|
|
);
|