refactor(apps): simplify API layer by removing redundant wrapper classes
- Remove ApiClientWrapper and MockApiClientWrapper - Simplify IApiClient interface - Update dependency injection configuration - Optimize calendar service and AG-UI chat models
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import 'package:social_app/core/config/env.dart';
|
||||
import 'package:social_app/core/api/i_api_client.dart';
|
||||
import '../models/schedule_item_model.dart';
|
||||
|
||||
class MockCalendarService {
|
||||
@@ -56,54 +56,50 @@ class MockCalendarService {
|
||||
}
|
||||
|
||||
class CalendarService {
|
||||
static final CalendarService _instance = CalendarService._internal();
|
||||
factory CalendarService() => _instance;
|
||||
CalendarService._internal();
|
||||
final IApiClient? _apiClient;
|
||||
final MockCalendarService _mock = MockCalendarService();
|
||||
|
||||
MockCalendarService get _mock => MockCalendarService();
|
||||
CalendarService({IApiClient? apiClient}) : _apiClient = apiClient;
|
||||
|
||||
List<ScheduleItemModel> getEventsForDay(DateTime date) {
|
||||
if (Env.isMockApi) {
|
||||
return _mock.getEventsForDay(date);
|
||||
if (_apiClient != null) {
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
}
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
return _mock.getEventsForDay(date);
|
||||
}
|
||||
|
||||
List<ScheduleItemModel> getEventsForRange(DateTime start, DateTime end) {
|
||||
if (Env.isMockApi) {
|
||||
return _mock.getEventsForRange(start, end);
|
||||
if (_apiClient != null) {
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
}
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
return _mock.getEventsForRange(start, end);
|
||||
}
|
||||
|
||||
ScheduleItemModel? getEventById(String id) {
|
||||
if (Env.isMockApi) {
|
||||
return _mock.getEventById(id);
|
||||
if (_apiClient != null) {
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
}
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
return _mock.getEventById(id);
|
||||
}
|
||||
|
||||
void addEvent(ScheduleItemModel event) {
|
||||
if (Env.isMockApi) {
|
||||
_mock.addEvent(event);
|
||||
return;
|
||||
if (_apiClient != null) {
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
}
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
_mock.addEvent(event);
|
||||
}
|
||||
|
||||
void updateEvent(ScheduleItemModel event) {
|
||||
if (Env.isMockApi) {
|
||||
_mock.updateEvent(event);
|
||||
return;
|
||||
if (_apiClient != null) {
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
}
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
_mock.updateEvent(event);
|
||||
}
|
||||
|
||||
void deleteEvent(String id) {
|
||||
if (Env.isMockApi) {
|
||||
_mock.deleteEvent(id);
|
||||
return;
|
||||
if (_apiClient != null) {
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
}
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
_mock.deleteEvent(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user