-
Notifications
You must be signed in to change notification settings - Fork 0
[FIX] 게시물 북마크 버그 수정 #265
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
ryusuye0n
wants to merge
4
commits into
develop
Choose a base branch
from
feature/#264-bookmark-bug-fix
base: develop
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
[FIX] 게시물 북마크 버그 수정 #265
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,11 @@ | ||
| class BookmarkChangedEvent { | ||
| final int postId; | ||
| final bool isBookmarked; | ||
| final int bookmarkCount; | ||
|
|
||
| BookmarkChangedEvent({ | ||
| required this.postId, | ||
| required this.isBookmarked, | ||
| required this.bookmarkCount, | ||
| }); | ||
| } |
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,11 @@ | ||
| import 'package:ondo/domain/repositories/post/post_repository.dart'; | ||
|
|
||
| class BookmarkedPostUseCase { | ||
| final PostRepository _repository; | ||
|
|
||
| BookmarkedPostUseCase(this._repository); | ||
|
|
||
| Future<bool> call(int postId) { | ||
| return _repository.bookmarkedPost(postId); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
lib/domain/usecases/post/save_post_bookmark_local_use_case.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,11 @@ | ||
| import 'package:ondo/domain/repositories/post/post_repository.dart'; | ||
|
|
||
| class SavePostBookmarkLocalUseCase { | ||
| final PostRepository _repository; | ||
|
|
||
| SavePostBookmarkLocalUseCase(this._repository); | ||
|
|
||
| Future<void> call(int postId, bool isBookmarked) { | ||
| return _repository.saveBookmarkState(postId, isBookmarked); | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -9,6 +9,10 @@ import 'package:ondo/domain/usecases/post/post_search_use_case.dart'; | |
| import 'package:ondo/domain/usecases/post/save_post_like_local_use_case.dart'; | ||
| import 'package:ondo/domain/usecases/post/unlike_post_usecase.dart'; | ||
| import 'package:ondo/domain/usecases/post/update_post_usecase.dart'; | ||
| import 'package:ondo/domain/usecases/post/bookmark_post_usecase.dart'; | ||
| import 'package:ondo/domain/usecases/post/unbookmark_post_usecase.dart'; | ||
| import 'package:ondo/domain/usecases/post/bookmarked_post_use_case.dart'; | ||
| import 'package:ondo/domain/usecases/post/save_post_bookmark_local_use_case.dart'; | ||
| import 'package:ondo/presentation/community/controllers/community_post_create_screen_controller.dart'; | ||
| import 'package:ondo/presentation/community/screens/community_post_create_screen.dart'; | ||
| import 'package:ondo/presentation/post/controllers/post_controller.dart'; | ||
|
|
@@ -19,6 +23,10 @@ class CommunityController extends GetxController { | |
| final LoadRecommendPostListUseCase _getRecommendPostsUseCase; | ||
| final SavePostLikeLocalUseCase _savePostLikeLocalUseCase; | ||
| final LikedPostUseCase _likedPostUseCase; | ||
| final BookmarkPostUseCase _bookmarkUseCase; | ||
| final UnbookmarkPostUseCase _unbookmarkUseCase; | ||
| final SavePostBookmarkLocalUseCase _savePostBookmarkLocalUseCase; | ||
| final BookmarkedPostUseCase _bookmarkedPostUseCase; | ||
| final PostSearchUseCase _postSearchUseCase; | ||
|
|
||
| CommunityController({ | ||
|
|
@@ -27,12 +35,20 @@ class CommunityController extends GetxController { | |
| required LoadRecommendPostListUseCase getRecommendPostsUseCase, | ||
| required SavePostLikeLocalUseCase savePostLikeLocalUseCase, | ||
| required LikedPostUseCase likedPostUseCase, | ||
| required BookmarkPostUseCase bookmarkUseCase, | ||
| required UnbookmarkPostUseCase unbookmarkUseCase, | ||
| required SavePostBookmarkLocalUseCase savePostBookmarkLocalUseCase, | ||
| required BookmarkedPostUseCase bookmarkedPostUseCase, | ||
| required PostSearchUseCase postSearchUseCase, | ||
| }) : _likeUseCase = likeUseCase, | ||
| _unlikeUseCase = unlikeUseCase, | ||
| _getRecommendPostsUseCase = getRecommendPostsUseCase, | ||
| _savePostLikeLocalUseCase = savePostLikeLocalUseCase, | ||
| _likedPostUseCase = likedPostUseCase, | ||
| _bookmarkUseCase = bookmarkUseCase, | ||
| _unbookmarkUseCase = unbookmarkUseCase, | ||
| _savePostBookmarkLocalUseCase = savePostBookmarkLocalUseCase, | ||
| _bookmarkedPostUseCase = bookmarkedPostUseCase, | ||
| _postSearchUseCase = postSearchUseCase; | ||
|
|
||
| final RxSet<String> viewTagList = <String>{}.obs; | ||
|
|
@@ -60,6 +76,15 @@ class CommunityController extends GetxController { | |
| _syncLike(event.postId, event.isLiked, event.likeCount); | ||
| }, | ||
| ); | ||
|
|
||
| ever( | ||
| Get.find<PostController>().lastBookmarkEvent, | ||
| (event) { | ||
| if (event == null) return; | ||
| _syncBookmark(event.postId, event.isBookmarked, event.bookmarkCount); | ||
| }, | ||
| ); | ||
|
|
||
| ever( | ||
| Get.find<PostController>().lastDeleteEvent, | ||
| (postId) { | ||
|
|
@@ -93,6 +118,25 @@ class CommunityController extends GetxController { | |
| } | ||
| } | ||
|
|
||
| void _syncBookmark(int postId, bool isBookmarked, int bookmarkCount) { | ||
| final index = viewPostList.indexWhere((p) => p.postId == postId); | ||
| if (index != -1) { | ||
| viewPostList[index] = viewPostList[index].copyWith( | ||
| bookmarkCount: bookmarkCount, | ||
| isBookmark: isBookmarked, | ||
| ); | ||
| viewPostList.refresh(); | ||
| } | ||
|
|
||
| final cacheIndex = _cachePostList.indexWhere((p) => p.postId == postId); | ||
| if (cacheIndex != -1) { | ||
| _cachePostList[cacheIndex] = _cachePostList[cacheIndex].copyWith( | ||
| bookmarkCount: bookmarkCount, | ||
| isBookmark: isBookmarked, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| void onReady() { | ||
| Get.put(CommunityResultController()); | ||
|
|
@@ -122,6 +166,7 @@ class CommunityController extends GetxController { | |
| result.content.map((post) async { | ||
| return post.copyWith( | ||
| isFavorite: await _likedPostUseCase(post.postId), | ||
| isBookmark: await _bookmarkedPostUseCase(post.postId), | ||
| ); | ||
| }), | ||
| ); | ||
|
|
@@ -192,6 +237,41 @@ class CommunityController extends GetxController { | |
| } | ||
| } | ||
|
|
||
| Future<void> toggleBookmark(int postId, bool isBookmarked) async { | ||
| _updatePostBookmarkInList(postId, isBookmarked ? 1 : -1, isBookmarked); | ||
|
|
||
| try { | ||
| if (isBookmarked) { | ||
| await _bookmarkUseCase(postId); | ||
| } else { | ||
| await _unbookmarkUseCase(postId); | ||
| } | ||
| await _savePostBookmarkLocalUseCase(postId, isBookmarked); | ||
| } catch (e) { | ||
| debugPrint('[CommunityController] 북마크 토글 실패 - error: $e'); | ||
| _updatePostBookmarkInList(postId, isBookmarked ? -1 : 1, !isBookmarked); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굳이 빼는 값을 함수의 인자로 넘기는 것 보다는, |
||
| } | ||
| } | ||
|
|
||
| void _updatePostBookmarkInList(int postId, int delta, bool isBookmark) { | ||
| final index = viewPostList.indexWhere((p) => p.postId == postId); | ||
| if (index != -1) { | ||
| viewPostList[index] = viewPostList[index].copyWith( | ||
| bookmarkCount: viewPostList[index].bookmarkCount + delta, | ||
| isBookmark: isBookmark, | ||
| ); | ||
| viewPostList.refresh(); | ||
| } | ||
|
|
||
| final cacheIndex = _cachePostList.indexWhere((p) => p.postId == postId); | ||
| if (cacheIndex != -1) { | ||
| _cachePostList[cacheIndex] = _cachePostList[cacheIndex].copyWith( | ||
| bookmarkCount: _cachePostList[cacheIndex].bookmarkCount + delta, | ||
| isBookmark: isBookmark, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| void removePost(int postId) { | ||
| viewPostList.removeWhere((p) => p.postId == postId); | ||
| _cachePostList.removeWhere((p) => p.postId == postId); | ||
|
|
||
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.
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.