Line data Source code
1 : import 'package:dio/dio.dart'; 2 : import 'package:memories_app/network/network_manager.dart'; 3 : import 'package:memories_app/routes/app/model/response/base_response_model.dart'; 4 : import 'package:memories_app/routes/home/model/response/stories_response_model.dart'; 5 : import 'package:memories_app/routes/login/model/user_details_response_model.dart'; 6 : import 'package:memories_app/routes/profile/model/request/update_biography_request_model.dart'; 7 : import 'package:memories_app/routes/profile/model/response/add_profile_photo_response_model.dart'; 8 : import 'package:memories_app/util/api_endpoints.dart'; 9 : import 'dart:io'; 10 : 11 : abstract class ProfileRepository { 12 : Future<UserDetailsResponseModel> getUserDetails(int? userId); 13 : 14 : Future<StoriesResponseModel> getOwnStories(int id); 15 : 16 : Future<UpdateBiographyRequestModel> updateBiography(String biography); 17 : 18 : Future<AddProfilePhotoResponseModel> addAvatar(File content); 19 : 20 : Future<BaseResponseModel> deleteAvatar(); 21 : 22 : Future<BaseResponseModel> followUser(int userId); 23 : } 24 : 25 : class ProfileRepositoryImp extends ProfileRepository { 26 : final NetworkManager _networkManager; 27 : 28 1 : ProfileRepositoryImp({NetworkManager? networkManager}) : _networkManager = networkManager ?? NetworkManager(); 29 : 30 1 : @override 31 : Future<UserDetailsResponseModel> getUserDetails(int? userId) async { 32 : final Result result = 33 3 : await _networkManager.get(ApiEndpoints.getUserDetails(userId: userId)); 34 2 : return UserDetailsResponseModel.fromJson(result.json); 35 : } 36 : 37 1 : @override 38 : Future<StoriesResponseModel> getOwnStories(int id) async { 39 : final Result result = 40 3 : await _networkManager.get(ApiEndpoints.getStoriesByAuthorId(id)); 41 2 : return StoriesResponseModel.fromJson(result.json); 42 : } 43 : 44 1 : @override 45 : Future<UpdateBiographyRequestModel> updateBiography(String biography) async { 46 2 : final Result result = await _networkManager.put( 47 : ApiEndpoints.updateBiography, 48 1 : body: UpdateBiographyRequestModel(biography: biography)); 49 2 : return UpdateBiographyRequestModel.fromJson(result.json); 50 : } 51 : 52 1 : @override 53 : Future<AddProfilePhotoResponseModel> addAvatar(File content) async { 54 2 : final Result result = await _networkManager.putFile( 55 : ApiEndpoints.avatar, 56 1 : formData: FormData.fromMap( 57 1 : <String, dynamic>{ 58 2 : "profile_photo": await MultipartFile.fromFile(content.path) 59 : }, 60 : ), 61 : ); 62 2 : return AddProfilePhotoResponseModel.fromJson(result.json); 63 : } 64 : 65 1 : @override 66 : Future<AddProfilePhotoResponseModel> deleteAvatar() async { 67 2 : final Result result = await _networkManager.delete(ApiEndpoints.avatar); 68 2 : return AddProfilePhotoResponseModel.fromJson(result.json); 69 : } 70 : 71 1 : @override 72 : Future<BaseResponseModel> followUser(int userId) async { 73 : final Result result = 74 3 : await _networkManager.post(ApiEndpoints.followUser(userId)); 75 2 : return BaseResponseModel.fromJson(result.json); 76 : } 77 : }