update submission
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
/// Submissions Remote Data Source
|
||||
///
|
||||
/// Handles remote API calls for project submissions.
|
||||
library;
|
||||
|
||||
import 'package:worker/features/projects/domain/entities/project_submission.dart';
|
||||
|
||||
/// Submissions Remote Data Source
|
||||
///
|
||||
/// Abstract interface for remote submissions operations.
|
||||
abstract class SubmissionsRemoteDataSource {
|
||||
/// Fetch all submissions from remote API
|
||||
Future<List<ProjectSubmission>> getSubmissions();
|
||||
|
||||
/// Fetch a single submission by ID
|
||||
Future<ProjectSubmission> getSubmissionById(String submissionId);
|
||||
|
||||
/// Create a new submission
|
||||
Future<ProjectSubmission> createSubmission(ProjectSubmission submission);
|
||||
|
||||
/// Update an existing submission
|
||||
Future<ProjectSubmission> updateSubmission(ProjectSubmission submission);
|
||||
|
||||
/// Delete a submission
|
||||
Future<void> deleteSubmission(String submissionId);
|
||||
}
|
||||
|
||||
/// Mock Implementation of Submissions Remote Data Source
|
||||
///
|
||||
/// Provides mock data for development and testing.
|
||||
class SubmissionsRemoteDataSourceImpl implements SubmissionsRemoteDataSource {
|
||||
@override
|
||||
Future<List<ProjectSubmission>> getSubmissions() async {
|
||||
// Simulate network delay
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
|
||||
return [
|
||||
ProjectSubmission(
|
||||
submissionId: 'DA001',
|
||||
userId: 'user123',
|
||||
projectName: 'Chung cư Vinhomes Grand Park - Block A1',
|
||||
projectAddress: 'TP.HCM',
|
||||
projectValue: 850000000,
|
||||
projectType: ProjectType.residential,
|
||||
status: SubmissionStatus.approved,
|
||||
beforePhotos: [],
|
||||
afterPhotos: [],
|
||||
invoices: [],
|
||||
submittedAt: DateTime(2023, 11, 15),
|
||||
reviewedAt: DateTime(2023, 11, 20),
|
||||
pointsEarned: 8500,
|
||||
),
|
||||
ProjectSubmission(
|
||||
submissionId: 'DA002',
|
||||
userId: 'user123',
|
||||
projectName: 'Trung tâm thương mại Bitexco',
|
||||
projectAddress: 'TP.HCM',
|
||||
projectValue: 2200000000,
|
||||
projectType: ProjectType.commercial,
|
||||
status: SubmissionStatus.pending,
|
||||
beforePhotos: [],
|
||||
afterPhotos: [],
|
||||
invoices: [],
|
||||
submittedAt: DateTime(2023, 11, 25),
|
||||
),
|
||||
ProjectSubmission(
|
||||
submissionId: 'DA003',
|
||||
userId: 'user123',
|
||||
projectName: 'Biệt thự sinh thái Ecopark',
|
||||
projectAddress: 'Hà Nội',
|
||||
projectValue: 420000000,
|
||||
projectType: ProjectType.residential,
|
||||
status: SubmissionStatus.approved,
|
||||
beforePhotos: [],
|
||||
afterPhotos: [],
|
||||
invoices: [],
|
||||
submittedAt: DateTime(2023, 10, 10),
|
||||
reviewedAt: DateTime(2023, 10, 15),
|
||||
pointsEarned: 4200,
|
||||
),
|
||||
ProjectSubmission(
|
||||
submissionId: 'DA004',
|
||||
userId: 'user123',
|
||||
projectName: 'Nhà xưởng sản xuất ABC',
|
||||
projectAddress: 'Bình Dương',
|
||||
projectValue: 1500000000,
|
||||
projectType: ProjectType.industrial,
|
||||
status: SubmissionStatus.rejected,
|
||||
beforePhotos: [],
|
||||
afterPhotos: [],
|
||||
invoices: [],
|
||||
submittedAt: DateTime(2023, 11, 20),
|
||||
reviewedAt: DateTime(2023, 11, 28),
|
||||
rejectionReason: 'Thiếu giấy phép xây dựng và báo cáo tác động môi trường',
|
||||
),
|
||||
ProjectSubmission(
|
||||
submissionId: 'DA005',
|
||||
userId: 'user123',
|
||||
projectName: 'Khách sạn 5 sao Diamond Plaza',
|
||||
projectAddress: 'Đà Nẵng',
|
||||
projectValue: 5800000000,
|
||||
projectType: ProjectType.commercial,
|
||||
status: SubmissionStatus.pending,
|
||||
beforePhotos: [],
|
||||
afterPhotos: [],
|
||||
invoices: [],
|
||||
submittedAt: DateTime(2023, 12, 1),
|
||||
),
|
||||
ProjectSubmission(
|
||||
submissionId: 'DA006',
|
||||
userId: 'user123',
|
||||
projectName: 'Khu đô thị thông minh Smart City',
|
||||
projectAddress: 'Hà Nội',
|
||||
projectValue: 8500000000,
|
||||
projectType: ProjectType.residential,
|
||||
status: SubmissionStatus.approved,
|
||||
beforePhotos: [],
|
||||
afterPhotos: [],
|
||||
invoices: [],
|
||||
submittedAt: DateTime(2023, 11, 10),
|
||||
reviewedAt: DateTime(2023, 11, 18),
|
||||
pointsEarned: 85000,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProjectSubmission> getSubmissionById(String submissionId) async {
|
||||
// Simulate network delay
|
||||
await Future<void>.delayed(const Duration(milliseconds: 300));
|
||||
|
||||
final submissions = await getSubmissions();
|
||||
return submissions.firstWhere(
|
||||
(s) => s.submissionId == submissionId,
|
||||
orElse: () => throw Exception('Submission not found'),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProjectSubmission> createSubmission(
|
||||
ProjectSubmission submission,
|
||||
) async {
|
||||
// Simulate network delay
|
||||
await Future<void>.delayed(const Duration(milliseconds: 800));
|
||||
|
||||
// In real implementation, this would call the API
|
||||
return submission;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProjectSubmission> updateSubmission(
|
||||
ProjectSubmission submission,
|
||||
) async {
|
||||
// Simulate network delay
|
||||
await Future<void>.delayed(const Duration(milliseconds: 600));
|
||||
|
||||
// In real implementation, this would call the API
|
||||
return submission;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteSubmission(String submissionId) async {
|
||||
// Simulate network delay
|
||||
await Future<void>.delayed(const Duration(milliseconds: 400));
|
||||
|
||||
// In real implementation, this would call the API
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/// Submissions Repository Implementation
|
||||
///
|
||||
/// Implements the submissions repository interface.
|
||||
library;
|
||||
|
||||
import 'package:worker/features/projects/data/datasources/submissions_remote_datasource.dart';
|
||||
import 'package:worker/features/projects/domain/entities/project_submission.dart';
|
||||
import 'package:worker/features/projects/domain/repositories/submissions_repository.dart';
|
||||
|
||||
/// Submissions Repository Implementation
|
||||
///
|
||||
/// Handles data operations for project submissions.
|
||||
class SubmissionsRepositoryImpl implements SubmissionsRepository {
|
||||
|
||||
const SubmissionsRepositoryImpl(this._remoteDataSource);
|
||||
final SubmissionsRemoteDataSource _remoteDataSource;
|
||||
|
||||
@override
|
||||
Future<List<ProjectSubmission>> getSubmissions() async {
|
||||
try {
|
||||
return await _remoteDataSource.getSubmissions();
|
||||
} catch (e) {
|
||||
// In real implementation, handle errors properly
|
||||
// For now, rethrow
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProjectSubmission> getSubmissionById(String submissionId) async {
|
||||
try {
|
||||
return await _remoteDataSource.getSubmissionById(submissionId);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProjectSubmission> createSubmission(
|
||||
ProjectSubmission submission,
|
||||
) async {
|
||||
try {
|
||||
return await _remoteDataSource.createSubmission(submission);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProjectSubmission> updateSubmission(
|
||||
ProjectSubmission submission,
|
||||
) async {
|
||||
try {
|
||||
return await _remoteDataSource.updateSubmission(submission);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteSubmission(String submissionId) async {
|
||||
try {
|
||||
await _remoteDataSource.deleteSubmission(submissionId);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user