From fce9d1598dc060f44934ef0290b1183de3180db5 Mon Sep 17 00:00:00 2001 From: EraiicPhu Date: Wed, 14 Jan 2026 21:35:07 +0100 Subject: [PATCH 1/2] initial commit --- src/main/java/backend/factories/BookingFactory.java | 7 ++++++- src/main/java/backend/factories/CustomerFactory.java | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/backend/factories/BookingFactory.java b/src/main/java/backend/factories/BookingFactory.java index 153222a3..6e6c4692 100644 --- a/src/main/java/backend/factories/BookingFactory.java +++ b/src/main/java/backend/factories/BookingFactory.java @@ -7,7 +7,12 @@ import java.time.LocalTime; public class BookingFactory { - + /** + * Creates a booking for a restaurant. + * + * Checks that all required information is provided and valid. + * The booking always lasts for 2 hours starting from the given start time. + */ public Booking createBooking( Restaurant restaurant, Customer customer, diff --git a/src/main/java/backend/factories/CustomerFactory.java b/src/main/java/backend/factories/CustomerFactory.java index fa73108f..13a5da00 100644 --- a/src/main/java/backend/factories/CustomerFactory.java +++ b/src/main/java/backend/factories/CustomerFactory.java @@ -4,6 +4,12 @@ public class CustomerFactory { +/** + * Creates a new customer. + * + * Validates the customer's name, phone number, and email address + * before creating the customer. + */ public Customer createCustomer( String firstName, String lastName, From 06e06ac464b363217652ffd477726178f67e8ed8 Mon Sep 17 00:00:00 2001 From: EraiicPhu Date: Wed, 14 Jan 2026 21:50:16 +0100 Subject: [PATCH 2/2] added method description with docstrings --- src/main/java/backend/DataSeeder.java | 6 ++++++ src/main/java/backend/repositories/BaseRepo.java | 7 ++++++- src/main/java/backend/services/BookingService.java | 13 +++++++++++++ src/main/java/backend/services/CustomerService.java | 8 ++++++++ .../java/frontend/controller/BookingController.java | 7 ++++++- .../java/frontend/controller/MainController.java | 13 +++++++++++++ src/main/java/frontend/model/RestaurantHandler.java | 13 +++++++++++++ .../java/backend/services/BookingServiceTest.java | 9 +++++++++ 8 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/main/java/backend/DataSeeder.java b/src/main/java/backend/DataSeeder.java index 272b4318..857848d2 100644 --- a/src/main/java/backend/DataSeeder.java +++ b/src/main/java/backend/DataSeeder.java @@ -5,6 +5,12 @@ import jakarta.persistence.EntityTransaction; import java.math.BigDecimal; import java.util.List; +/** + * Utility class for populating the database with initial test data. + * + * Adds sample restaurants, tables, and customers if they do not + * already exist in the database. + */ public class DataSeeder { diff --git a/src/main/java/backend/repositories/BaseRepo.java b/src/main/java/backend/repositories/BaseRepo.java index 674d5bf5..1f63c4aa 100644 --- a/src/main/java/backend/repositories/BaseRepo.java +++ b/src/main/java/backend/repositories/BaseRepo.java @@ -6,7 +6,12 @@ import java.util.List; import java.util.function.Consumer; import java.util.function.Function; - +/** + * Base repository class that provides common database operations. + * + * Handles basic CRUD operations and transaction management + * for any JPA entity. + */ public abstract class BaseRepo { public Class entityClass; diff --git a/src/main/java/backend/services/BookingService.java b/src/main/java/backend/services/BookingService.java index 07a8d9e6..40c6d6b3 100644 --- a/src/main/java/backend/services/BookingService.java +++ b/src/main/java/backend/services/BookingService.java @@ -13,7 +13,20 @@ import java.time.LocalTime; import java.util.*; +/** + * Service responsible for handling table bookings. + * + * Creates customers if needed, checks table availability, + * prevents double bookings, and saves the booking. + */ + public class BookingService { +/** + * Books a table at a restaurant for a specific date and time. + * + * Validates input, finds an available table with enough capacity, + * prevents double bookings, creates the booking, and saves it. + */ private final BookingRepo bookingRepo = new BookingRepo(); private final DiningTableRepo diningTableRepo = new DiningTableRepo(); diff --git a/src/main/java/backend/services/CustomerService.java b/src/main/java/backend/services/CustomerService.java index 59e1832b..617aaf4d 100644 --- a/src/main/java/backend/services/CustomerService.java +++ b/src/main/java/backend/services/CustomerService.java @@ -9,6 +9,14 @@ public class CustomerService { private final CustomerRepo customerRepo = new CustomerRepo(); private final CustomerFactory customerFactory = new CustomerFactory(); + +/** + * Finds an existing customer or creates a new one. + * + * Searches for a customer using first name, last name, + * and phone number. If no customer is found, a new one is created + * and saved. + */ public Customer createOrFetchCustomer( String firstName, String lastName, diff --git a/src/main/java/frontend/controller/BookingController.java b/src/main/java/frontend/controller/BookingController.java index 945f403f..f7dbd988 100644 --- a/src/main/java/frontend/controller/BookingController.java +++ b/src/main/java/frontend/controller/BookingController.java @@ -41,7 +41,12 @@ private void initialize() { } } - + /** + * 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 { diff --git a/src/main/java/frontend/controller/MainController.java b/src/main/java/frontend/controller/MainController.java index 8de13f63..8e2644a5 100644 --- a/src/main/java/frontend/controller/MainController.java +++ b/src/main/java/frontend/controller/MainController.java @@ -35,6 +35,13 @@ private void initialize() { displayRestaurants(allRestaurants); } + + /** + * Handles restaurant search input. + * + * Searches for restaurants based on the user's input + * and updates the displayed list. + */ @FXML public void handleRestaurantSearch(ActionEvent event){ String restaurant = searchRestaurantField.getText(); @@ -42,6 +49,12 @@ public void handleRestaurantSearch(ActionEvent event){ displayRestaurants(restaurantList); } + + /** + * Displays a list of restaurants in the UI. + * + * Clears the current view and adds a card for each restaurant. + */ private void displayRestaurants(List restaurants){ restaurantContainer.getChildren().clear(); for(Restaurant r : restaurants){ diff --git a/src/main/java/frontend/model/RestaurantHandler.java b/src/main/java/frontend/model/RestaurantHandler.java index 36d905dd..1d7703c1 100644 --- a/src/main/java/frontend/model/RestaurantHandler.java +++ b/src/main/java/frontend/model/RestaurantHandler.java @@ -5,6 +5,12 @@ import java.util.List; +/** + * Helper class for handling restaurant selection and search. + * + * Stores the currently selected restaurant and provides + * search functionality. + */ public class RestaurantHandler { private static Restaurant currentRestaurant; @@ -17,6 +23,13 @@ public static void setCurrentRestaurant(Restaurant restaurant) { currentRestaurant = restaurant; } + + /** + * Searches for restaurants matching the given name. + * + * If no restaurants are found, all restaurants are returned. + * + */ public static List getResturantList(String name){ RestaurantRepo repo = new RestaurantRepo(); List result = repo.findRestaurantsMatchingSearch(name); diff --git a/src/test/java/backend/services/BookingServiceTest.java b/src/test/java/backend/services/BookingServiceTest.java index ddb2f20c..d51f12aa 100644 --- a/src/test/java/backend/services/BookingServiceTest.java +++ b/src/test/java/backend/services/BookingServiceTest.java @@ -42,6 +42,10 @@ public class BookingServiceTest { ) ); + /** + * Configures database connection properties + * before running the tests. + */ @BeforeAll static void wireDbProperties() { System.setProperty("APP_JDBC_URL", mysql.getJdbcUrl()); @@ -51,6 +55,11 @@ static void wireDbProperties() { } + /** + * Verifies that the test database connection works. + * + * Also clears the Booking table before running other tests. + */ @Test @Order(0) void testConnection() throws SQLException {