refactor: Implement custom DioClient with AuthInterceptor and strongly typed API service responses.
This commit is contained in:
@@ -37,23 +37,18 @@ class AttireRepositoryImpl implements AttireRepository {
|
||||
Future<AttireItem> uploadPhoto(String itemId, String filePath) async {
|
||||
// 1. Upload file to Core API
|
||||
final FileUploadService uploadService = Modular.get<FileUploadService>();
|
||||
final ApiResponse uploadRes = await uploadService.uploadFile(
|
||||
final FileUploadResponse uploadRes = await uploadService.uploadFile(
|
||||
filePath: filePath,
|
||||
fileName: filePath.split('/').last,
|
||||
);
|
||||
|
||||
if (!uploadRes.code.startsWith('2')) {
|
||||
throw Exception('Upload failed: ${uploadRes.message}');
|
||||
}
|
||||
|
||||
final String fileUri = uploadRes.data?['fileUri'] as String;
|
||||
final String fileUri = uploadRes.fileUri;
|
||||
|
||||
// 2. Create signed URL for the uploaded file
|
||||
final SignedUrlService signedUrlService = Modular.get<SignedUrlService>();
|
||||
final ApiResponse signedUrlRes = await signedUrlService.createSignedUrl(
|
||||
fileUri: fileUri,
|
||||
);
|
||||
final String photoUrl = signedUrlRes.data?['signedUrl'] as String;
|
||||
final SignedUrlResponse signedUrlRes = await signedUrlService
|
||||
.createSignedUrl(fileUri: fileUri);
|
||||
final String photoUrl = signedUrlRes.signedUrl;
|
||||
|
||||
// 3. Initiate verification job
|
||||
final VerificationService verificationService =
|
||||
@@ -68,14 +63,15 @@ class AttireRepositoryImpl implements AttireRepository {
|
||||
final String dressCode =
|
||||
'${targetItem.description ?? ''} ${targetItem.label}'.trim();
|
||||
|
||||
final ApiResponse verifyRes = await verificationService.createVerification(
|
||||
type: 'attire',
|
||||
subjectType: 'worker',
|
||||
subjectId: staff.id,
|
||||
fileUri: fileUri,
|
||||
rules: <String, dynamic>{'dressCode': dressCode},
|
||||
);
|
||||
final String verificationId = verifyRes.data?['verificationId'] as String;
|
||||
final VerificationResponse verifyRes = await verificationService
|
||||
.createVerification(
|
||||
type: 'attire',
|
||||
subjectType: 'worker',
|
||||
subjectId: staff.id,
|
||||
fileUri: fileUri,
|
||||
rules: <String, dynamic>{'dressCode': dressCode},
|
||||
);
|
||||
final String verificationId = verifyRes.verificationId;
|
||||
|
||||
// 4. Poll for status until it's finished or timeout (max 10 seconds)
|
||||
try {
|
||||
@@ -83,11 +79,10 @@ class AttireRepositoryImpl implements AttireRepository {
|
||||
bool isFinished = false;
|
||||
while (!isFinished && attempts < 5) {
|
||||
await Future<void>.delayed(const Duration(seconds: 2));
|
||||
final ApiResponse statusRes = await verificationService.getStatus(
|
||||
verificationId,
|
||||
);
|
||||
final String? status = statusRes.data?['status'] as String?;
|
||||
if (status != null && status != 'PENDING' && status != 'QUEUED') {
|
||||
final VerificationResponse statusRes = await verificationService
|
||||
.getStatus(verificationId);
|
||||
final String status = statusRes.status;
|
||||
if (status != 'PENDING' && status != 'QUEUED') {
|
||||
isFinished = true;
|
||||
}
|
||||
attempts++;
|
||||
|
||||
Reference in New Issue
Block a user