-
Notifications
You must be signed in to change notification settings - Fork 0
{model}Store を {model}Repositoryに変更 & CategoryFilterをFireStoreで #54
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
Open
ho2ri2s
wants to merge
6
commits into
master
Choose a base branch
from
rename/store-to-repository
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8dc4879
rename: store to repository
ho2ri2s 63b95ac
add: filteredArticle
ho2ri2s 7b7796a
refactor: article store to article repository
ho2ri2s ed61e33
rename
ho2ri2s be4378f
refactor: category store to category repository
ho2ri2s 71f1260
fix: like
ho2ri2s 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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| export 'api_repository.dart'; | ||
| export 'base_repository.dart'; | ||
| export 'api_client.dart'; | ||
| export 'base_client.dart'; | ||
| export 'custom_exception.dart'; | ||
| export 'entities/entities.dart'; | ||
| export 'firestore_repository.dart'; | ||
| export 'firestore_client.dart'; |
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,88 @@ | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:gottiesclient/models/entities/article.dart'; | ||
| import 'package:gottiesclient/models/models.dart'; | ||
| import 'package:gottiesclient/models/stores/stores.dart'; | ||
|
|
||
| class ArticleRepository extends ChangeNotifier { | ||
| ArticleRepository(LoginStore loginStore, BaseClient client) | ||
| : assert(client != null), | ||
| assert(loginStore != null), | ||
| _loginStore = loginStore, | ||
| _client = client { | ||
| getArticles(); | ||
| } | ||
|
|
||
| final BaseClient _client; | ||
| final LoginStore _loginStore; | ||
| List<Article> articles; | ||
|
|
||
| String get userID => _loginStore.user?.uid; | ||
|
|
||
| // TODO: try catchはStoreで | ||
| Future<void> getArticles() async { | ||
| articles = await _client.getArticles(); | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| Future<void> postArticle(String title, File before, File after, String body, String categoryId) async { | ||
| if (!_loginStore.isLoggedIn) { | ||
| await _loginStore.loginAnonymously(); | ||
| } | ||
| await _client.postArticle(title, before, after, body, categoryId, userID ?? ''); | ||
| } | ||
|
|
||
| Future<void> deleteArticle(Article article) async { | ||
| if (userID == article.userID) { | ||
| throw UnauthorisedException(); | ||
| } | ||
| await _client.deleteArticle(article.id, userID); | ||
| articles = articles.where((element) => element.id != article.id).toList(); | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| Future<void> likeArticle(String articleID) async { | ||
| if (userID == null) { | ||
| throw UnauthorisedException(); | ||
| } | ||
| await _client.likeArticle(userID, articleID); | ||
| articles.forEach((article) { | ||
| if (article.id == articleID) { | ||
| article.likeUserIds.add(_loginStore.user.uid); | ||
| } | ||
| }); | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| bool isLike(String articleId) { | ||
| if (userID == null) { | ||
| return false; | ||
| } | ||
| final article = articles.firstWhere((article) => article.id == articleId); | ||
| final isLike = article.likeUserIds.contains(userID); | ||
| return isLike; | ||
| } | ||
|
|
||
| Future<void> unlikeArticle(String articleID) async { | ||
| if (userID == null) { | ||
| throw UnauthorisedException(); | ||
| } | ||
| await _client.unlikeArticle(userID, articleID); | ||
| articles.forEach((article) { | ||
| if (article.id == articleID) { | ||
| article.likeUserIds.remove(userID); | ||
| } | ||
| }); | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| Future<void> filterArticles(Category category) async { | ||
| articles = await _client.getFilteredArticles(category.id); | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| bool isMyArticle(Article article) { | ||
| return article.userID == userID; | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なぜかファイルごとaddな差分になってしまってるけど、変更した箇所はここと、
それぞれのメソッドのtry-catchを一時的に外した感じ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今View に入ってる
RepositoryはふさわしいStoreで置き換えられる認識でいいよね?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そうやね!HomeStoreとかProfileStoreとかな感じ!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OKOK~