74 lines
2.1 KiB
Dart
74 lines
2.1 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:injectable/injectable.dart';
|
|
import 'package:remever/common/services/api_client.dart';
|
|
import 'package:remever/database/database.dart';
|
|
import 'package:remever/inject.dart';
|
|
import 'package:remever/models/crud_collection_dto.dart';
|
|
import 'package:remever/services/collection/collections_interface.dart';
|
|
|
|
///
|
|
/// Сервис авторизации
|
|
///
|
|
|
|
@Singleton(as: CollectionsInterface)
|
|
final class CollectionsService implements CollectionsInterface {
|
|
@override
|
|
Stream<List<Collection>> watchCollectionsList({String? search}) {
|
|
return getIt<AppDatabase>().collectionsDao.getCollections(search);
|
|
}
|
|
|
|
@override
|
|
Future<void> createCollection(CrudCollectionDto dto) async {
|
|
return await getIt<AppDatabase>().collectionsDao.createCollection(dto);
|
|
}
|
|
|
|
@override
|
|
Future<void> updateCollection(CrudCollectionDto dto, String id) async {
|
|
return await getIt<AppDatabase>().collectionsDao.updateCollection(dto, id);
|
|
}
|
|
|
|
@override
|
|
Future<void> deleteCollection(String id) async {
|
|
return await getIt<AppDatabase>().collectionsDao.deleteCollection(id);
|
|
}
|
|
|
|
@override
|
|
Future<bool> makeCollectionPublic(String id, bool isPublic) {
|
|
// TODO: implement makeCollectionPublic
|
|
throw UnimplementedError();
|
|
}
|
|
|
|
@override
|
|
Future<void> getCollectionsFromApi() async {
|
|
try {
|
|
final Response<dynamic> response = await apiClient.get(
|
|
'/collections',
|
|
queryParameters: <String, dynamic>{'perPage': 20, 'page': 1},
|
|
);
|
|
|
|
print('data');
|
|
} catch (e) {
|
|
print('Response error $e');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> createCollectionApi() async {
|
|
try {
|
|
final Response<dynamic> response = await apiClient.post(
|
|
'/collections',
|
|
data: {
|
|
"title": "Основы программирования для утюгов",
|
|
"description":
|
|
"Коллекция карточек по основам программирования для начинающих",
|
|
"is_public": true,
|
|
},
|
|
);
|
|
|
|
print('data');
|
|
} catch (e) {
|
|
print('Response error $e');
|
|
}
|
|
}
|
|
}
|