-
Notifications
You must be signed in to change notification settings - Fork 0
[Issue 20]: Tag a book as favorite #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0591b12
[feat](pnalvarez): added new favorite icon and saving favorite books …
pnalvarez 605c795
[feat](pnalvarez): created FavoriteRepository with unit tests
pnalvarez 90f896a
[feat](pnalvarez): added favorite button to book details page
pnalvarez c1f8025
[fix](pnalvarez): removed comment
pnalvarez 0c5511b
[refactor](pnalvarez): removed unused imports
pnalvarez 2363f9b
[refactor](pnalvarez): code review
pnalvarez 688d315
[fix](pnalvarez): FavoriteItemUI is freezed
pnalvarez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import 'package:injectable/injectable.dart'; | ||
| import 'package:mibook/layers/data/api/storage_client.dart'; | ||
| import 'package:mibook/layers/data/models/book_list_data.dart'; | ||
|
|
||
| abstract class IFavoriteDataSource { | ||
| Future<void> setFavoriteStatus(BookItem book, bool isFavorite); | ||
| Future<bool> getFavoriteStatus(String bookId); | ||
| Future<List<BookItem>> getFavoriteBooks(); | ||
| } | ||
|
|
||
| @LazySingleton(as: IFavoriteDataSource) | ||
| class FavoriteDataSource implements IFavoriteDataSource { | ||
| final IStorageClient storageClient; | ||
|
|
||
| FavoriteDataSource(this.storageClient); | ||
|
|
||
| @override | ||
| Future<void> setFavoriteStatus(BookItem book, bool isFavorite) async { | ||
| await storageClient.setFavoriteStatus(book, isFavorite); | ||
| } | ||
|
|
||
| @override | ||
| Future<bool> getFavoriteStatus(String bookId) async { | ||
| return await storageClient.getFavoriteStatus(bookId); | ||
| } | ||
|
|
||
| @override | ||
| Future<List<BookItem>> getFavoriteBooks() async { | ||
| return await storageClient.getFavoriteBooks(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import 'package:injectable/injectable.dart'; | ||
| import 'package:mibook/layers/data/datasource/favorite_data_source.dart'; | ||
| import 'package:mibook/layers/data/models/book_list_data.dart'; | ||
| import 'package:mibook/layers/domain/models/book_list_domain.dart'; | ||
| import 'package:mibook/layers/domain/repository/favorite_repository.dart'; | ||
|
|
||
| @LazySingleton(as: IFavoriteRepository) | ||
| class FavoriteRepository implements IFavoriteRepository { | ||
| final IFavoriteDataSource _dataSource; | ||
|
|
||
| FavoriteRepository(this._dataSource); | ||
|
|
||
| @override | ||
| Future<List<BookDomain>> getFavoriteBooks() async => | ||
| _dataSource.getFavoriteBooks().then( | ||
| (dataBooks) => dataBooks.map((e) => e.toDomain()).toList(), | ||
| ); | ||
|
|
||
| @override | ||
| Future<bool> getFavoriteStatus(String bookId) async => | ||
| _dataSource.getFavoriteStatus(bookId); | ||
|
|
||
| @override | ||
| Future<void> setFavoriteStatus(BookDomain book, bool isFavorite) async => | ||
| _dataSource.setFavoriteStatus(BookItem.fromDomain(book), isFavorite); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,23 @@ | ||
| class BookListDomain { | ||
| final int totalItems; | ||
| final List<BookDomain> books; | ||
| import 'package:freezed_annotation/freezed_annotation.dart'; | ||
| part 'book_list_domain.freezed.dart'; | ||
|
|
||
| BookListDomain({ | ||
| required this.totalItems, | ||
| required this.books, | ||
| }); | ||
| @freezed | ||
| class BookListDomain with _$BookListDomain { | ||
| const factory BookListDomain({ | ||
| required int totalItems, | ||
| required List<BookDomain> books, | ||
| }) = _BookListDomain; | ||
| } | ||
|
|
||
| class BookDomain { | ||
| final String id; | ||
| final String kind; | ||
| final String title; | ||
| final List<String>? authors; | ||
| final String? description; | ||
| final String? thumbnail; | ||
| final int pageCount; | ||
|
|
||
| BookDomain({ | ||
| required this.id, | ||
| required this.kind, | ||
| required this.title, | ||
| required this.authors, | ||
| required this.description, | ||
| required this.thumbnail, | ||
| required this.pageCount, | ||
| }); | ||
| @freezed | ||
| class BookDomain with _$BookDomain { | ||
| const factory BookDomain({ | ||
| required String id, | ||
| required String kind, | ||
| required String title, | ||
| @Default([]) List<String> authors, | ||
| String? description, | ||
| String? thumbnail, | ||
| @Default(0) int pageCount, | ||
| }) = _BookDomain; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import 'package:mibook/layers/domain/models/book_list_domain.dart'; | ||
|
|
||
| abstract class IFavoriteRepository { | ||
| Future<void> setFavoriteStatus(BookDomain book, bool isFavorite); | ||
| Future<bool> getFavoriteStatus(String bookId); | ||
| Future<List<BookDomain>> getFavoriteBooks(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import 'package:injectable/injectable.dart'; | ||
| import 'package:mibook/layers/domain/repository/favorite_repository.dart'; | ||
|
|
||
| abstract class IGetFavorite { | ||
| Future<bool> call(String id); | ||
| } | ||
|
|
||
| @LazySingleton(as: IGetFavorite) | ||
| class GetFavorite implements IGetFavorite { | ||
gabrielbmoro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| final IFavoriteRepository _favoriteRepository; | ||
|
|
||
| GetFavorite(this._favoriteRepository); | ||
gabrielbmoro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @override | ||
| Future<bool> call(String id) async => | ||
| await _favoriteRepository.getFavoriteStatus(id); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.