AppData : simplification du système. Suppression de la nécéssité de passer un objet User pour réaliser les opérations

This commit is contained in:
Maximilien LEDOUX 2022-03-11 16:00:05 +01:00
parent 1a3b796f61
commit 18df312592
2 changed files with 16 additions and 19 deletions

View File

@ -68,8 +68,6 @@ public class AppData {
}
/**
* Use this method when a user signs up.
*
@ -98,15 +96,15 @@ public class AppData {
* True indicates the success of the operation.
* False indicates the failure of the operation.
*
* @param file The file to add
* @param user The user who wants to add the file
* @param file The file to add
* @param userName The name of the user who wants to add the file
* @return True if the user is found and a file with the same name doesn't already exist for this user. False otherwise.
*/
public boolean addFileFor(File file, User user) {
if (!this.users.containsKey(user.getName())) {
public boolean addFileFor(File file, String userName) {
if (!this.users.containsKey(userName)) {
return false;
} else {
this.users.get(user.getName()).addFile(file);
this.users.get(userName).addFile(file);
return true;
}
}
@ -119,28 +117,28 @@ public class AppData {
* False indicates the failure of the operation.
*
* @param fileName The name of the file to delete
* @param user The user who wants to delete the file
* @param userName The name of the user who wants to delete the file
* @return True if the user is found and the file was deleted. False otherwise.
*/
public boolean deleteFileOf(String fileName, User user) {
if (!this.users.containsKey(user.getName())) {
public boolean deleteFileOf(String fileName, String userName) {
if (!this.users.containsKey(userName)) {
return false;
} else {
return this.users.get(user.getName()).deleteFile(fileName);
return this.users.get(userName).deleteFile(fileName);
}
}
/**
* @param user The user who wants to add a storage for their file
* @param file The file that needs a new storage
* @param storage The storage to add
* @param userName The name of the user who wants to add a storage for their file
* @param file The file that needs a new storage
* @param storage The storage to add
* @return True if the storage was added. False otherwise.
*/
public boolean addStorage(User user, File file, String storage) {
if (!this.users.containsKey(user.getName())) {
public boolean addStorage(String userName, File file, String storage) {
if (!this.users.containsKey(userName)) {
return false;
} else {
return this.users.get(user.getName()).addStorage(file, storage);
return this.users.get(userName).addStorage(file, storage);
}
}

View File

@ -40,9 +40,8 @@ public class RepositoryTests {
storage.add("StorBackEnd1");
File file1 = new File("File1", 15, "8d8d8d8d", storage);
files.put(file1.getName(), file1);
User user1 = new User("User1", "Password", "djdjjdj", files);
appData.setAppConfig(appConfig);
//appData.addUser(user1);
appData.addUser("User1", "Password", "djdjjdj");
JsonAdapter jsonAdapter = new JsonAdapter(appData);
//WHEN Repository calls save method
String filePath = "src/test/resources/test.json";