Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 0 additions & 76 deletions src/main/java/backend/entities/Customer.java

This file was deleted.

75 changes: 43 additions & 32 deletions src/main/java/frontend/controller/BookingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,64 +24,75 @@ public class BookingController {
@FXML private DatePicker datePicker;
@FXML private ComboBox<LocalTime> startTimeBox;


@FXML private Label statusLabel;

@FXML
private void initialize() {

guestsSpinner.setValueFactory(
new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 8, 2)
);

guestsSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 8, 2));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Inconsistent spinner default values.

The spinner is initialized with a default of 2 guests (line 31), but after booking it resets to 1 (line 89). Consider using a consistent default value.

Proposed fix to use consistent default value
-        guestsSpinner.getValueFactory().setValue(1);
+        guestsSpinner.getValueFactory().setValue(2);

Also applies to: 89-89

🤖 Prompt for AI Agents
In `@src/main/java/frontend/controller/BookingController.java` at line 31, The
guests spinner default is inconsistent: it’s initialized with
SpinnerValueFactory.IntegerSpinnerValueFactory(1, 8, 2) (default 2) but later
reset to 1 after booking; update one side so both use the same default (pick
either default 1 or 2) — locate the initialization of guestsSpinner (where
SpinnerValueFactory.IntegerSpinnerValueFactory is used) and the post-booking
reset (the code that sets the spinner value after booking, e.g.,
guestsSpinner.getValueFactory().setValue(...) or a new ValueFactory) and make
them match (set the reset to the same default as the initial factory or change
the initial factory default to the reset value).

for (int h = 12; h <= 20; h++) {
startTimeBox.getItems().add(LocalTime.of(h, 0));
// startTimeBox.getItems().add(LocalTime.of(h, 15));
// startTimeBox.getItems().add(LocalTime.of(h, 30));
}
}

/**
* Handles the book table button action.
*
* Reads user input from the form, validates required fields,
* creates a booking, and shows the result to the user.
*/
@FXML
private void BookTable() {
try {
LocalDate date = datePicker.getValue();
LocalTime startTime = startTimeBox.getValue();

if (date == null || startTime == null) {
statusLabel.setText("Please select date and time");
if (firstNameField.getText().isEmpty() || lastNameField.getText().isEmpty() ||
date == null || startTime == null) {
statusLabel.setText("Please fill in all required fields");
statusLabel.setStyle("-fx-text-fill: red;");
return;
}

LocalTime endTime = startTime.plusHours(2);

Booking booking = bookingService.bookTable(
restaurant,
firstNameField.getText(),
lastNameField.getText(),
emailField.getText(),
phoneField.getText(),
guestsSpinner.getValue(),
startTime,
endTime,
date
restaurant,
firstNameField.getText(),
lastNameField.getText(),
emailField.getText(),
phoneField.getText(),
guestsSpinner.getValue(),
startTime,
endTime,
date
);

statusLabel.setText(
"Booking confirmed! ID: " + booking.getId()
statusLabel.setText("Booking confirmed! ID: " + booking.getId());
statusLabel.setStyle("-fx-text-fill: green;");

Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Booking confirmed");
alert.setHeaderText(null);
alert.setContentText(
"Booking confirmed for " + firstNameField.getText() + " " + lastNameField.getText() + "\n" +
"Restaurant: " + restaurant.getName() + "\n" +
"Date & Time: " + date + " at " + startTime + "\n" +
"Guests: " + guestsSpinner.getValue()
Comment on lines 52 to +74

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Potential NullPointerException if restaurant is null.

restaurant is initialized from RestaurantHandler.getCurrentRestaurant() at line 16 and used without a null check. If no restaurant is selected, restaurant.getName() at line 72 (and the booking call at line 52) will throw an NPE.

Proposed fix to add null check in validation
-            if (firstNameField.getText().isEmpty() || lastNameField.getText().isEmpty() ||
-                    date == null || startTime == null) {
+            if (restaurant == null || firstNameField.getText().isEmpty() || lastNameField.getText().isEmpty() ||
+                    date == null || startTime == null) {
                 statusLabel.setText("Please fill in all required fields");
                 statusLabel.setStyle("-fx-text-fill: red;");
                 return;
             }
🤖 Prompt for AI Agents
In `@src/main/java/frontend/controller/BookingController.java` around lines 52 -
74, BookingController uses restaurant from
RestaurantHandler.getCurrentRestaurant() without checking for null before
calling bookingService.bookTable(...) and restaurant.getName(), which can cause
NPEs; add a null check for restaurant at the start of the booking flow (before
calling bookTable and before referencing restaurant.getName()), and if null, set
statusLabel to an error message (red) and show an Alert with a clear message to
select a restaurant, then return early so bookTable and subsequent uses of
restaurant are never called.

);

DialogPane dialogPane = alert.getDialogPane();
var contentLabel = dialogPane.lookup(".content.label");
if (contentLabel != null) {
contentLabel.setStyle("-fx-text-fill: #CF6720; -fx-font-weight: bold; -fx-font-family: 'Agency FB'; -fx-font-size: 16px;");
}

alert.showAndWait();

firstNameField.clear();
lastNameField.clear();
phoneField.clear();
emailField.clear();
guestsSpinner.getValueFactory().setValue(1);
datePicker.setValue(null);
startTimeBox.getSelectionModel().clearSelection();

} catch (Exception e) {
statusLabel.setText(e.getMessage());
statusLabel.setStyle("-fx-text-fill: red;");
}
}

// public void setRestaurant(Restaurant restaurant) {
// this.restaurant = restaurant;
// }
}
}
Loading