From fc75c30bf12738fa247dde772d3039ddf210244a Mon Sep 17 00:00:00 2001 From: Suriya Date: Fri, 30 Jan 2026 23:19:28 +0530 Subject: [PATCH] fix: resolve payments compilation error and remove redundant datasource layer --- .../datasources/payments_mock_datasource.dart | 67 ----------------- .../payments_remote_datasource.dart | 7 -- .../payments_repository_impl.dart | 71 ++++++++++++++++--- .../payments_repository_impl.dart | 61 ---------------- .../domain/entities/payment_transaction.dart | 41 ----------- .../repositories/payments_repository.dart | 4 +- .../usecases/get_payment_history_usecase.dart | 6 +- .../payments/lib/src/payments_module.dart | 2 +- .../blocs/payments/payments_bloc.dart | 6 +- .../blocs/payments/payments_state.dart | 6 +- .../src/presentation/pages/payments_page.dart | 22 +++--- 11 files changed, 87 insertions(+), 206 deletions(-) delete mode 100644 apps/mobile/packages/features/staff/payments/lib/src/data/datasources/payments_mock_datasource.dart delete mode 100644 apps/mobile/packages/features/staff/payments/lib/src/data/datasources/payments_remote_datasource.dart delete mode 100644 apps/mobile/packages/features/staff/payments/lib/src/data/repositories_impl/payments_repository_impl.dart delete mode 100644 apps/mobile/packages/features/staff/payments/lib/src/domain/entities/payment_transaction.dart diff --git a/apps/mobile/packages/features/staff/payments/lib/src/data/datasources/payments_mock_datasource.dart b/apps/mobile/packages/features/staff/payments/lib/src/data/datasources/payments_mock_datasource.dart deleted file mode 100644 index 2b084c46..00000000 --- a/apps/mobile/packages/features/staff/payments/lib/src/data/datasources/payments_mock_datasource.dart +++ /dev/null @@ -1,67 +0,0 @@ -// ignore: depend_on_referenced_packages -import 'package:flutter/foundation.dart'; -import '../../domain/entities/payment_summary.dart'; -import '../../domain/entities/payment_transaction.dart'; -import 'payments_remote_datasource.dart'; - -class PaymentsMockDataSource implements PaymentsRemoteDataSource { - @override - Future fetchPaymentSummary() async { - // Simulate network delay - await Future.delayed(const Duration(milliseconds: 800)); - - // Mock data matching the prototype - return const PaymentSummary( - weeklyEarnings: 847.50, - monthlyEarnings: 3240.0, - pendingEarnings: 285.0, - totalEarnings: 12450.0, - ); - } - - @override - Future> fetchPaymentHistory(String period) async { - await Future.delayed(const Duration(milliseconds: 1000)); - - // Mock data matching the prototype - // In a real scenario, this would filter by 'period' (week/month/year) - return [ - PaymentTransaction( - id: '1', - title: 'Cook', - location: 'LA Convention Center', - address: '1201 S Figueroa St, Los Angeles, CA 90015', - workedTime: '2:00 PM - 10:00 PM', - amount: 160.00, - status: 'PAID', - hours: 8, - rate: 20.0, - date: DateTime(2025, 12, 6), // "Sat, Dec 6" (Using future date to match context if needed, but keeping it simple) - ), - PaymentTransaction( - id: '2', - title: 'Server', - location: 'The Grand Hotel', - address: '456 Main St, Los Angeles, CA 90012', - workedTime: '5:00 PM - 11:00 PM', - amount: 176.00, - status: 'PAID', - hours: 8, - rate: 22.0, - date: DateTime(2025, 12, 5), // "Fri, Dec 5" - ), - PaymentTransaction( - id: '3', - title: 'Bartender', - location: 'Club Luxe', - address: '789 Sunset Blvd, Los Angeles, CA 90028', - workedTime: '6:00 PM - 2:00 AM', - amount: 225.00, - status: 'PAID', - hours: 9, - rate: 25.0, - date: DateTime(2025, 12, 4), // "Thu, Dec 4" - ), - ]; - } -} diff --git a/apps/mobile/packages/features/staff/payments/lib/src/data/datasources/payments_remote_datasource.dart b/apps/mobile/packages/features/staff/payments/lib/src/data/datasources/payments_remote_datasource.dart deleted file mode 100644 index 37f24a9e..00000000 --- a/apps/mobile/packages/features/staff/payments/lib/src/data/datasources/payments_remote_datasource.dart +++ /dev/null @@ -1,7 +0,0 @@ -import '../../domain/entities/payment_summary.dart'; -import '../../domain/entities/payment_transaction.dart'; - -abstract class PaymentsRemoteDataSource { - Future fetchPaymentSummary(); - Future> fetchPaymentHistory(String period); -} diff --git a/apps/mobile/packages/features/staff/payments/lib/src/data/repositories/payments_repository_impl.dart b/apps/mobile/packages/features/staff/payments/lib/src/data/repositories/payments_repository_impl.dart index 5ac53641..0716001e 100644 --- a/apps/mobile/packages/features/staff/payments/lib/src/data/repositories/payments_repository_impl.dart +++ b/apps/mobile/packages/features/staff/payments/lib/src/data/repositories/payments_repository_impl.dart @@ -1,20 +1,75 @@ +import 'package:krow_data_connect/krow_data_connect.dart'; +import 'package:krow_data_connect/src/session/staff_session_store.dart'; +import 'package:krow_domain/krow_domain.dart'; import '../../domain/entities/payment_summary.dart'; -import '../../domain/entities/payment_transaction.dart'; import '../../domain/repositories/payments_repository.dart'; -import '../datasources/payments_remote_datasource.dart'; class PaymentsRepositoryImpl implements PaymentsRepository { - final PaymentsRemoteDataSource remoteDataSource; - - PaymentsRepositoryImpl({required this.remoteDataSource}); + PaymentsRepositoryImpl(); @override Future getPaymentSummary() async { - return await remoteDataSource.fetchPaymentSummary(); + // Current requirement: Mock data only for summary + await Future.delayed(const Duration(milliseconds: 500)); + return const PaymentSummary( + weeklyEarnings: 847.50, + monthlyEarnings: 3240.0, + pendingEarnings: 285.0, + totalEarnings: 12450.0, + ); } @override - Future> getPaymentHistory(String period) async { - return await remoteDataSource.fetchPaymentHistory(period); + Future> getPaymentHistory(String period) async { + final session = StaffSessionStore.instance.session; + if (session?.staff?.id == null) return []; + + final String currentStaffId = session!.staff!.id; + + try { + final response = await ExampleConnector.instance + .listRecentPaymentsByStaffId(staffId: currentStaffId) + .execute(); + + return response.data.recentPayments.map((payment) { + return StaffPayment( + id: payment.id, + staffId: payment.staffId, + assignmentId: payment.applicationId, + amount: payment.invoice.amount, + status: _mapStatus(payment.status), + paidAt: payment.invoice.issueDate?.toDate(), + ); + }).toList(); + } catch (e) { + return []; + } + } + + PaymentStatus _mapStatus(EnumValue? status) { + if (status == null || status is! Known) return PaymentStatus.pending; + + switch ((status as Known).value) { + case RecentPaymentStatus.PAID: + return PaymentStatus.paid; + case RecentPaymentStatus.PENDING: + return PaymentStatus.pending; + case RecentPaymentStatus.FAILED: + return PaymentStatus.failed; + default: + return PaymentStatus.pending; + } } } + +extension on DateTime { + // Simple toDate if needed, but Data Connect Timestamp has toDate() usually + // or we need the extension from earlier +} + +extension TimestampExt on Timestamp { + DateTime toDate() { + return DateTime.fromMillisecondsSinceEpoch(seconds.toInt() * 1000 + nanoseconds ~/ 1000000); + } +} + diff --git a/apps/mobile/packages/features/staff/payments/lib/src/data/repositories_impl/payments_repository_impl.dart b/apps/mobile/packages/features/staff/payments/lib/src/data/repositories_impl/payments_repository_impl.dart deleted file mode 100644 index 5beccf8c..00000000 --- a/apps/mobile/packages/features/staff/payments/lib/src/data/repositories_impl/payments_repository_impl.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'package:krow_data_connect/krow_data_connect.dart'; -import 'package:firebase_data_connect/firebase_data_connect.dart'; -import 'package:krow_data_connect/src/session/staff_session_store.dart'; -import 'package:krow_domain/krow_domain.dart'; -import '../../domain/repositories/payments_repository.dart'; -import '../datasources/payments_remote_datasource.dart'; - -extension TimestampExt on Timestamp { - DateTime toDate() { - return DateTime.fromMillisecondsSinceEpoch(seconds.toInt() * 1000 + nanoseconds ~/ 1000000); - } -} - -/// Implementation of [PaymentsRepository]. -class PaymentsRepositoryImpl implements PaymentsRepository { - PaymentsRepositoryImpl(); - - Future> getPayments() async { - // Get current staff ID from session - final session = StaffSessionStore.instance.session; - - if (session?.staff?.id == null) return []; - final String currentStaffId = session!.staff!.id; - - - try { - final response = await ExampleConnector.instance - .listRecentPaymentsByStaffId(staffId: currentStaffId) - .execute(); - - return response.data.recentPayments.map((payment) { - return StaffPayment( - id: payment.id, - staffId: payment.staffId, - assignmentId: payment.applicationId, // Application implies assignment - amount: payment.invoice.amount, - status: _mapStatus(payment.status), - paidAt: payment.invoice.issueDate.toDate(), - ); - }).toList(); - } catch (e) { - // Fallback or empty list on error - return []; - } - } - - PaymentStatus _mapStatus(EnumValue? status) { - if (status == null || status is! Known) return PaymentStatus.pending; - - switch ((status as Known).value) { - case RecentPaymentStatus.PAID: - return PaymentStatus.paid; - case RecentPaymentStatus.PENDING: - return PaymentStatus.pending; - case RecentPaymentStatus.FAILED: - return PaymentStatus.failed; - default: - return PaymentStatus.pending; - } - } -} diff --git a/apps/mobile/packages/features/staff/payments/lib/src/domain/entities/payment_transaction.dart b/apps/mobile/packages/features/staff/payments/lib/src/domain/entities/payment_transaction.dart deleted file mode 100644 index dff3eec0..00000000 --- a/apps/mobile/packages/features/staff/payments/lib/src/domain/entities/payment_transaction.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'package:equatable/equatable.dart'; - -class PaymentTransaction extends Equatable { - final String id; - final String title; - final String location; - final String address; - final String workedTime; - final double amount; - final String status; - final int hours; - final double rate; - final DateTime date; - - const PaymentTransaction({ - required this.id, - required this.title, - required this.location, - required this.address, - required this.workedTime, - required this.amount, - required this.status, - required this.hours, - required this.rate, - required this.date, - }); - - @override - List get props => [ - id, - title, - location, - address, - workedTime, - amount, - status, - hours, - rate, - date, - ]; -} diff --git a/apps/mobile/packages/features/staff/payments/lib/src/domain/repositories/payments_repository.dart b/apps/mobile/packages/features/staff/payments/lib/src/domain/repositories/payments_repository.dart index b142805d..d813a8ae 100644 --- a/apps/mobile/packages/features/staff/payments/lib/src/domain/repositories/payments_repository.dart +++ b/apps/mobile/packages/features/staff/payments/lib/src/domain/repositories/payments_repository.dart @@ -1,5 +1,5 @@ +import 'package:krow_domain/krow_domain.dart'; import '../entities/payment_summary.dart'; -import '../entities/payment_transaction.dart'; /// Repository interface for Payments feature. /// @@ -10,5 +10,5 @@ abstract class PaymentsRepository { Future getPaymentSummary(); /// Fetches the payment history for a specific period. - Future> getPaymentHistory(String period); + Future> getPaymentHistory(String period); } diff --git a/apps/mobile/packages/features/staff/payments/lib/src/domain/usecases/get_payment_history_usecase.dart b/apps/mobile/packages/features/staff/payments/lib/src/domain/usecases/get_payment_history_usecase.dart index 01ceac51..c43296f0 100644 --- a/apps/mobile/packages/features/staff/payments/lib/src/domain/usecases/get_payment_history_usecase.dart +++ b/apps/mobile/packages/features/staff/payments/lib/src/domain/usecases/get_payment_history_usecase.dart @@ -1,19 +1,19 @@ import 'package:krow_core/core.dart'; +import 'package:krow_domain/krow_domain.dart'; import '../arguments/get_payment_history_arguments.dart'; -import '../entities/payment_transaction.dart'; import '../repositories/payments_repository.dart'; /// Use case to retrieve payment history filtered by a period. /// /// This use case delegates the data retrieval to [PaymentsRepository]. -class GetPaymentHistoryUseCase extends UseCase> { +class GetPaymentHistoryUseCase extends UseCase> { final PaymentsRepository repository; /// Creates a [GetPaymentHistoryUseCase]. GetPaymentHistoryUseCase(this.repository); @override - Future> call(GetPaymentHistoryArguments arguments) async { + Future> call(GetPaymentHistoryArguments arguments) async { return await repository.getPaymentHistory(arguments.period); } } diff --git a/apps/mobile/packages/features/staff/payments/lib/src/payments_module.dart b/apps/mobile/packages/features/staff/payments/lib/src/payments_module.dart index 3108e8c8..d2db5ae7 100644 --- a/apps/mobile/packages/features/staff/payments/lib/src/payments_module.dart +++ b/apps/mobile/packages/features/staff/payments/lib/src/payments_module.dart @@ -3,7 +3,7 @@ import 'package:krow_data_connect/krow_data_connect.dart'; import 'domain/repositories/payments_repository.dart'; import 'domain/usecases/get_payment_summary_usecase.dart'; import 'domain/usecases/get_payment_history_usecase.dart'; -import 'data/repositories_impl/payments_repository_impl.dart'; +import 'data/repositories/payments_repository_impl.dart'; import 'presentation/blocs/payments/payments_bloc.dart'; import 'presentation/pages/payments_page.dart'; diff --git a/apps/mobile/packages/features/staff/payments/lib/src/presentation/blocs/payments/payments_bloc.dart b/apps/mobile/packages/features/staff/payments/lib/src/presentation/blocs/payments/payments_bloc.dart index f2448175..d2885d44 100644 --- a/apps/mobile/packages/features/staff/payments/lib/src/presentation/blocs/payments/payments_bloc.dart +++ b/apps/mobile/packages/features/staff/payments/lib/src/presentation/blocs/payments/payments_bloc.dart @@ -1,7 +1,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:krow_domain/krow_domain.dart'; import '../../../domain/arguments/get_payment_history_arguments.dart'; import '../../../domain/entities/payment_summary.dart'; -import '../../../domain/entities/payment_transaction.dart'; import '../../../domain/usecases/get_payment_history_usecase.dart'; import '../../../domain/usecases/get_payment_summary_usecase.dart'; import 'payments_event.dart'; @@ -27,7 +27,7 @@ class PaymentsBloc extends Bloc { try { final PaymentSummary currentSummary = await getPaymentSummary(); - final List history = await getPaymentHistory( + final List history = await getPaymentHistory( const GetPaymentHistoryArguments('week'), ); emit(PaymentsLoaded( @@ -47,7 +47,7 @@ class PaymentsBloc extends Bloc { final PaymentsState currentState = state; if (currentState is PaymentsLoaded) { try { - final List newHistory = await getPaymentHistory( + final List newHistory = await getPaymentHistory( GetPaymentHistoryArguments(event.period), ); emit(currentState.copyWith( diff --git a/apps/mobile/packages/features/staff/payments/lib/src/presentation/blocs/payments/payments_state.dart b/apps/mobile/packages/features/staff/payments/lib/src/presentation/blocs/payments/payments_state.dart index f3742ca3..4bba5691 100644 --- a/apps/mobile/packages/features/staff/payments/lib/src/presentation/blocs/payments/payments_state.dart +++ b/apps/mobile/packages/features/staff/payments/lib/src/presentation/blocs/payments/payments_state.dart @@ -1,6 +1,6 @@ import 'package:equatable/equatable.dart'; +import 'package:krow_domain/krow_domain.dart'; import '../../../domain/entities/payment_summary.dart'; -import '../../../domain/entities/payment_transaction.dart'; abstract class PaymentsState extends Equatable { const PaymentsState(); @@ -15,7 +15,7 @@ class PaymentsLoading extends PaymentsState {} class PaymentsLoaded extends PaymentsState { final PaymentSummary summary; - final List history; + final List history; final String activePeriod; const PaymentsLoaded({ @@ -26,7 +26,7 @@ class PaymentsLoaded extends PaymentsState { PaymentsLoaded copyWith({ PaymentSummary? summary, - List? history, + List? history, String? activePeriod, }) { return PaymentsLoaded( diff --git a/apps/mobile/packages/features/staff/payments/lib/src/presentation/pages/payments_page.dart b/apps/mobile/packages/features/staff/payments/lib/src/presentation/pages/payments_page.dart index e1930ada..82123957 100644 --- a/apps/mobile/packages/features/staff/payments/lib/src/presentation/pages/payments_page.dart +++ b/apps/mobile/packages/features/staff/payments/lib/src/presentation/pages/payments_page.dart @@ -3,7 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_modular/flutter_modular.dart'; import 'package:lucide_icons/lucide_icons.dart'; import 'package:intl/intl.dart'; -import '../../domain/entities/payment_transaction.dart'; +import 'package:krow_domain/krow_domain.dart'; import '../blocs/payments/payments_bloc.dart'; import '../blocs/payments/payments_event.dart'; import '../blocs/payments/payments_state.dart'; @@ -184,19 +184,21 @@ class _PaymentsPageState extends State { ), const SizedBox(height: 12), Column( - children: state.history.map((PaymentTransaction payment) { + children: state.history.map((StaffPayment payment) { return Padding( padding: const EdgeInsets.only(bottom: 8), child: PaymentHistoryItem( amount: payment.amount, - title: payment.title, - location: payment.location, - address: payment.address, - date: DateFormat('E, MMM d').format(payment.date), - workedTime: payment.workedTime, - hours: payment.hours, - rate: payment.rate, - status: payment.status, + title: "Shift Payment", + location: "Varies", + address: "Payment ID: ${payment.id}", + date: payment.paidAt != null + ? DateFormat('E, MMM d').format(payment.paidAt!) + : 'Pending', + workedTime: "Completed", + hours: 0, + rate: 0.0, + status: payment.status.name.toUpperCase(), ), ); }).toList(),