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

@@ -34,7 +34,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
required DateTime end,
}) async {
final ApiResponse response = await _apiService.get(
StaffEndpoints.shiftsAssigned.path,
StaffEndpoints.shiftsAssigned,
params: <String, dynamic>{
'startDate': start.toIso8601String(),
'endDate': end.toIso8601String(),
@@ -59,7 +59,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
params['search'] = search;
}
final ApiResponse response = await _apiService.get(
StaffEndpoints.shiftsOpen.path,
StaffEndpoints.shiftsOpen,
params: params,
);
final List<dynamic> items = _extractItems(response.data);
@@ -72,7 +72,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
@override
Future<List<PendingAssignment>> getPendingAssignments() async {
final ApiResponse response =
await _apiService.get(StaffEndpoints.shiftsPending.path);
await _apiService.get(StaffEndpoints.shiftsPending);
final List<dynamic> items = _extractItems(response.data);
return items
.map((dynamic json) =>
@@ -83,7 +83,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
@override
Future<List<CancelledShift>> getCancelledShifts() async {
final ApiResponse response =
await _apiService.get(StaffEndpoints.shiftsCancelled.path);
await _apiService.get(StaffEndpoints.shiftsCancelled);
final List<dynamic> items = _extractItems(response.data);
return items
.map((dynamic json) =>
@@ -94,7 +94,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
@override
Future<List<CompletedShift>> getCompletedShifts() async {
final ApiResponse response =
await _apiService.get(StaffEndpoints.shiftsCompleted.path);
await _apiService.get(StaffEndpoints.shiftsCompleted);
final List<dynamic> items = _extractItems(response.data);
return items
.map((dynamic json) =>
@@ -105,7 +105,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
@override
Future<ShiftDetail?> getShiftDetail(String shiftId) async {
final ApiResponse response =
await _apiService.get(StaffEndpoints.shiftDetails(shiftId).path);
await _apiService.get(StaffEndpoints.shiftDetails(shiftId));
if (response.data == null) {
return null;
}
@@ -119,7 +119,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
bool instantBook = false,
}) async {
await _apiService.post(
StaffEndpoints.shiftApply(shiftId).path,
StaffEndpoints.shiftApply(shiftId),
data: <String, dynamic>{
if (roleId != null) 'roleId': roleId,
'instantBook': instantBook,
@@ -129,18 +129,18 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
@override
Future<void> acceptShift(String shiftId) async {
await _apiService.post(StaffEndpoints.shiftAccept(shiftId).path);
await _apiService.post(StaffEndpoints.shiftAccept(shiftId));
}
@override
Future<void> declineShift(String shiftId) async {
await _apiService.post(StaffEndpoints.shiftDecline(shiftId).path);
await _apiService.post(StaffEndpoints.shiftDecline(shiftId));
}
@override
Future<void> requestSwap(String shiftId, {String? reason}) async {
await _apiService.post(
StaffEndpoints.shiftRequestSwap(shiftId).path,
StaffEndpoints.shiftRequestSwap(shiftId),
data: <String, dynamic>{
if (reason != null) 'reason': reason,
},
@@ -150,7 +150,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
@override
Future<bool> getProfileCompletion() async {
final ApiResponse response =
await _apiService.get(StaffEndpoints.profileCompletion.path);
await _apiService.get(StaffEndpoints.profileCompletion);
final Map<String, dynamic> data = response.data as Map<String, dynamic>;
final ProfileCompletion completion = ProfileCompletion.fromJson(data);
return completion.completed;