forked from AmityCo/amity_social_cloud_sdk_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AmityCo#7 from AmityCo/feature-post-live-object
Feature post live object
- Loading branch information
Showing
42 changed files
with
758 additions
and
125 deletions.
There are no files selected for viewing
This file contains 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 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 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,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<String> dataTypes; | ||
final bool matchingOnlyParentPost; | ||
|
||
factory GetPostRequest.fromJson(Map<String, dynamic> 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<String>.from(json["dataTypes"].map((x) => x)), | ||
matchingOnlyParentPost: json["matchingOnlyParentPost"], | ||
); | ||
|
||
Map<String, dynamic> toJson() => { | ||
"targetId": targetId, | ||
"targetType": targetType, | ||
"sortBy": sortBy, | ||
"hasFlag": hasFlag, | ||
"isDeleted": isDeleted, | ||
"options": options.toJson(), | ||
"feedType": feedType, | ||
"dataTypes": List<dynamic>.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<String, dynamic> json) => Options( | ||
limit: json["limit"], | ||
token: json["token"], | ||
); | ||
|
||
Map<String, dynamic> toJson() => { | ||
"limit": limit, | ||
"token": token, | ||
}; | ||
} |
This file contains 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 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 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 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 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
10 changes: 9 additions & 1 deletion
10
lib/data/data_source/remote/api_interface/file_api_interface.dart
This file contains 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 +1,9 @@ | ||
abstract class FileApiInterface {} | ||
import 'dart:io'; | ||
|
||
import 'package:amity_sdk/data/response/response.dart'; | ||
|
||
abstract class FileApiInterface { | ||
Future<CreatePostResponse> uploadFile(File file); | ||
Future<CreatePostResponse> getFile(String fileId); | ||
Future<bool> deleteFile(String fileId); | ||
} |
12 changes: 11 additions & 1 deletion
12
lib/data/data_source/remote/api_interface/public_post_api_interface.dart
This file contains 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,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<CreatePostResponse> getPostById(String postId); | ||
Future<CreatePostResponse> queryPost(GetPostRequest request); | ||
Future<CreatePostResponse> createPost(CreatePostRequest request); | ||
|
||
Future<CreatePostResponse> getPostById(String postId); | ||
Future<CreatePostResponse> updatePostById( | ||
String postId, CreatePostRequest request); | ||
Future<bool> deletePostById(String postId); | ||
|
||
Future<bool> flagPost(String postId); | ||
Future<bool> unflagPost(String postId); | ||
Future<bool> isPostFlagByMe(String postId); | ||
} |
This file contains 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 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
39 changes: 38 additions & 1 deletion
39
lib/data/data_source/remote/http_api_interface_impl/file_api_interface_impl.dart
This file contains 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,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<bool> 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<CreatePostResponse> 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<CreatePostResponse> 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()); | ||
} | ||
} | ||
} |
Oops, something went wrong.