50 lines
1.5 KiB
Dart
50 lines
1.5 KiB
Dart
import 'dart:convert';
|
|
import '../constants/api_constants.dart';
|
|
import '../models/invitation_models.dart';
|
|
import 'http_service.dart';
|
|
|
|
class InvitationsService {
|
|
static Future<Map<String, dynamic>> getAllInvitations() async {
|
|
try {
|
|
final response = await HttpService.get(ApiConstants.getAllInvitationsEndpoint);
|
|
|
|
if (response.statusCode == 200) {
|
|
final responseData = jsonDecode(response.body);
|
|
final invitationsResponse = InvitationsResponse.fromJson(responseData);
|
|
|
|
if (invitationsResponse.status) {
|
|
return {
|
|
'success': true,
|
|
'data': invitationsResponse.data,
|
|
};
|
|
} else {
|
|
return {
|
|
'success': false,
|
|
'message': invitationsResponse.message ?? 'Failed to fetch invitations',
|
|
};
|
|
}
|
|
} else if (response.statusCode == 401) {
|
|
return {
|
|
'success': false,
|
|
'message': 'Session expired. Please login again.',
|
|
};
|
|
} else if (response.statusCode == 403) {
|
|
return {
|
|
'success': false,
|
|
'message': 'Access denied. Invalid credentials.',
|
|
};
|
|
} else {
|
|
return {
|
|
'success': false,
|
|
'message': 'Server error (${response.statusCode})',
|
|
};
|
|
}
|
|
} catch (e) {
|
|
print('Error fetching invitations: $e');
|
|
return {
|
|
'success': false,
|
|
'message': 'Network error. Please check your connection.',
|
|
};
|
|
}
|
|
}
|
|
} |