From 314f9b0ee348a392fa3fa42ed3893fe9f33bc44b Mon Sep 17 00:00:00 2001 From: Saurabh kumar Date: Mon, 28 Feb 2022 17:31:35 +0530 Subject: [PATCH 1/3] - updated API calls for post and comment repo - added API calls for File repo --- .dart_tool/package_config.json | 2 +- lib/core/constant/global_constant.dart | 1 + .../model/api_request/get_post_request.dart | 78 ++++++++++++++++++ .../comment_db_adater_impl.dart | 2 +- .../api_interface/commnet_api_interface.dart | 8 ++ .../api_interface/file_api_interface.dart | 10 ++- .../public_post_api_interface.dart | 12 ++- .../commant_api_interface_impl.dart | 60 ++++++++++++++ .../file_api_interface_impl.dart | 39 ++++++++- .../public_post_api_interface_impl.dart | 71 ++++++++++++++++ lib/data/repo_impl/comment_repo_impl.dart | 82 +++++++++++-------- lib/data/repo_impl/post_repo_impl.dart | 58 +++++++++++-- lib/domain/repo/comment_repo.dart | 9 ++ lib/domain/repo/post_repo.dart | 9 ++ .../remove_reaction_query_builder.dart | 2 +- 15 files changed, 398 insertions(+), 45 deletions(-) create mode 100644 lib/core/model/api_request/get_post_request.dart diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 9f32b8a9..c76a89e7 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -530,7 +530,7 @@ "languageVersion": "2.15" } ], - "generated": "2022-02-27T12:21:18.149516Z", + "generated": "2022-02-28T09:24:40.836846Z", "generator": "pub", "generatorVersion": "2.16.0" } diff --git a/lib/core/constant/global_constant.dart b/lib/core/constant/global_constant.dart index b5b343ba..c2000f73 100644 --- a/lib/core/constant/global_constant.dart +++ b/lib/core/constant/global_constant.dart @@ -25,6 +25,7 @@ const POST_V4 = 'api/v4/posts'; const POST_V3 = 'api/v3/posts'; const COMMENT_V3 = 'api/v3/comments'; +const FILE_V3 = 'api/v3/files'; const ME_FOLLLOWING = 'api/v4/me/following'; const ME_FOLLLOWERS = 'api/v4/me/followers'; diff --git a/lib/core/model/api_request/get_post_request.dart b/lib/core/model/api_request/get_post_request.dart new file mode 100644 index 00000000..94d7910e --- /dev/null +++ b/lib/core/model/api_request/get_post_request.dart @@ -0,0 +1,78 @@ +// To parse this JSON data, do +// +// final getPostRequest = getPostRequestFromJson(jsonString); + +import 'dart:convert'; + +GetPostRequest getPostRequestFromJson(String str) => + GetPostRequest.fromJson(json.decode(str)); + +String getPostRequestToJson(GetPostRequest data) => json.encode(data.toJson()); + +class GetPostRequest { + GetPostRequest({ + required this.targetId, + required this.targetType, + required this.sortBy, + required this.hasFlag, + required this.isDeleted, + required this.options, + required this.feedType, + required this.dataTypes, + required this.matchingOnlyParentPost, + }); + + final String targetId; + final String targetType; + final String sortBy; + final dynamic hasFlag; + final dynamic isDeleted; + final Options options; + final String feedType; + final List dataTypes; + final bool matchingOnlyParentPost; + + factory GetPostRequest.fromJson(Map json) => GetPostRequest( + targetId: json["targetId"], + targetType: json["targetType"], + sortBy: json["sortBy"], + hasFlag: json["hasFlag"], + isDeleted: json["isDeleted"], + options: Options.fromJson(json["options"]), + feedType: json["feedType"], + dataTypes: List.from(json["dataTypes"].map((x) => x)), + matchingOnlyParentPost: json["matchingOnlyParentPost"], + ); + + Map toJson() => { + "targetId": targetId, + "targetType": targetType, + "sortBy": sortBy, + "hasFlag": hasFlag, + "isDeleted": isDeleted, + "options": options.toJson(), + "feedType": feedType, + "dataTypes": List.from(dataTypes.map((x) => x)), + "matchingOnlyParentPost": matchingOnlyParentPost, + }; +} + +class Options { + Options({ + required this.limit, + required this.token, + }); + + final int limit; + final String token; + + factory Options.fromJson(Map json) => Options( + limit: json["limit"], + token: json["token"], + ); + + Map toJson() => { + "limit": limit, + "token": token, + }; +} diff --git a/lib/data/data_source/local/hive_db_adapter_impl/comment_db_adater_impl.dart b/lib/data/data_source/local/hive_db_adapter_impl/comment_db_adater_impl.dart index 2cc4bb62..7a7f83bc 100644 --- a/lib/data/data_source/local/hive_db_adapter_impl/comment_db_adater_impl.dart +++ b/lib/data/data_source/local/hive_db_adapter_impl/comment_db_adater_impl.dart @@ -15,7 +15,7 @@ class CommentDbAdapterImpl extends CommentDbAdapter { } @override - CommentHiveEntity getCommentEntity(String id) { + CommentHiveEntity getCommentEntity(String id) { return box.get(id); } diff --git a/lib/data/data_source/remote/api_interface/commnet_api_interface.dart b/lib/data/data_source/remote/api_interface/commnet_api_interface.dart index 3b487102..c03ab8a3 100644 --- a/lib/data/data_source/remote/api_interface/commnet_api_interface.dart +++ b/lib/data/data_source/remote/api_interface/commnet_api_interface.dart @@ -5,5 +5,13 @@ import 'package:amity_sdk/data/response/response.dart'; abstract class CommentApiInterface { Future createComment(CreateCommentRequest request); Future queryComment(GetCommentRequest request); + + Future getComment(String commentId); + Future updateComment( + String commentId, CreateCommentRequest request); Future deleteComment(String commentId); + + Future flagComment(String commentId); + Future unflagComment(String commentId); + Future isCommentFlagByMe(String commentId); } diff --git a/lib/data/data_source/remote/api_interface/file_api_interface.dart b/lib/data/data_source/remote/api_interface/file_api_interface.dart index 88c348f0..69508f09 100644 --- a/lib/data/data_source/remote/api_interface/file_api_interface.dart +++ b/lib/data/data_source/remote/api_interface/file_api_interface.dart @@ -1 +1,9 @@ -abstract class FileApiInterface {} +import 'dart:io'; + +import 'package:amity_sdk/data/response/response.dart'; + +abstract class FileApiInterface { + Future uploadFile(File file); + Future getFile(String fileId); + Future deleteFile(String fileId); +} diff --git a/lib/data/data_source/remote/api_interface/public_post_api_interface.dart b/lib/data/data_source/remote/api_interface/public_post_api_interface.dart index 4e148607..fc4ecac4 100644 --- a/lib/data/data_source/remote/api_interface/public_post_api_interface.dart +++ b/lib/data/data_source/remote/api_interface/public_post_api_interface.dart @@ -1,7 +1,17 @@ import 'package:amity_sdk/core/model/api_request/create_post_request.dart'; +import 'package:amity_sdk/core/model/api_request/get_post_request.dart'; import 'package:amity_sdk/data/data.dart'; abstract class PublicPostApiInterface { - Future getPostById(String postId); + Future queryPost(GetPostRequest request); Future createPost(CreatePostRequest request); + + Future getPostById(String postId); + Future updatePostById( + String postId, CreatePostRequest request); + Future deletePostById(String postId); + + Future flagPost(String postId); + Future unflagPost(String postId); + Future isPostFlagByMe(String postId); } diff --git a/lib/data/data_source/remote/http_api_interface_impl/commant_api_interface_impl.dart b/lib/data/data_source/remote/http_api_interface_impl/commant_api_interface_impl.dart index 7669da23..bc30fa77 100644 --- a/lib/data/data_source/remote/http_api_interface_impl/commant_api_interface_impl.dart +++ b/lib/data/data_source/remote/http_api_interface_impl/commant_api_interface_impl.dart @@ -45,4 +45,64 @@ class CommentApiInterfaceImpl extends CommentApiInterface { return Future.error(amityError.amityException()); } } + + @override + Future flagComment(String commentId) async { + try { + final data = + await httpApiClient().post(COMMENT_V3 + '/$commentId' + '/flag'); + return true; + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future getComment(String commentId) async { + try { + final data = await httpApiClient().get(COMMENT_V3 + '/$commentId'); + return CreatePostResponse.fromJson(data.data); + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future isCommentFlagByMe(String commentId) async { + try { + final data = + await httpApiClient().get(COMMENT_V3 + '/$commentId' + '/isflagbyme'); + return true; + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future unflagComment(String commentId) async { + try { + final data = + await httpApiClient().delete(COMMENT_V3 + '/$commentId' + '/unflag'); + return true; + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future updateComment( + String commentId, CreateCommentRequest request) async { + try { + final data = + await httpApiClient().put(COMMENT_V3 + '/$commentId', data: request); + return CreatePostResponse.fromJson(data.data); + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } } diff --git a/lib/data/data_source/remote/http_api_interface_impl/file_api_interface_impl.dart b/lib/data/data_source/remote/http_api_interface_impl/file_api_interface_impl.dart index b411bc4e..468a97d6 100644 --- a/lib/data/data_source/remote/http_api_interface_impl/file_api_interface_impl.dart +++ b/lib/data/data_source/remote/http_api_interface_impl/file_api_interface_impl.dart @@ -1,8 +1,45 @@ +import 'dart:io'; + +import 'package:amity_sdk/core/core.dart'; +import 'package:amity_sdk/data/data.dart'; import 'package:amity_sdk/data/data_source/remote/api_interface/file_api_interface.dart'; -import 'package:amity_sdk/data/data_source/remote/client/http/http_api_client.dart'; +import 'package:dio/dio.dart'; class FileApiInterfaceImpl extends FileApiInterface { final HttpApiClient httpApiClient; FileApiInterfaceImpl({required this.httpApiClient}); + + @override + Future deleteFile(String fileId) async { + try { + final data = await httpApiClient().delete(FILE_V3 + '/$fileId'); + return true; + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future getFile(String fileId) async { + try { + final data = await httpApiClient().get(FILE_V3 + '/$fileId'); + return CreatePostResponse.fromJson(data.data); + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future uploadFile(File file) async { + try { + final data = await httpApiClient().post(FILE_V3 + '/'); + return CreatePostResponse.fromJson(data.data); + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } } diff --git a/lib/data/data_source/remote/http_api_interface_impl/public_post_api_interface_impl.dart b/lib/data/data_source/remote/http_api_interface_impl/public_post_api_interface_impl.dart index df7acdc4..7f33a0a7 100644 --- a/lib/data/data_source/remote/http_api_interface_impl/public_post_api_interface_impl.dart +++ b/lib/data/data_source/remote/http_api_interface_impl/public_post_api_interface_impl.dart @@ -1,4 +1,5 @@ import 'package:amity_sdk/core/core.dart'; +import 'package:amity_sdk/core/model/api_request/get_post_request.dart'; import 'package:amity_sdk/data/data.dart'; import 'package:dio/dio.dart'; @@ -26,4 +27,74 @@ class PublicPostApiInterfaceImpl extends PublicPostApiInterface { return Future.error(amityError.amityException()); } } + + @override + Future deletePostById(String postId) async { + try { + final data = await httpApiClient().delete(POST_V3 + '/$postId'); + return true; + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future flagPost(String postId) async { + try { + final data = await httpApiClient().post(POST_V3 + '/$postId' + '/flag'); + return true; + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future isPostFlagByMe(String postId) async { + try { + final data = + await httpApiClient().post(POST_V3 + '/$postId' + '/isflagbyme'); + return true; + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future queryPost(GetPostRequest request) async { + try { + final data = + await httpApiClient().get(POST_V3, queryParameters: request.toJson()); + return CreatePostResponse.fromJson(data.data); + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future unflagPost(String postId) async { + try { + final data = await httpApiClient().delete(POST_V3 + '/$postId' + '/flag'); + return true; + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } + + @override + Future updatePostById( + String postId, CreatePostRequest request) async { + try { + final data = + await httpApiClient().put(POST_V3 + '/$postId', data: request); + return CreatePostResponse.fromJson(data.data); + } on DioError catch (error) { + final amityError = AmityErrorResponse.fromJson(error.response!.data); + return Future.error(amityError.amityException()); + } + } } diff --git a/lib/data/repo_impl/comment_repo_impl.dart b/lib/data/repo_impl/comment_repo_impl.dart index 95a1c5a0..031a7862 100644 --- a/lib/data/repo_impl/comment_repo_impl.dart +++ b/lib/data/repo_impl/comment_repo_impl.dart @@ -25,40 +25,64 @@ class CommentRepoImpl extends CommentRepo { Future createComment(CreateCommentRequest request) async { final data = await commentApiInterface.createComment(request); - //Convert to Comment Hive Entity - List commentHiveEntities = - data.comments.map((e) => e.convertToCommentHiveEntity()).toList(); + final amityComments = await _saveDetailsToDb(data); - //Convert to User Hive Entity - List userHiveEntities = - data.users.map((e) => e.convertToUserHiveEntity()).toList(); + return Future.value(amityComments[0]); + } - //Convert to File Hive Entity - List fileHiveEntities = - data.files.map((e) => e.convertToFileHiveEntity()).toList(); + @override + Future> queryComment(GetCommentRequest request) async { + final data = await commentApiInterface.queryComment(request); - //Save the Comment Entity - for (var e in commentHiveEntities) { - await commentDbAdapter.saveCommentEntity(e); - } + final amityComments = await _saveDetailsToDb(data); - //Save the User Entity - for (var e in userHiveEntities) { - await userDbAdapter.saveUserEntity(e); - } + return Future.value(amityComments); + } - //Save the File Entity - for (var e in fileHiveEntities) { - await fileDbAdapter.saveFileEntity(e); - } + @override + Future deleteComment(String commentId) async { + final data = await commentApiInterface.deleteComment(commentId); + return data; + } - return Future.value(commentHiveEntities[0].convertToAmityComment()); + @override + Future flagComment(String commentId) async { + final data = await commentApiInterface.flagComment(commentId); + return data; } @override - Future> queryComment(GetCommentRequest request) async { - final data = await commentApiInterface.queryComment(request); + Future getComment(String commentId) async { + final data = await commentApiInterface.getComment(commentId); + final amityComments = await _saveDetailsToDb(data); + + return Future.value(amityComments[0]); + } + + @override + Future isCommentFlagByMe(String commentId) async { + final data = await commentApiInterface.isCommentFlagByMe(commentId); + return data; + } + + @override + Future unflagComment(String commentId) async { + final data = await commentApiInterface.unflagComment(commentId); + return data; + } + + @override + Future updateComment( + String commentId, CreateCommentRequest request) async { + final data = await commentApiInterface.updateComment(commentId, request); + + final amityComments = await _saveDetailsToDb(data); + + return Future.value(amityComments[0]); + } + + Future> _saveDetailsToDb(CreatePostResponse data) async { //Convert to Comment Hive Entity List commentHiveEntities = data.comments.map((e) => e.convertToCommentHiveEntity()).toList(); @@ -85,14 +109,6 @@ class CommentRepoImpl extends CommentRepo { for (var e in fileHiveEntities) { await fileDbAdapter.saveFileEntity(e); } - - return Future.value( - commentHiveEntities.map((e) => e.convertToAmityComment()).toList()); - } - - @override - Future deleteComment(String commentId) async { - final data = await commentApiInterface.deleteComment(commentId); - return data; + return commentHiveEntities.map((e) => e.convertToAmityComment()).toList(); } } diff --git a/lib/data/repo_impl/post_repo_impl.dart b/lib/data/repo_impl/post_repo_impl.dart index 7d0e66d3..c6e42cdf 100644 --- a/lib/data/repo_impl/post_repo_impl.dart +++ b/lib/data/repo_impl/post_repo_impl.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:amity_sdk/core/model/api_request/create_post_request.dart'; +import 'package:amity_sdk/core/model/api_request/get_post_request.dart'; import 'package:amity_sdk/data/data.dart'; import 'package:amity_sdk/domain/model/amity_post.dart'; import 'package:amity_sdk/domain/repo/post_repo.dart'; @@ -29,6 +30,23 @@ class PostRepoImpl extends PostRepo { //Get the data from remote source and return it final data = await publicPostApiInterface.getPostById(postId); + final amitPosts = await _saveDataTpDb(data); + + return amitPosts[0]; + } + + @override + Future createPost(CreatePostRequest request) async { + final data = await publicPostApiInterface.createPost(request); + return AmityPost(); + } + + @override + Future getPostByIdFromDb(String id) { + return Future.value(postDbAdapter.getPostEntity(id).convertToAmityPost()); + } + + Future> _saveDataTpDb(CreatePostResponse data) async { //Convert to Post Hive Entity List postHiveEntities = data.posts.map((e) => e.convertToPostHiveEntity()).toList(); @@ -73,17 +91,45 @@ class PostRepoImpl extends PostRepo { await fileDbAdapter.saveFileEntity(e); } - return Future.value(postHiveEntities[0].convertToAmityPost()); + return postChildHiveEntities.map((e) => e.convertToAmityPost()).toList(); } @override - Future createPost(CreatePostRequest request) async { - final data = await publicPostApiInterface.createPost(request); - return AmityPost(); + Future deletePostById(String postId) async { + final data = await publicPostApiInterface.deletePostById(postId); + return data; } @override - Future getPostByIdFromDb(String id) { - return Future.value(postDbAdapter.getPostEntity(id).convertToAmityPost()); + Future flagPost(String postId) async { + final data = await publicPostApiInterface.flagPost(postId); + return data; + } + + @override + Future isPostFlagByMe(String postId) async { + final data = await publicPostApiInterface.isPostFlagByMe(postId); + return data; + } + + @override + Future unflagPost(String postId) async { + final data = await publicPostApiInterface.unflagPost(postId); + return data; + } + + @override + Future updatePostById( + String postId, CreatePostRequest request) async { + final data = await publicPostApiInterface.updatePostById(postId, request); + final amitPosts = await _saveDataTpDb(data); + return amitPosts[0]; + } + + @override + Future> queryPost(GetPostRequest request) async { + final data = await publicPostApiInterface.queryPost(request); + final amitPosts = await _saveDataTpDb(data); + return amitPosts; } } diff --git a/lib/domain/repo/comment_repo.dart b/lib/domain/repo/comment_repo.dart index 27b149c2..67f93ec5 100644 --- a/lib/domain/repo/comment_repo.dart +++ b/lib/domain/repo/comment_repo.dart @@ -4,7 +4,16 @@ import 'package:amity_sdk/domain/model/model.dart'; abstract class CommentRepo { Future getCommentByIdFromDb(String commentId); + Future createComment(CreateCommentRequest request); Future> queryComment(GetCommentRequest request); + + Future getComment(String commentId); + Future updateComment( + String commentId, CreateCommentRequest request); Future deleteComment(String commentId); + + Future flagComment(String commentId); + Future unflagComment(String commentId); + Future isCommentFlagByMe(String commentId); } diff --git a/lib/domain/repo/post_repo.dart b/lib/domain/repo/post_repo.dart index 9dfa30ce..222e9c48 100644 --- a/lib/domain/repo/post_repo.dart +++ b/lib/domain/repo/post_repo.dart @@ -1,8 +1,17 @@ import 'package:amity_sdk/core/model/api_request/create_post_request.dart'; +import 'package:amity_sdk/core/model/api_request/get_post_request.dart'; import 'package:amity_sdk/domain/model/amity_post.dart'; abstract class PostRepo { + Future> queryPost(GetPostRequest request); Future getPostById(String postId); Future createPost(CreatePostRequest request); Future getPostByIdFromDb(String id); + + Future updatePostById(String postId, CreatePostRequest request); + Future deletePostById(String postId); + + Future flagPost(String postId); + Future unflagPost(String postId); + Future isPostFlagByMe(String postId); } diff --git a/lib/public/query_builder/reaction/remove_reaction_query_builder.dart b/lib/public/query_builder/reaction/remove_reaction_query_builder.dart index b10280ae..0af96105 100644 --- a/lib/public/query_builder/reaction/remove_reaction_query_builder.dart +++ b/lib/public/query_builder/reaction/remove_reaction_query_builder.dart @@ -15,7 +15,7 @@ class RemoveReactionQueryBuilder { referenceId = _referenceId; } - Future removeReaction(String reaction) { + Future removeReaction(String reaction) { ReactionRequest reactionRequest = ReactionRequest( referenceId: _referenceId, referenceType: _referenceType, From 523ba610d0212fb48dcf38f1b95dc576d5b7a091 Mon Sep 17 00:00:00 2001 From: Saurabh kumar Date: Wed, 2 Mar 2022 20:03:33 +0530 Subject: [PATCH 2/3] Post live object base --- .dart_tool/package_config.json | 8 +- .../service_locator/sdk_service_locator.dart | 3 +- .../local/db_adapter/post_db_adapter.dart | 4 + .../post_db_adapter_impl.dart | 13 ++ .../remote/client/http/http_api_client.dart | 15 +- lib/data/repo_impl/comment_repo_impl.dart | 33 +++-- lib/data/repo_impl/post_repo_impl.dart | 140 +++++++++++------- ...follow_relationship_composer_usecase.dart} | 0 .../comment_compose_usecase.dart | 0 .../comment_composer_usecase.dart | 16 ++ .../composer_usecase/composer_usecase.dart | 2 +- .../file_composer_usecase.dart | 16 ++ lib/domain/model/amity_file.dart | 3 + lib/domain/repo/post_repo.dart | 4 + .../usecase/post/get_post_by_id_usecase.dart | 13 +- lib/public/amity_core_client.dart | 14 +- lib/public/public.dart | 2 + lib/public/repo/post_repository.dart | 4 + pubspec.lock | 7 + pubspec.yaml | 1 + sample_app/lib/main.dart | 15 +- 21 files changed, 227 insertions(+), 86 deletions(-) rename lib/domain/composer_usecase/{amity_follow_relationship_composer.dart => amity_follow_relationship_composer_usecase.dart} (100%) delete mode 100644 lib/domain/composer_usecase/comment_compose_usecase.dart create mode 100644 lib/domain/composer_usecase/comment_composer_usecase.dart create mode 100644 lib/domain/composer_usecase/file_composer_usecase.dart create mode 100644 lib/domain/model/amity_file.dart diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index c76a89e7..a1fdd674 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -403,6 +403,12 @@ "packageUri": "lib/", "languageVersion": "2.14" }, + { + "name": "rxdart", + "rootUri": "file:///Users/saurabhkumar/sorbh/flutter/.pub-cache/hosted/pub.dartlang.org/rxdart-0.27.3", + "packageUri": "lib/", + "languageVersion": "2.12" + }, { "name": "shelf", "rootUri": "file:///Users/saurabhkumar/sorbh/flutter/.pub-cache/hosted/pub.dartlang.org/shelf-1.2.0", @@ -530,7 +536,7 @@ "languageVersion": "2.15" } ], - "generated": "2022-02-28T09:24:40.836846Z", + "generated": "2022-02-28T14:52:16.619036Z", "generator": "pub", "generatorVersion": "2.16.0" } diff --git a/lib/core/service_locator/sdk_service_locator.dart b/lib/core/service_locator/sdk_service_locator.dart index 715c9db1..e0a132b9 100644 --- a/lib/core/service_locator/sdk_service_locator.dart +++ b/lib/core/service_locator/sdk_service_locator.dart @@ -108,7 +108,8 @@ class SdkServiceLocator { commentDbAdapter: serviceLocator(), commentApiInterface: serviceLocator(), fileDbAdapter: serviceLocator(), - userDbAdapter: serviceLocator())); + userDbAdapter: serviceLocator(), + postDbAdapter: serviceLocator())); serviceLocator.registerLazySingleton( () => FileRepoImpl(fileDbAdapter: serviceLocator())); serviceLocator.registerLazySingleton( diff --git a/lib/data/data_source/local/db_adapter/post_db_adapter.dart b/lib/data/data_source/local/db_adapter/post_db_adapter.dart index 436180dd..48f61305 100644 --- a/lib/data/data_source/local/db_adapter/post_db_adapter.dart +++ b/lib/data/data_source/local/db_adapter/post_db_adapter.dart @@ -4,4 +4,8 @@ abstract class PostDbAdapter { Future savePostEntity(PostHiveEntity data); Future deletePostEntity(PostHiveEntity data); PostHiveEntity getPostEntity(String postId); + + Stream listenPostEntity(String postId); + + Future updateComment(String postId, String commentId); } diff --git a/lib/data/data_source/local/hive_db_adapter_impl/post_db_adapter_impl.dart b/lib/data/data_source/local/hive_db_adapter_impl/post_db_adapter_impl.dart index 3950d5e7..9a0365a7 100644 --- a/lib/data/data_source/local/hive_db_adapter_impl/post_db_adapter_impl.dart +++ b/lib/data/data_source/local/hive_db_adapter_impl/post_db_adapter_impl.dart @@ -25,4 +25,17 @@ class PostDbAdapterImpl extends PostDbAdapter { PostHiveEntity getPostEntity(String postId) { return box.get(postId); } + + @override + Stream listenPostEntity(String postId) { + return box.watch(key: postId).map((event) => event.value); + } + + @override + Future updateComment(String postId, String commentId) async { + getPostEntity(postId) + ..comments!.add(commentId) + ..save(); + return; + } } diff --git a/lib/data/data_source/remote/client/http/http_api_client.dart b/lib/data/data_source/remote/client/http/http_api_client.dart index d0a4bd25..d0a76b84 100644 --- a/lib/data/data_source/remote/client/http/http_api_client.dart +++ b/lib/data/data_source/remote/client/http/http_api_client.dart @@ -27,13 +27,14 @@ class HttpApiClient { return handler.next(options); }, )); - - dio.interceptors.add(LogInterceptor( - requestBody: true, - responseBody: true, - logPrint: (logs) { - log(logs as String); - })); + if (amityCoreClientOption.showLogs) { + dio.interceptors.add(LogInterceptor( + requestBody: true, + responseBody: true, + logPrint: (logs) { + log(logs as String); + })); + } } late Dio dio; diff --git a/lib/data/repo_impl/comment_repo_impl.dart b/lib/data/repo_impl/comment_repo_impl.dart index 031a7862..792d8d40 100644 --- a/lib/data/repo_impl/comment_repo_impl.dart +++ b/lib/data/repo_impl/comment_repo_impl.dart @@ -9,8 +9,10 @@ class CommentRepoImpl extends CommentRepo { final CommentDbAdapter commentDbAdapter; final UserDbAdapter userDbAdapter; final FileDbAdapter fileDbAdapter; + final PostDbAdapter postDbAdapter; CommentRepoImpl( - {required this.commentDbAdapter, + {required this.postDbAdapter, + required this.commentDbAdapter, required this.commentApiInterface, required this.userDbAdapter, required this.fileDbAdapter}); @@ -27,6 +29,10 @@ class CommentRepoImpl extends CommentRepo { final amityComments = await _saveDetailsToDb(data); + //Update the post entity + postDbAdapter.updateComment( + request.referenceId, amityComments[0].commentId!); + return Future.value(amityComments[0]); } @@ -83,21 +89,21 @@ class CommentRepoImpl extends CommentRepo { } Future> _saveDetailsToDb(CreatePostResponse data) async { - //Convert to Comment Hive Entity - List commentHiveEntities = - data.comments.map((e) => e.convertToCommentHiveEntity()).toList(); + //Convert to File Hive Entity + List fileHiveEntities = + data.files.map((e) => e.convertToFileHiveEntity()).toList(); //Convert to User Hive Entity List userHiveEntities = data.users.map((e) => e.convertToUserHiveEntity()).toList(); - //Convert to File Hive Entity - List fileHiveEntities = - data.files.map((e) => e.convertToFileHiveEntity()).toList(); + //Convert to Comment Hive Entity + List commentHiveEntities = + data.comments.map((e) => e.convertToCommentHiveEntity()).toList(); - //Save the Comment Entity - for (var e in commentHiveEntities) { - await commentDbAdapter.saveCommentEntity(e); + //Save the File Entity + for (var e in fileHiveEntities) { + await fileDbAdapter.saveFileEntity(e); } //Save the User Entity @@ -105,10 +111,11 @@ class CommentRepoImpl extends CommentRepo { await userDbAdapter.saveUserEntity(e); } - //Save the File Entity - for (var e in fileHiveEntities) { - await fileDbAdapter.saveFileEntity(e); + //Save the Comment Entity + for (var e in commentHiveEntities) { + await commentDbAdapter.saveCommentEntity(e); } + return commentHiveEntities.map((e) => e.convertToAmityComment()).toList(); } } diff --git a/lib/data/repo_impl/post_repo_impl.dart b/lib/data/repo_impl/post_repo_impl.dart index c6e42cdf..3f900219 100644 --- a/lib/data/repo_impl/post_repo_impl.dart +++ b/lib/data/repo_impl/post_repo_impl.dart @@ -30,7 +30,7 @@ class PostRepoImpl extends PostRepo { //Get the data from remote source and return it final data = await publicPostApiInterface.getPostById(postId); - final amitPosts = await _saveDataTpDb(data); + final amitPosts = await _saveDataToDb(data); return amitPosts[0]; } @@ -38,60 +38,13 @@ class PostRepoImpl extends PostRepo { @override Future createPost(CreatePostRequest request) async { final data = await publicPostApiInterface.createPost(request); - return AmityPost(); + final amitPosts = await _saveDataToDb(data); + return amitPosts[0]; } @override - Future getPostByIdFromDb(String id) { - return Future.value(postDbAdapter.getPostEntity(id).convertToAmityPost()); - } - - Future> _saveDataTpDb(CreatePostResponse data) async { - //Convert to Post Hive Entity - List postHiveEntities = - data.posts.map((e) => e.convertToPostHiveEntity()).toList(); - - List postChildHiveEntities = - data.postChildren.map((e) => e.convertToPostHiveEntity()).toList(); - - //Convert to Comment Hive Entity - List commentHiveEntities = - data.comments.map((e) => e.convertToCommentHiveEntity()).toList(); - - //Convert to User Hive Entity - List userHiveEntities = - data.users.map((e) => e.convertToUserHiveEntity()).toList(); - - //Convert to File Hive Entity - List fileHiveEntities = - data.files.map((e) => e.convertToFileHiveEntity()).toList(); - - //Save Post Entity - for (var e in postHiveEntities) { - await postDbAdapter.savePostEntity(e); - } - - //Save Child Post Entity - for (var e in postChildHiveEntities) { - await postDbAdapter.savePostEntity(e); - } - - //Save the Comment Entity - for (var e in commentHiveEntities) { - await commentDbAdapter.saveCommentEntity(e); - } - - //Save the User Entity - for (var e in userHiveEntities) { - await userDbAdapter.saveUserEntity(e); - } - - //Save the File Entity - for (var e in fileHiveEntities) { - await fileDbAdapter.saveFileEntity(e); - } - - return postChildHiveEntities.map((e) => e.convertToAmityPost()).toList(); + Future getPostByIdFromDb(String id) async { + return postDbAdapter.getPostEntity(id).convertToAmityPost(); } @override @@ -122,14 +75,93 @@ class PostRepoImpl extends PostRepo { Future updatePostById( String postId, CreatePostRequest request) async { final data = await publicPostApiInterface.updatePostById(postId, request); - final amitPosts = await _saveDataTpDb(data); + final amitPosts = await _saveDataToDb(data); return amitPosts[0]; } @override Future> queryPost(GetPostRequest request) async { final data = await publicPostApiInterface.queryPost(request); - final amitPosts = await _saveDataTpDb(data); + final amitPosts = await _saveDataToDb(data); return amitPosts; } + + Future> _saveDataToDb(CreatePostResponse data) async { + //Convert to File Hive Entity + //we have save the file first, since every object depends on file + List fileHiveEntities = + data.files.map((e) => e.convertToFileHiveEntity()).toList(); + + //Convert to User Hive Entity + List userHiveEntities = + data.users.map((e) => e.convertToUserHiveEntity()).toList(); + + //Convert to Comment Hive Entity + List commentHiveEntities = + data.comments.map((e) => e.convertToCommentHiveEntity()).toList(); + + //Convert to Post Hive Entity + List postChildHiveEntities = + data.postChildren.map((e) => e.convertToPostHiveEntity()).toList(); + + List postHiveEntities = + data.posts.map((e) => e.convertToPostHiveEntity()).toList(); + + //Save the File Entity + for (var e in fileHiveEntities) { + await fileDbAdapter.saveFileEntity(e); + } + + //Save Child Post Entity + for (var e in postChildHiveEntities) { + await postDbAdapter.savePostEntity(e); + } + + //Save the User Entity + for (var e in userHiveEntities) { + await userDbAdapter.saveUserEntity(e); + } + + //Save the Comment Entity + for (var e in commentHiveEntities) { + await commentDbAdapter.saveCommentEntity(e); + } + + //Save Post Entity + for (var e in postHiveEntities) { + await postDbAdapter.savePostEntity(e); + } + + return postHiveEntities.map((e) => e.convertToAmityPost()).toList(); + } + + @override + Stream getPostByIdStream(String postId) { + StreamController controller = StreamController(); + //1. Get Amity Post from local db + getPostByIdFromDb(postId).then((value) { + if (value != null) { + controller.add(value); + } + }).onError((error, stackTrace) {}); + + // 2. Make the API request and send the updated data back + getPostById(postId).then((value) { + if (value != null) { + controller.add(value); + } + }); + + //3. Listen any chagnes in the Amity Post Db and send the update back + postDbAdapter.listenPostEntity(postId).listen((event) { + controller.add(event.convertToAmityPost()); + }); + + //1. Amity Post + //2. Comment + //3. User + //4. File + + return controller.stream; + } } diff --git a/lib/domain/composer_usecase/amity_follow_relationship_composer.dart b/lib/domain/composer_usecase/amity_follow_relationship_composer_usecase.dart similarity index 100% rename from lib/domain/composer_usecase/amity_follow_relationship_composer.dart rename to lib/domain/composer_usecase/amity_follow_relationship_composer_usecase.dart diff --git a/lib/domain/composer_usecase/comment_compose_usecase.dart b/lib/domain/composer_usecase/comment_compose_usecase.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/domain/composer_usecase/comment_composer_usecase.dart b/lib/domain/composer_usecase/comment_composer_usecase.dart new file mode 100644 index 00000000..4e2fe785 --- /dev/null +++ b/lib/domain/composer_usecase/comment_composer_usecase.dart @@ -0,0 +1,16 @@ +import 'package:amity_sdk/core/core.dart'; +import 'package:amity_sdk/domain/model/amity_comment.dart'; + +class CommentComposerUsecase extends UseCase { + @override + Future get(AmityComment params) { + // TODO: implement get + throw UnimplementedError(); + } + + @override + Stream listen(AmityComment params) { + // TODO: implement listen + throw UnimplementedError(); + } +} diff --git a/lib/domain/composer_usecase/composer_usecase.dart b/lib/domain/composer_usecase/composer_usecase.dart index f52b9755..52913f5a 100644 --- a/lib/domain/composer_usecase/composer_usecase.dart +++ b/lib/domain/composer_usecase/composer_usecase.dart @@ -1,2 +1,2 @@ -export 'amity_follow_relationship_composer.dart'; +export 'amity_follow_relationship_composer_usecase.dart'; export 'post_composer_usecase.dart'; diff --git a/lib/domain/composer_usecase/file_composer_usecase.dart b/lib/domain/composer_usecase/file_composer_usecase.dart new file mode 100644 index 00000000..d942d48e --- /dev/null +++ b/lib/domain/composer_usecase/file_composer_usecase.dart @@ -0,0 +1,16 @@ +import 'package:amity_sdk/core/core.dart'; +import 'package:amity_sdk/domain/model/amity_file.dart'; + +class FileComposerUsecase extends UseCase { + @override + Future get(AmityFile params) { + // TODO: implement get + throw UnimplementedError(); + } + + @override + Stream listen(AmityFile params) { + // TODO: implement listen + throw UnimplementedError(); + } +} diff --git a/lib/domain/model/amity_file.dart b/lib/domain/model/amity_file.dart new file mode 100644 index 00000000..abd4cb5e --- /dev/null +++ b/lib/domain/model/amity_file.dart @@ -0,0 +1,3 @@ +class AmityFile{ + +} \ No newline at end of file diff --git a/lib/domain/repo/post_repo.dart b/lib/domain/repo/post_repo.dart index 222e9c48..f20054da 100644 --- a/lib/domain/repo/post_repo.dart +++ b/lib/domain/repo/post_repo.dart @@ -3,6 +3,7 @@ import 'package:amity_sdk/core/model/api_request/get_post_request.dart'; import 'package:amity_sdk/domain/model/amity_post.dart'; abstract class PostRepo { + //Future Method Future> queryPost(GetPostRequest request); Future getPostById(String postId); Future createPost(CreatePostRequest request); @@ -14,4 +15,7 @@ abstract class PostRepo { Future flagPost(String postId); Future unflagPost(String postId); Future isPostFlagByMe(String postId); + + //Streams Method + Stream getPostByIdStream(String postId); } diff --git a/lib/domain/usecase/post/get_post_by_id_usecase.dart b/lib/domain/usecase/post/get_post_by_id_usecase.dart index 8616f1bc..fb17a672 100644 --- a/lib/domain/usecase/post/get_post_by_id_usecase.dart +++ b/lib/domain/usecase/post/get_post_by_id_usecase.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:amity_sdk/core/usercase/usecase.dart'; import 'package:amity_sdk/domain/domain.dart'; @@ -19,6 +21,15 @@ class GetPostByIdUseCase extends UseCase { @override Stream listen(String params) { - throw UnimplementedError(); + //1. Listen to Amity post stream + //2. compose the Amity post + StreamController controller = StreamController(); + + postRepo.getPostByIdStream(params).listen((event) async { + final amityComposedPost = await postComposerUsecase.get(event); + controller.add(amityComposedPost); + }); + + return controller.stream; } } diff --git a/lib/public/amity_core_client.dart b/lib/public/amity_core_client.dart index c6ae913e..c40e8127 100644 --- a/lib/public/amity_core_client.dart +++ b/lib/public/amity_core_client.dart @@ -1,5 +1,4 @@ import 'package:amity_sdk/core/core.dart'; -import 'package:amity_sdk/core/enum/mqtt_end_point.dart'; import 'package:amity_sdk/domain/domain.dart'; import 'package:amity_sdk/public/public.dart'; @@ -36,10 +35,13 @@ class AmityCoreClientOption { final AmityRegionalHttpEndpoint httpEndpoint; final AmityRegionalSocketEndpoint socketEndpoint; final AmityRegionalMqttEndpoint mqttEndpoint; + final bool showLogs; - AmityCoreClientOption( - {required this.apiKey, - this.httpEndpoint = AmityRegionalHttpEndpoint.SG, - this.socketEndpoint = AmityRegionalSocketEndpoint.SG, - this.mqttEndpoint = AmityRegionalMqttEndpoint.SG}); + AmityCoreClientOption({ + required this.apiKey, + this.httpEndpoint = AmityRegionalHttpEndpoint.SG, + this.socketEndpoint = AmityRegionalSocketEndpoint.SG, + this.mqttEndpoint = AmityRegionalMqttEndpoint.SG, + this.showLogs = false, + }); } diff --git a/lib/public/public.dart b/lib/public/public.dart index 868e8e58..4516efe3 100644 --- a/lib/public/public.dart +++ b/lib/public/public.dart @@ -1,3 +1,5 @@ +library amity_social_sdk; + export 'amity_core_client.dart'; export 'client/client.dart'; export 'query_builder/query_builder.dart'; diff --git a/lib/public/repo/post_repository.dart b/lib/public/repo/post_repository.dart index b4172ea9..6c033654 100644 --- a/lib/public/repo/post_repository.dart +++ b/lib/public/repo/post_repository.dart @@ -7,6 +7,10 @@ class PostRepository { return serviceLocator().get(postId); } + Stream getPostStream(String postId) { + return serviceLocator().listen(postId); + } + AmityPostCreateTargetSelector createPost() { return AmityPostCreateTargetSelector(useCase: serviceLocator()); } diff --git a/pubspec.lock b/pubspec.lock index 632dac52..c8d9012a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -466,6 +466,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0" + rxdart: + dependency: "direct main" + description: + name: rxdart + url: "https://pub.dartlang.org" + source: hosted + version: "0.27.3" shelf: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index debec069..e3b6c8d5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,6 +17,7 @@ dependencies: path_provider: ^2.0.9 mqtt_client: 9.6.5 http: ^0.13.4 + rxdart: ^0.27.3 dev_dependencies: flutter_test: diff --git a/sample_app/lib/main.dart b/sample_app/lib/main.dart index 6109c7e5..282e4f94 100644 --- a/sample_app/lib/main.dart +++ b/sample_app/lib/main.dart @@ -25,7 +25,8 @@ class _MyAppState extends State { AmityCoreClient.setup( option: AmityCoreClientOption( apiKey: 'b3bee858328ef4344a308e4a5a091688d05fdee2be353a2b', - httpEndpoint: AmityRegionalHttpEndpoint.STAGING)); + httpEndpoint: AmityRegionalHttpEndpoint.STAGING, + showLogs: true)); } late String userId; @@ -50,6 +51,16 @@ class _MyAppState extends State { .submit() .then((value) { log(value.displayName!); + + // + AmitySocialClient.newPostRepository() + .getPostStream('9cf90cd06d874b8e72c7a0057a330de4') + .listen((event) { + print('>>>>>>>>>>> Update from Live Object'); + log(event.toString()); + }).onError((error, stackTrace) { + log('>>>>>' + error.message.toString()); + }); }).onError((error, stackTrace) { log(error.message.toString()); }); @@ -281,7 +292,7 @@ class _MyAppState extends State { .createComment() .post('9cf90cd06d874b8e72c7a0057a330de4') .create() - .text('Testing Comment from Saurabh') + .text('Comment from Saurabh') .send() .then((value) { print('>>>>>' + value.toString()); From 9835a5fc516514ad95749c8e82585449a0fbbf9d Mon Sep 17 00:00:00 2001 From: Saurabh kumar Date: Thu, 3 Mar 2022 11:37:08 +0530 Subject: [PATCH 3/3] - added post and comment report module --- .dart_tool/package_config.json | 2 +- .../service_locator/sdk_service_locator.dart | 14 +++++++++++ lib/domain/model/amity_post.dart | 2 +- .../usecase/comment/comment_flag_usecase.dart | 19 ++++++++++++++ .../comment/comment_unflag_usecase.dart | 19 ++++++++++++++ .../usecase/post/post_flag_usecase.dart | 19 ++++++++++++++ .../usecase/post/post_unflag_usecase.dart | 19 ++++++++++++++ .../amity_comment_extenstion.dart | 22 ++++++++++++++++ .../amity_post_extension.dart | 10 +++++++- .../comment/comment_flag_query_builder.dart | 22 ++++++++++++++++ .../post/post_flag_query_builder.dart | 22 ++++++++++++++++ ...ilder.dart => reaction_query_builder.dart} | 0 .../remove_reaction_query_builder.dart | 25 ------------------- 13 files changed, 167 insertions(+), 28 deletions(-) create mode 100644 lib/domain/usecase/comment/comment_flag_usecase.dart create mode 100644 lib/domain/usecase/comment/comment_unflag_usecase.dart create mode 100644 lib/domain/usecase/post/post_flag_usecase.dart create mode 100644 lib/domain/usecase/post/post_unflag_usecase.dart create mode 100644 lib/public/model_extenstion/amity_comment_extenstion.dart create mode 100644 lib/public/query_builder/comment/comment_flag_query_builder.dart create mode 100644 lib/public/query_builder/post/post_flag_query_builder.dart rename lib/public/query_builder/reaction/{add_reaction_query_builder.dart => reaction_query_builder.dart} (100%) delete mode 100644 lib/public/query_builder/reaction/remove_reaction_query_builder.dart diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index a1fdd674..a964db06 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -536,7 +536,7 @@ "languageVersion": "2.15" } ], - "generated": "2022-02-28T14:52:16.619036Z", + "generated": "2022-03-02T14:43:54.851642Z", "generator": "pub", "generatorVersion": "2.16.0" } diff --git a/lib/core/service_locator/sdk_service_locator.dart b/lib/core/service_locator/sdk_service_locator.dart index e0a132b9..e446df23 100644 --- a/lib/core/service_locator/sdk_service_locator.dart +++ b/lib/core/service_locator/sdk_service_locator.dart @@ -8,7 +8,11 @@ import 'package:amity_sdk/domain/composer_usecase/user_compose_usecase.dart'; import 'package:amity_sdk/domain/domain.dart'; import 'package:amity_sdk/domain/repo/reaction_repo.dart'; import 'package:amity_sdk/domain/usecase/comment/comment_create_usecase.dart'; +import 'package:amity_sdk/domain/usecase/comment/comment_flag_usecase.dart'; import 'package:amity_sdk/domain/usecase/comment/comment_query_usecase.dart'; +import 'package:amity_sdk/domain/usecase/comment/comment_unflag_usecase.dart'; +import 'package:amity_sdk/domain/usecase/post/post_flag_usecase.dart'; +import 'package:amity_sdk/domain/usecase/post/post_unflag_usecase.dart'; import 'package:amity_sdk/domain/usecase/reaction/add_reaction_usecase.dart'; import 'package:amity_sdk/domain/usecase/reaction/remove_reaction_usecase.dart'; import 'package:amity_sdk/public/public.dart'; @@ -187,6 +191,16 @@ class SdkServiceLocator { serviceLocator.registerLazySingleton( () => CommentQueryUsecase(commentRepo: serviceLocator())); + serviceLocator.registerLazySingleton( + () => PostFlagUsecase(postRepo: serviceLocator())); + serviceLocator.registerLazySingleton( + () => PostUnflagUsecase(postRepo: serviceLocator())); + + serviceLocator.registerLazySingleton( + () => CommentFlagUsecase(commentRepo: serviceLocator())); + serviceLocator.registerLazySingleton( + () => CommentUnflagUsecase(commentRepo: serviceLocator())); + ///----------------------------------- Public Layer -----------------------------------/// //-public_repo serviceLocator.registerLazySingleton(() => PostRepository()); diff --git a/lib/domain/model/amity_post.dart b/lib/domain/model/amity_post.dart index 4d4ded86..0cf30643 100644 --- a/lib/domain/model/amity_post.dart +++ b/lib/domain/model/amity_post.dart @@ -1,7 +1,7 @@ import 'package:amity_sdk/core/core.dart'; import 'package:amity_sdk/core/enum/reaction_reference_type.dart'; import 'package:amity_sdk/domain/domain.dart'; -import 'package:amity_sdk/public/query_builder/reaction/add_reaction_query_builder.dart'; +import 'package:amity_sdk/public/query_builder/reaction/reaction_query_builder.dart'; class AmityPost { String? postId; diff --git a/lib/domain/usecase/comment/comment_flag_usecase.dart b/lib/domain/usecase/comment/comment_flag_usecase.dart new file mode 100644 index 00000000..1c4b6840 --- /dev/null +++ b/lib/domain/usecase/comment/comment_flag_usecase.dart @@ -0,0 +1,19 @@ +import 'package:amity_sdk/core/core.dart'; +import 'package:amity_sdk/domain/domain.dart'; + +class CommentFlagUsecase extends UseCase { + final CommentRepo commentRepo; + + CommentFlagUsecase({required this.commentRepo}); + + @override + Future get(String params) { + return commentRepo.flagComment(params); + } + + @override + Stream listen(String params) { + // TODO: implement listen + throw UnimplementedError(); + } +} diff --git a/lib/domain/usecase/comment/comment_unflag_usecase.dart b/lib/domain/usecase/comment/comment_unflag_usecase.dart new file mode 100644 index 00000000..99c5d513 --- /dev/null +++ b/lib/domain/usecase/comment/comment_unflag_usecase.dart @@ -0,0 +1,19 @@ +import 'package:amity_sdk/core/core.dart'; +import 'package:amity_sdk/domain/domain.dart'; + +class CommentUnflagUsecase extends UseCase { + final CommentRepo commentRepo; + + CommentUnflagUsecase({required this.commentRepo}); + + @override + Future get(String params) { + return commentRepo.unflagComment(params); + } + + @override + Stream listen(String params) { + // TODO: implement listen + throw UnimplementedError(); + } +} diff --git a/lib/domain/usecase/post/post_flag_usecase.dart b/lib/domain/usecase/post/post_flag_usecase.dart new file mode 100644 index 00000000..6435782a --- /dev/null +++ b/lib/domain/usecase/post/post_flag_usecase.dart @@ -0,0 +1,19 @@ +import 'package:amity_sdk/core/core.dart'; +import 'package:amity_sdk/domain/domain.dart'; + +class PostFlagUsecase extends UseCase { + final PostRepo postRepo; + + PostFlagUsecase({required this.postRepo}); + + @override + Future get(String params) { + return postRepo.flagPost(params); + } + + @override + Stream listen(String params) { + // TODO: implement listen + throw UnimplementedError(); + } +} diff --git a/lib/domain/usecase/post/post_unflag_usecase.dart b/lib/domain/usecase/post/post_unflag_usecase.dart new file mode 100644 index 00000000..b751fa67 --- /dev/null +++ b/lib/domain/usecase/post/post_unflag_usecase.dart @@ -0,0 +1,19 @@ +import 'package:amity_sdk/core/core.dart'; +import 'package:amity_sdk/domain/domain.dart'; + +class PostUnflagUsecase extends UseCase { + final PostRepo postRepo; + + PostUnflagUsecase({required this.postRepo}); + + @override + Future get(String params) { + return postRepo.unflagPost(params); + } + + @override + Stream listen(String params) { + // TODO: implement listen + throw UnimplementedError(); + } +} diff --git a/lib/public/model_extenstion/amity_comment_extenstion.dart b/lib/public/model_extenstion/amity_comment_extenstion.dart new file mode 100644 index 00000000..6e1c63fa --- /dev/null +++ b/lib/public/model_extenstion/amity_comment_extenstion.dart @@ -0,0 +1,22 @@ +import 'package:amity_sdk/core/core.dart'; +import 'package:amity_sdk/core/enum/reaction_reference_type.dart'; +import 'package:amity_sdk/domain/domain.dart'; +import 'package:amity_sdk/public/query_builder/comment/comment_flag_query_builder.dart'; +import 'package:amity_sdk/public/query_builder/reaction/reaction_query_builder.dart'; + +extension AmityCommentExtension on AmityComment { + AddReactionQueryBuilder react() { + return AddReactionQueryBuilder( + addReactionUsecase: serviceLocator(), + removeReactionUsecase: serviceLocator(), + referenceType: ReactionReferenceType.COMMENT.value, + referenceId: commentId!); + } + + CommentFlagQueryBuilder report() { + return CommentFlagQueryBuilder( + commentFlagUsecase: serviceLocator(), + commentUnflagUsecase: serviceLocator(), + commentId: commentId!); + } +} diff --git a/lib/public/model_extenstion/amity_post_extension.dart b/lib/public/model_extenstion/amity_post_extension.dart index 88b7ba5c..370f0d88 100644 --- a/lib/public/model_extenstion/amity_post_extension.dart +++ b/lib/public/model_extenstion/amity_post_extension.dart @@ -2,7 +2,8 @@ import 'package:amity_sdk/core/core.dart'; import 'package:amity_sdk/core/enum/reaction_reference_type.dart'; import 'package:amity_sdk/domain/domain.dart'; import 'package:amity_sdk/public/query_builder/comment/comment_create_query_builder.dart'; -import 'package:amity_sdk/public/query_builder/reaction/add_reaction_query_builder.dart'; +import 'package:amity_sdk/public/query_builder/post/post_flag_query_builder.dart'; +import 'package:amity_sdk/public/query_builder/reaction/reaction_query_builder.dart'; extension AmityPostExtension on AmityPost { AddReactionQueryBuilder react() { @@ -18,4 +19,11 @@ extension AmityPostExtension on AmityPost { useCase: serviceLocator(), ).post(postId!); } + + PostFlagQueryBuilder report() { + return PostFlagQueryBuilder( + postFlagUsecase: serviceLocator(), + postUnflagUsecase: serviceLocator(), + postId: postId!); + } } diff --git a/lib/public/query_builder/comment/comment_flag_query_builder.dart b/lib/public/query_builder/comment/comment_flag_query_builder.dart new file mode 100644 index 00000000..57b4b5e6 --- /dev/null +++ b/lib/public/query_builder/comment/comment_flag_query_builder.dart @@ -0,0 +1,22 @@ +import 'package:amity_sdk/domain/usecase/Comment/Comment_flag_usecase.dart'; +import 'package:amity_sdk/domain/usecase/comment/comment_unflag_usecase.dart'; + +class CommentFlagQueryBuilder { + final CommentFlagUsecase _commentFlagUsecase; + final CommentUnflagUsecase _commentUnflagUsecase; + final String _commentId; + CommentFlagQueryBuilder( + {required CommentFlagUsecase commentFlagUsecase, + required CommentUnflagUsecase commentUnflagUsecase, + required String commentId}) + : _commentFlagUsecase = commentFlagUsecase, + _commentUnflagUsecase = commentUnflagUsecase, + _commentId = commentId; + Future flag() { + return _commentFlagUsecase.get(_commentId); + } + + Future unflag() { + return _commentUnflagUsecase.get(_commentId); + } +} diff --git a/lib/public/query_builder/post/post_flag_query_builder.dart b/lib/public/query_builder/post/post_flag_query_builder.dart new file mode 100644 index 00000000..cd99d0b7 --- /dev/null +++ b/lib/public/query_builder/post/post_flag_query_builder.dart @@ -0,0 +1,22 @@ +import 'package:amity_sdk/domain/usecase/post/post_flag_usecase.dart'; +import 'package:amity_sdk/domain/usecase/post/post_unflag_usecase.dart'; + +class PostFlagQueryBuilder { + final PostFlagUsecase _postFlagUsecase; + final PostUnflagUsecase _postUnflagUsecase; + final String _postId; + PostFlagQueryBuilder( + {required PostFlagUsecase postFlagUsecase, + required PostUnflagUsecase postUnflagUsecase, + required String postId}) + : _postFlagUsecase = postFlagUsecase, + _postUnflagUsecase = postUnflagUsecase, + _postId = postId; + Future flag() { + return _postFlagUsecase.get(_postId); + } + + Future unflag() { + return _postUnflagUsecase.get(_postId); + } +} diff --git a/lib/public/query_builder/reaction/add_reaction_query_builder.dart b/lib/public/query_builder/reaction/reaction_query_builder.dart similarity index 100% rename from lib/public/query_builder/reaction/add_reaction_query_builder.dart rename to lib/public/query_builder/reaction/reaction_query_builder.dart diff --git a/lib/public/query_builder/reaction/remove_reaction_query_builder.dart b/lib/public/query_builder/reaction/remove_reaction_query_builder.dart deleted file mode 100644 index 0af96105..00000000 --- a/lib/public/query_builder/reaction/remove_reaction_query_builder.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:amity_sdk/core/model/api_request/reaction_request.dart'; -import 'package:amity_sdk/domain/usecase/reaction/Remove_reaction_usecase.dart'; - -class RemoveReactionQueryBuilder { - late RemoveReactionUsecase _useCase; - late String _referenceType; - late String _referenceId; - - RemoveReactionQueryBuilder( - {required RemoveReactionUsecase useCase, - required String referenceType, - required String referenceId}) { - _useCase = useCase; - referenceType = _referenceType; - referenceId = _referenceId; - } - - Future removeReaction(String reaction) { - ReactionRequest reactionRequest = ReactionRequest( - referenceId: _referenceId, - referenceType: _referenceType, - reactionName: reaction); - return _useCase.get(reactionRequest); - } -}