50 lines
1.4 KiB
Dart
50 lines
1.4 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import '../../core/error/exceptions.dart';
|
|
import '../../core/network/api_client.dart';
|
|
import '../dto/theme_response_dto.dart';
|
|
|
|
abstract class ThemeRemoteDataSource {
|
|
Future<ThemeDataDto> getTheme();
|
|
}
|
|
|
|
class ThemeRemoteDataSourceImpl implements ThemeRemoteDataSource {
|
|
final ApiClient apiClient;
|
|
|
|
ThemeRemoteDataSourceImpl({required this.apiClient});
|
|
|
|
@override
|
|
Future<ThemeDataDto> getTheme() async {
|
|
try {
|
|
debugPrint('[ThemeDataSource] Calling GET /Theme (with auth)...');
|
|
|
|
final res = await apiClient.get('/Theme'); // ✅ no custom headers
|
|
|
|
debugPrint('[ThemeDataSource] Status: ${res.statusCode}');
|
|
debugPrint('[ThemeDataSource] Data: ${res.data}');
|
|
|
|
if (res.statusCode == 200) {
|
|
final dto = ThemeResponseDto.fromJson(
|
|
Map<String, dynamic>.from(res.data),
|
|
);
|
|
|
|
if (dto.isSuccess && dto.data != null) {
|
|
debugPrint('[ThemeDataSource] ✅ logo = ${dto.data!.logo}');
|
|
return dto.data!;
|
|
}
|
|
|
|
throw ServerException(message: dto.message ?? 'Theme request failed');
|
|
}
|
|
|
|
throw ServerException(
|
|
message: 'Theme request failed (code ${res.statusCode})',
|
|
);
|
|
} on ServerException {
|
|
rethrow;
|
|
} catch (e, stack) {
|
|
debugPrint('[ThemeDataSource] ❌ Exception: $e');
|
|
debugPrint('[ThemeDataSource] ❌ Stack: $stack');
|
|
throw ServerException(message: e.toString());
|
|
}
|
|
}
|
|
}
|