Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/main/java/backend/DataSeeder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/backend/factories/BookingFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/backend/factories/CustomerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/backend/repositories/BaseRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {

public Class<T> entityClass;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/backend/services/BookingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/backend/services/CustomerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/frontend/controller/BookingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/frontend/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,26 @@ 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();
List<Restaurant> restaurantList = RestaurantHandler.getResturantList(restaurant);
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<Restaurant> restaurants){
restaurantContainer.getChildren().clear();
for(Restaurant r : restaurants){
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/frontend/model/RestaurantHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Restaurant> getResturantList(String name){
RestaurantRepo repo = new RestaurantRepo();
List<Restaurant> result = repo.findRestaurantsMatchingSearch(name);
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/backend/services/BookingServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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 {
Expand Down
Loading