feat: Update API endpoint usage in repositories to remove redundant path property

- Refactored multiple repository implementations across client and staff features to directly use endpoint objects without accessing the `path` property.
- Introduced a new `FeatureGate` class for client-side feature gating based on user scopes, allowing for better access control to API endpoints.
- Added `ApiEndpoint` class to represent API endpoints with their paths and required scopes for future feature gating.
This commit is contained in:
Achintha Isuru
2026-03-17 12:01:06 -04:00
parent 57bba8ab4e
commit 376b4e4431
47 changed files with 240 additions and 139 deletions

View File

@@ -27,7 +27,7 @@ class CertificatesRepositoryImpl implements CertificatesRepository {
@override
Future<List<StaffCertificate>> getCertificates() async {
final ApiResponse response =
await _api.get(StaffEndpoints.certificates.path);
await _api.get(StaffEndpoints.certificates);
final List<dynamic> items =
response.data['certificates'] as List<dynamic>;
return items
@@ -73,7 +73,7 @@ class CertificatesRepositoryImpl implements CertificatesRepository {
// 4. Save certificate via V2 API
await _api.post(
StaffEndpoints.certificates.path,
StaffEndpoints.certificates,
data: <String, dynamic>{
'certificateType': certificateType,
'name': name,
@@ -95,7 +95,7 @@ class CertificatesRepositoryImpl implements CertificatesRepository {
@override
Future<void> deleteCertificate({required String certificateId}) async {
await _api.delete(
StaffEndpoints.certificateDelete(certificateId).path,
StaffEndpoints.certificateDelete(certificateId),
);
}
}

View File

@@ -27,7 +27,7 @@ class DocumentsRepositoryImpl implements DocumentsRepository {
@override
Future<List<ProfileDocument>> getDocuments() async {
final ApiResponse response =
await _api.get(StaffEndpoints.documents.path);
await _api.get(StaffEndpoints.documents);
final List<dynamic> items = response.data['documents'] as List<dynamic>;
return items
.map((dynamic json) =>
@@ -64,7 +64,7 @@ class DocumentsRepositoryImpl implements DocumentsRepository {
// 4. Submit upload result to V2 API
await _api.put(
StaffEndpoints.documentUpload(documentId).path,
StaffEndpoints.documentUpload(documentId),
data: <String, dynamic>{
'fileUri': signedUrlRes.signedUrl,
'verificationId': verificationRes.verificationId,

View File

@@ -18,7 +18,7 @@ class TaxFormsRepositoryImpl implements TaxFormsRepository {
@override
Future<List<TaxForm>> getTaxForms() async {
final ApiResponse response =
await _api.get(StaffEndpoints.taxForms.path);
await _api.get(StaffEndpoints.taxForms);
final List<dynamic> items = response.data['taxForms'] as List<dynamic>;
return items
.map((dynamic json) =>
@@ -29,7 +29,7 @@ class TaxFormsRepositoryImpl implements TaxFormsRepository {
@override
Future<void> updateTaxForm(TaxForm form) async {
await _api.put(
StaffEndpoints.taxFormUpdate(form.formType).path,
StaffEndpoints.taxFormUpdate(form.formType),
data: form.toJson(),
);
}
@@ -37,7 +37,7 @@ class TaxFormsRepositoryImpl implements TaxFormsRepository {
@override
Future<void> submitTaxForm(TaxForm form) async {
await _api.post(
StaffEndpoints.taxFormSubmit(form.formType).path,
StaffEndpoints.taxFormSubmit(form.formType),
data: form.toJson(),
);
}

View File

@@ -16,7 +16,7 @@ class BankAccountRepositoryImpl implements BankAccountRepository {
@override
Future<List<BankAccount>> getAccounts() async {
final ApiResponse response =
await _api.get(StaffEndpoints.bankAccounts.path);
await _api.get(StaffEndpoints.bankAccounts);
final List<dynamic> items = response.data['accounts'] as List<dynamic>;
return items
.map((dynamic json) =>
@@ -27,7 +27,7 @@ class BankAccountRepositoryImpl implements BankAccountRepository {
@override
Future<void> addAccount(BankAccount account) async {
await _api.post(
StaffEndpoints.bankAccounts.path,
StaffEndpoints.bankAccounts,
data: account.toJson(),
);
}

View File

@@ -16,7 +16,7 @@ class TimeCardRepositoryImpl implements TimeCardRepository {
@override
Future<List<TimeCardEntry>> getTimeCards(DateTime month) async {
final ApiResponse response = await _api.get(
StaffEndpoints.timeCard.path,
StaffEndpoints.timeCard,
params: <String, dynamic>{
'year': month.year,
'month': month.month,

View File

@@ -27,7 +27,7 @@ class AttireRepositoryImpl implements AttireRepository {
@override
Future<List<AttireChecklist>> getAttireOptions() async {
final ApiResponse response = await _api.get(StaffEndpoints.attire.path);
final ApiResponse response = await _api.get(StaffEndpoints.attire);
final List<dynamic> items = response.data['items'] as List<dynamic>;
return items
.map((dynamic json) =>
@@ -100,7 +100,7 @@ class AttireRepositoryImpl implements AttireRepository {
// 5. Update attire item via V2 API
await _api.put(
StaffEndpoints.attireUpload(itemId).path,
StaffEndpoints.attireUpload(itemId),
data: <String, dynamic>{
'photoUrl': photoUrl,
'verificationId': verifyRes.verificationId,

View File

@@ -17,7 +17,7 @@ class EmergencyContactRepositoryImpl
@override
Future<List<EmergencyContact>> getContacts() async {
final ApiResponse response =
await _api.get(StaffEndpoints.emergencyContacts.path);
await _api.get(StaffEndpoints.emergencyContacts);
final List<dynamic> items = response.data['contacts'] as List<dynamic>;
return items
.map((dynamic json) =>
@@ -28,7 +28,7 @@ class EmergencyContactRepositoryImpl
@override
Future<void> saveContacts(List<EmergencyContact> contacts) async {
await _api.put(
StaffEndpoints.emergencyContacts.path,
StaffEndpoints.emergencyContacts,
data: <String, dynamic>{
'contacts':
contacts.map((EmergencyContact c) => c.toJson()).toList(),

View File

@@ -16,14 +16,14 @@ class ExperienceRepositoryImpl implements ExperienceRepositoryInterface {
@override
Future<List<String>> getIndustries() async {
final ApiResponse response =
await _api.get(StaffEndpoints.industries.path);
await _api.get(StaffEndpoints.industries);
final List<dynamic> items = response.data['industries'] as List<dynamic>;
return items.map((dynamic e) => e.toString()).toList();
}
@override
Future<List<String>> getSkills() async {
final ApiResponse response = await _api.get(StaffEndpoints.skills.path);
final ApiResponse response = await _api.get(StaffEndpoints.skills);
final List<dynamic> items = response.data['skills'] as List<dynamic>;
return items.map((dynamic e) => e.toString()).toList();
}
@@ -34,7 +34,7 @@ class ExperienceRepositoryImpl implements ExperienceRepositoryInterface {
List<String> skills,
) async {
await _api.put(
StaffEndpoints.personalInfo.path,
StaffEndpoints.personalInfo,
data: <String, dynamic>{
'industries': industries,
'skills': skills,

View File

@@ -28,7 +28,7 @@ class PersonalInfoRepositoryImpl implements PersonalInfoRepositoryInterface {
@override
Future<StaffPersonalInfo> getStaffProfile() async {
final ApiResponse response =
await _api.get(StaffEndpoints.personalInfo.path);
await _api.get(StaffEndpoints.personalInfo);
final Map<String, dynamic> json =
response.data as Map<String, dynamic>;
return StaffPersonalInfo.fromJson(json);
@@ -40,7 +40,7 @@ class PersonalInfoRepositoryImpl implements PersonalInfoRepositoryInterface {
required Map<String, dynamic> data,
}) async {
final ApiResponse response = await _api.put(
StaffEndpoints.personalInfo.path,
StaffEndpoints.personalInfo,
data: data,
);
final Map<String, dynamic> json =
@@ -65,7 +65,7 @@ class PersonalInfoRepositoryImpl implements PersonalInfoRepositoryInterface {
// 3. Submit the photo URL to the V2 API.
await _api.post(
StaffEndpoints.profilePhoto.path,
StaffEndpoints.profilePhoto,
data: <String, dynamic>{
'fileUri': uploadRes.fileUri,
'photoUrl': photoUrl,

View File

@@ -18,7 +18,7 @@ class FaqsRepositoryImpl implements FaqsRepositoryInterface {
Future<List<FaqCategory>> getFaqs() async {
try {
final ApiResponse response =
await _apiService.get(StaffEndpoints.faqs.path);
await _apiService.get(StaffEndpoints.faqs);
return _parseCategories(response);
} catch (_) {
return <FaqCategory>[];
@@ -29,7 +29,7 @@ class FaqsRepositoryImpl implements FaqsRepositoryInterface {
Future<List<FaqCategory>> searchFaqs(String query) async {
try {
final ApiResponse response = await _apiService.get(
StaffEndpoints.faqsSearch.path,
StaffEndpoints.faqsSearch,
params: <String, dynamic>{'q': query},
);
return _parseCategories(response);

View File

@@ -19,7 +19,7 @@ class PrivacySettingsRepositoryImpl
@override
Future<bool> getProfileVisibility() async {
final ApiResponse response =
await _api.get(StaffEndpoints.privacy.path);
await _api.get(StaffEndpoints.privacy);
final Map<String, dynamic> json =
response.data as Map<String, dynamic>;
final PrivacySettings settings = PrivacySettings.fromJson(json);
@@ -29,7 +29,7 @@ class PrivacySettingsRepositoryImpl
@override
Future<bool> updateProfileVisibility(bool isVisible) async {
await _api.put(
StaffEndpoints.privacy.path,
StaffEndpoints.privacy,
data: <String, dynamic>{'profileVisible': isVisible},
);
return isVisible;