-
Notifications
You must be signed in to change notification settings - Fork 0
Booking confirmed #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b200421
72e05f1
89dc2a8
ef7d6bd
8b6e0c2
9964c30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential
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 |
||
| ); | ||
|
|
||
| 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; | ||
| // } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spinner default values.
The spinner is initialized with a default of
2guests (line 31), but after booking it resets to1(line 89). Consider using a consistent default value.Proposed fix to use consistent default value
Also applies to: 89-89
🤖 Prompt for AI Agents