Skip to content
Snippets Groups Projects
Commit 7d0d11da authored by Syed OMAR's avatar Syed OMAR
Browse files

There is now error handling for add services when the service already exists in the json file

parent adc52264
No related branches found
No related tags found
No related merge requests found
Pipeline #8320 canceled
......@@ -60,6 +60,19 @@ public class AddServiceSceneController {
if (password.equals(confirmUser)) {
try {
DataStorage ds = new DataStorage("master_login.json");
// Check if the service already exists
if (ds.getData(platform, username) != null) {
// If service exists, show error message
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Add Service");
alert.setHeaderText("Error");
alert.setContentText("Service already exists for this platform and username.");
alert.showAndWait();
return; // Exit method early if service already exists
}
// Add new service if it doesn't exist
ds.addData(platform, username, password);
ds.saveToJSON();
......@@ -69,6 +82,7 @@ public class AddServiceSceneController {
alert.setContentText("Service added successfully.");
alert.showAndWait();
// Load MainPage.fxml after success
Parent root = FXMLLoader.load(getClass().getResource("MainPage.fxml"));
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
stage.setScene(new Scene(root));
......@@ -77,6 +91,7 @@ public class AddServiceSceneController {
e.printStackTrace();
}
} else {
// Show error if passwords don't match
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Add Service");
alert.setHeaderText("Error");
......@@ -85,4 +100,5 @@ public class AddServiceSceneController {
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment