Line data Source code
1 : import 'package:memories_app/network/network_manager.dart'; 2 : import 'package:memories_app/routes/story_detail/model/comment_model.dart'; 3 : import 'package:memories_app/routes/home/model/response/avatar_response_model.dart'; 4 : import 'package:memories_app/routes/home/model/response/comments_response_model.dart'; 5 : import 'package:memories_app/routes/home/model/response/like_response_model.dart'; 6 : import 'package:memories_app/routes/home/model/story_model.dart'; 7 : import 'package:memories_app/routes/story_detail/model/request/comment_request_model.dart'; 8 : import 'package:memories_app/util/api_endpoints.dart'; 9 : 10 : abstract class StoryDetailRepository { 11 : Future<StoryModel> getStoryById({required int id}); 12 : 13 : Future<CommentResponseModel> getComments({required int id}); 14 : 15 : Future<AvatarResponseModel> getAvatarUrlById({required int id}); 16 : 17 : Future<LikeResponseModel> likeStoryById({required int id}); 18 : 19 : Future<CommentModel> postComment( 20 : {required int id, required CommentRequestModel requestModel}); 21 : } 22 : 23 : class StoryDetailRepositoryImp extends StoryDetailRepository { 24 : final NetworkManager _networkManager; 25 : 26 1 : StoryDetailRepositoryImp({NetworkManager? networkManager}) : _networkManager = networkManager ?? NetworkManager(); 27 : 28 1 : @override 29 : Future<StoryModel> getStoryById({required int id}) async { 30 : final Result result = 31 3 : await _networkManager.get(ApiEndpoints.buildStoryGetUrl(id)); 32 2 : return StoryModel.fromJson(result.json); 33 : } 34 : 35 1 : @override 36 : Future<CommentResponseModel> getComments({required int id}) async { 37 : final Result result = 38 3 : await _networkManager.get(ApiEndpoints.getCommentsByStoryId(id)); 39 2 : return CommentResponseModel.fromJson(result.json); 40 : } 41 : 42 1 : @override 43 : Future<AvatarResponseModel> getAvatarUrlById({required int id}) async { 44 : final Result result = 45 3 : await _networkManager.get(ApiEndpoints.getAvatarById(id)); 46 2 : return AvatarResponseModel.fromJson(result.json); 47 : } 48 : 49 1 : @override 50 : Future<LikeResponseModel> likeStoryById({required int id}) async { 51 : final Result result = 52 3 : await _networkManager.post(ApiEndpoints.likeStory(id)); 53 2 : return LikeResponseModel.fromJson(result.json); 54 : } 55 : 56 1 : @override 57 : Future<CommentModel> postComment( 58 : {required int id, required CommentRequestModel requestModel}) async { 59 1 : final Result result = await _networkManager 60 2 : .post(ApiEndpoints.postComment(id), body: requestModel); 61 2 : return CommentModel.fromJson(result.json); 62 : } 63 : }