abdicate object assigning responsibility

The ImagesService itself handles the conversion of Json to the object itself, instead of the ImagesApi
This commit is contained in:
Mguy13 2022-12-24 00:32:53 +01:00
parent a0ed894016
commit 6a84a9bef0
9 changed files with 255 additions and 25 deletions

View file

@ -42,7 +42,8 @@ class ImagesService {
Future<void> _init() async {
_loggingService.info('Fetching and creating image models...');
_imageModels = {
for (final imageModel in await _imagesApi.fetchImageUri(token: ''))
for (final imageModel in (await _imagesApi.fetchImageUri(token: ''))
.map((final emulatedModelSerialized) => ImageModel.fromJson(emulatedModelSerialized)))
imageModel.imageName: imageModel
};
@ -90,10 +91,13 @@ class ImagesService {
..reversed;
return _imageModels.valuesByKeys(keys: rankedKeys).toList(growable: false);
case SearchOption.web:
return await _imagesApi.searchImages(
return (await _imagesApi.searchImages(
searchStr: imageNamePart,
token: '',
);
))
.map(
(final emulatedModelSerialized) => ImageModel.fromJson(emulatedModelSerialized))
.toList(growable: false);
}
} finally {
unlock();