Define a collection service
This commit is contained in:
parent
ad8bca7fe7
commit
c9342e9cc8
2 changed files with 38 additions and 1 deletions
|
@ -24,7 +24,7 @@ class Collection {
|
|||
);
|
||||
|
||||
static Collection emptyCollection() {
|
||||
return Collection(null, null, null, null, null, null, null, null);
|
||||
return Collection(null, null, null, null, null, null, null, List<String>());
|
||||
}
|
||||
|
||||
Collection copyWith({
|
||||
|
|
|
@ -1,5 +1,42 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/events/user_authenticated_event.dart';
|
||||
import 'package:photos/models/collection.dart';
|
||||
|
||||
class CollectionsService {
|
||||
final _logger = Logger("CollectionsService");
|
||||
|
||||
CollectionsService._privateConstructor() {
|
||||
Bus.instance.on<UserAuthenticatedEvent>().listen((event) {
|
||||
// TODO: sync();
|
||||
});
|
||||
}
|
||||
|
||||
static final CollectionsService instance =
|
||||
CollectionsService._privateConstructor();
|
||||
|
||||
Future<Collection> getFolder(String path) async {
|
||||
return Dio()
|
||||
.get(
|
||||
Configuration.instance.getHttpEndpoint() + "/collections/folder/",
|
||||
queryParameters: {
|
||||
"path": path,
|
||||
},
|
||||
options:
|
||||
Options(headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||
)
|
||||
.then((response) {
|
||||
return Collection.fromMap(response.data);
|
||||
}).catchError((e) {
|
||||
if (e.response.statusCode == HttpStatus.notFound) {
|
||||
return Collection.emptyCollection();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue