update
This commit is contained in:
62
lib/features/home/domain/usecases/get_member_card.dart
Normal file
62
lib/features/home/domain/usecases/get_member_card.dart
Normal 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();
|
||||
}
|
||||
}
|
||||
84
lib/features/home/domain/usecases/get_promotions.dart
Normal file
84
lib/features/home/domain/usecases/get_promotions.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
/// Use Case: Get Promotions
|
||||
///
|
||||
/// Retrieves the list of active promotional offers.
|
||||
/// This use case encapsulates the business logic for fetching promotions.
|
||||
///
|
||||
/// Follows the Single Responsibility Principle - one use case, one operation.
|
||||
library;
|
||||
|
||||
import 'package:worker/features/home/domain/entities/promotion.dart';
|
||||
import 'package:worker/features/home/domain/repositories/home_repository.dart';
|
||||
|
||||
/// Get Promotions Use Case
|
||||
///
|
||||
/// Fetches active promotional offers to display on home screen.
|
||||
///
|
||||
/// Usage:
|
||||
/// ```dart
|
||||
/// final promotions = await getPromotions();
|
||||
/// ```
|
||||
///
|
||||
/// This use case:
|
||||
/// - Retrieves promotions from repository (which handles caching)
|
||||
/// - Filters only active promotions
|
||||
/// - Sorts by priority/date
|
||||
/// - Returns list of Promotion entities
|
||||
class GetPromotions {
|
||||
/// Home repository instance
|
||||
final HomeRepository repository;
|
||||
|
||||
/// Constructor
|
||||
const GetPromotions(this.repository);
|
||||
|
||||
/// Execute the use case
|
||||
///
|
||||
/// Returns list of active [Promotion] objects.
|
||||
/// Returns empty list if no promotions available.
|
||||
///
|
||||
/// Throws:
|
||||
/// - [NetworkException] if network error occurs
|
||||
/// - [CacheException] if local data corrupted
|
||||
Future<List<Promotion>> call() async {
|
||||
// Fetch promotions from repository
|
||||
final promotions = await repository.getPromotions();
|
||||
|
||||
// TODO: Add business logic here if needed
|
||||
// For example:
|
||||
// - Filter only active promotions
|
||||
// - Sort by priority or start date
|
||||
// - Filter by user tier (Diamond exclusive promotions)
|
||||
// - Add personalization logic
|
||||
// - Log analytics events
|
||||
|
||||
// Filter only active promotions
|
||||
final activePromotions = promotions
|
||||
.where((promotion) => promotion.isActive)
|
||||
.toList();
|
||||
|
||||
// Sort by start date (newest first)
|
||||
activePromotions.sort((a, b) => b.startDate.compareTo(a.startDate));
|
||||
|
||||
return activePromotions;
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// - Need to show latest promotions immediately
|
||||
Future<List<Promotion>> refresh() async {
|
||||
final promotions = await repository.refreshPromotions();
|
||||
|
||||
// Apply same filtering logic
|
||||
final activePromotions = promotions
|
||||
.where((promotion) => promotion.isActive)
|
||||
.toList();
|
||||
|
||||
activePromotions.sort((a, b) => b.startDate.compareTo(a.startDate));
|
||||
|
||||
return activePromotions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user