This commit is contained in:
Phuoc Nguyen
2025-10-17 17:49:01 +07:00
parent 628c81ce13
commit 57bf73e4d1
23 changed files with 2655 additions and 87 deletions

View File

@@ -0,0 +1,62 @@
/// Use Case: Get Member Card
///
/// Retrieves the current user's member card information.
/// This use case encapsulates the business logic for fetching member card data.
///
/// Follows the Single Responsibility Principle - one use case, one operation.
library;
import 'package:worker/features/home/domain/entities/member_card.dart';
import 'package:worker/features/home/domain/repositories/home_repository.dart';
/// Get Member Card Use Case
///
/// Fetches the current authenticated user's member card.
///
/// Usage:
/// ```dart
/// final memberCard = await getMemberCard();
/// ```
///
/// This use case:
/// - Retrieves member card from repository (which handles caching)
/// - Can add business logic if needed (e.g., validation, transformation)
/// - Returns MemberCard entity
class GetMemberCard {
/// Home repository instance
final HomeRepository repository;
/// Constructor
const GetMemberCard(this.repository);
/// Execute the use case
///
/// Returns [MemberCard] with user's membership information.
///
/// Throws:
/// - [UnauthorizedException] if user not authenticated
/// - [NetworkException] if network error occurs
/// - [CacheException] if local data corrupted
Future<MemberCard> call() async {
// TODO: Add business logic here if needed
// For example:
// - Validate user authentication
// - Check if card is expired and handle accordingly
// - Transform data if needed
// - Log analytics events
return await repository.getMemberCard();
}
/// Execute with force refresh
///
/// Forces a refresh from the server instead of using cached data.
///
/// Use this when:
/// - User explicitly pulls to refresh
/// - Cached data is known to be stale
/// - After points redemption or other updates
Future<MemberCard> refresh() async {
return await repository.refreshMemberCard();
}
}