create promocode page
This commit is contained in:
@@ -1150,4 +1150,31 @@ class ApiService {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> applyPromoCode(String code) async {
|
||||
final token = await _securityService.getAccessToken();
|
||||
if (token == null) throw Exception('No access token');
|
||||
|
||||
final response = await _dio.post(
|
||||
'$baseUrl/promocode/apply',
|
||||
data: {'code': code},
|
||||
options: Options(
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 201 || response.statusCode == 200) {
|
||||
return response.data;
|
||||
} else if (response.statusCode == 404) {
|
||||
throw PromoCodeNotFoundException();
|
||||
} else {
|
||||
throw Exception('API Error: ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ Добавь исключение (можно в отдельный файл)
|
||||
class PromoCodeNotFoundException implements Exception {}
|
||||
|
||||
Reference in New Issue
Block a user