From aa07d61a3cdd8e49d34783fa0fa28e7f65d1a565 Mon Sep 17 00:00:00 2001 From: Varakh Date: Sun, 9 May 2021 10:59:14 +0200 Subject: [PATCH] Minor method refactor, release 1.3.3+12 --- CHANGELOG.md | 3 ++- lib/core/repositories/file_repository.dart | 6 +++--- lib/core/repositories/user_repository.dart | 2 +- lib/core/services/file_service.dart | 20 ++++++++++++-------- lib/core/services/user_service.dart | 11 +++++++---- lib/core/viewmodels/login_model.dart | 2 +- lib/core/viewmodels/upload_model.dart | 4 ++-- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2a6a3e..d82db82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # CHANGELOG -## 1.3.3+12 - UNRELEASED +## 1.3.3+12 * Automatically switch to initial tab when coming from the share menu +* Upgraded internal dependencies ## 1.3.2+11 * Add a slash to copied URLs diff --git a/lib/core/repositories/file_repository.dart b/lib/core/repositories/file_repository.dart index 6a233b8..0580f10 100644 --- a/lib/core/repositories/file_repository.dart +++ b/lib/core/repositories/file_repository.dart @@ -27,16 +27,16 @@ class FileRepository { return parsedResponse.data; } - Future delete(String id) async { + Future postDelete(String id) async { await _api.post('/file/delete', fields: {'ids[1]': id}); } - Future upload(List files, Map additionalFiles) async { + Future postUpload(List files, Map additionalFiles) async { var response = await _api.post('/file/upload', files: files, additionalFiles: additionalFiles); return UploadedResponse.fromJson(json.decode(response.body)); } - Future createMulti(List ids) async { + Future postCreateMultiPaste(List ids) async { Map multiPasteIds = Map(); ids.forEach((element) { diff --git a/lib/core/repositories/user_repository.dart b/lib/core/repositories/user_repository.dart index ffc289e..3482741 100644 --- a/lib/core/repositories/user_repository.dart +++ b/lib/core/repositories/user_repository.dart @@ -8,7 +8,7 @@ import '../services/api.dart'; class UserRepository { Api _api = locator(); - Future createApiKey( + Future postApiKey( String url, String username, String password, String accessLevel, String comment) async { _api.setUrl(url); diff --git a/lib/core/services/file_service.dart b/lib/core/services/file_service.dart index 9eca1c2..729f3c6 100644 --- a/lib/core/services/file_service.dart +++ b/lib/core/services/file_service.dart @@ -3,27 +3,31 @@ import 'dart:io'; import '../../core/repositories/file_repository.dart'; import '../../locator.dart'; +import '../models/rest/config.dart'; +import '../models/rest/history.dart'; +import '../models/rest/uploaded_multi_response.dart'; +import '../models/rest/uploaded_response.dart'; class FileService { final FileRepository _fileRepository = locator(); - Future getConfig(String url) async { + Future getConfig(String url) async { return await _fileRepository.getConfig(url); } - Future getHistory() async { + Future getHistory() async { return await _fileRepository.getHistory(); } - Future deletePaste(String id) async { - return await _fileRepository.delete(id); + Future deletePaste(String id) async { + return await _fileRepository.postDelete(id); } - Future upload(List files, Map additionalFiles) async { - return await _fileRepository.upload(files, additionalFiles); + Future uploadPaste(List files, Map additionalFiles) async { + return await _fileRepository.postUpload(files, additionalFiles); } - Future createMulti(List ids) async { - return await _fileRepository.createMulti(ids); + Future uploadMultiPaste(List ids) async { + return await _fileRepository.postCreateMultiPaste(ids); } } diff --git a/lib/core/services/user_service.dart b/lib/core/services/user_service.dart index 30eaecc..f0501f7 100644 --- a/lib/core/services/user_service.dart +++ b/lib/core/services/user_service.dart @@ -3,6 +3,8 @@ import 'dart:async'; import '../../locator.dart'; import '../enums/error_code.dart'; import '../error/service_exception.dart'; +import '../models/rest/apikeys_response.dart'; +import '../models/rest/create_apikey_response.dart'; import '../repositories/user_repository.dart'; import 'file_service.dart'; @@ -10,16 +12,17 @@ class UserService { final FileService _fileService = locator(); final UserRepository _userRepository = locator(); - Future createApiKey(String url, String username, String password, String accessLevel, String comment) async { - return await _userRepository.createApiKey(url, username, password, accessLevel, comment); + Future createApiKey( + String url, String username, String password, String accessLevel, String comment) async { + return await _userRepository.postApiKey(url, username, password, accessLevel, comment); } - Future getApiKeys() async { + Future getApiKeys() async { return await _userRepository.getApiKeys(); } /// Use 'getHistory' to check currently used API key to require 'apikey' access level - Future checkAccessLevelIsAtLeastApiKey() async { + Future checkAccessLevelIsAtLeastApiKey() async { try { await _fileService.getHistory(); } catch (e) { diff --git a/lib/core/viewmodels/login_model.dart b/lib/core/viewmodels/login_model.dart index 7e7d7c9..637e4bd 100644 --- a/lib/core/viewmodels/login_model.dart +++ b/lib/core/viewmodels/login_model.dart @@ -120,7 +120,7 @@ class LoginModel extends BaseModel { success = await _sessionService.login(url, apiKeyResponse.data['new_key']); } else { _sessionService.setApiConfig(url, apiKey); - success = await _userService.checkAccessLevelIsAtLeastApiKey(); + await _userService.checkAccessLevelIsAtLeastApiKey(); success = await _sessionService.login(url, apiKey); } errorMessage = null; diff --git a/lib/core/viewmodels/upload_model.dart b/lib/core/viewmodels/upload_model.dart index 9d53d26..495ee29 100644 --- a/lib/core/viewmodels/upload_model.dart +++ b/lib/core/viewmodels/upload_model.dart @@ -208,13 +208,13 @@ class UploadModel extends BaseModel { files = paths.map((e) => new File(e.path)).toList(); } - UploadedResponse response = await _fileService.upload(files, additionalFiles); + UploadedResponse response = await _fileService.uploadPaste(files, additionalFiles); response.data.ids.forEach((element) { uploadedPasteIds.putIfAbsent(element, () => false); }); if (createMulti && response.data.ids.length > 1) { - UploadedMultiResponse multiResponse = await _fileService.createMulti(response.data.ids); + UploadedMultiResponse multiResponse = await _fileService.uploadMultiPaste(response.data.ids); uploadedPasteIds.putIfAbsent(multiResponse.data.urlId, () => true); }