Skip to content

Feature/restaurant page#81

Merged
AnnaZiafar merged 3 commits into
mainfrom
feature/restaurantPage
Jan 14, 2026
Merged

Feature/restaurant page#81
AnnaZiafar merged 3 commits into
mainfrom
feature/restaurantPage

Conversation

@AnnaZiafar

@AnnaZiafar AnnaZiafar commented Jan 14, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • Restaurant pages now show address, cuisine, average price, rating, and a larger restaurant image; booking form is embedded directly on the restaurant page.
    • New standalone booking form UI with fields for guest details, date, time, and a Book action.
  • Style

    • Updated visual styling for restaurant pages, cards, and booking form.
    • Slightly larger main window size for improved layout.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 14, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Centralizes restaurant data via RestaurantHandler, enhances restaurant-detail UI and image loading, replaces booking-view.fxml with a new booking-form.fxml, updates main view layout, and tweaks scene size and CSS. Changes affect controllers, FXML, image handling, and restaurant card rendering.

Changes

Cohort / File(s) Summary
App entry / Scene
src/main/java/frontend/HelloFX.java
Scene size changed from 640x480 to 680x500.
Booking UI & Controller
src/main/java/frontend/controller/BookingController.java, src/main/resources/frontend/booking-view.fxml (removed), src/main/resources/frontend/booking-form.fxml (added)
Removed public setRestaurant(...) and restaurantNameLabel from BookingController; controller now uses RestaurantHandler.getCurrentRestaurant(). Replaced removed booking-view.fxml with new booking-form.fxml and wired BookTable action.
Restaurant details UI & Controller
src/main/java/frontend/controller/RestaurantController.java, src/main/resources/frontend/restaurant-view.fxml
RestaurantController gained new UI bindings, initialize() and setRestaurantData(...) to populate name, address, category, price, rating, and image. FXML root changed from restaurantRoot (VBox) to restaurantPageRoot (HBox) and now includes image area, details groups, and an fx:include of booking-form.fxml.
Main view layout & controller
src/main/resources/frontend/main-view.fxml, src/main/java/frontend/controller/MainController.java
main-view.fxml now wraps the FlowPane in a VBox with fx:id="mainArea". MainController added mainArea field and passes it to RestaurantCard instead of the old container.
Image handling & restaurant card
src/main/java/frontend/model/ImageHandler.java, src/main/java/frontend/view/RestaurantCard.java
ImageHandler signature for scaleAndCropImage reordered and new getRestaurantImage(Restaurant) added to load images from resources. RestaurantCard now constructs an ImageView inline using ImageHandler.getRestaurantImage(...), applies scaling/cropping and clipping.
Styling
src/main/resources/frontend/application.css
Added CSS classes and rules for restaurant page, booking form, icons, and restaurant card tweaks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐇 I nibbled code and found a thread,
Restaurant images neatly fed.
No setters now — the handler hums,
Forms and pages, rounded thumbs.
Hoppy builds and UI cheer, here we go! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feature/restaurant page' is partially related to the changeset, referring to a real aspect of the changes (restaurant page enhancements), but it is overly broad and uses a generic naming convention that doesn't clearly summarize the primary change. Replace the generic feature branch name with a more specific, descriptive title that highlights the main change, such as 'Add restaurant details page with booking form integration' or 'Refactor restaurant page UI with new data bindings and image handling'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
src/main/java/frontend/model/ImageHandler.java (1)

3-10: Unused import: RestaurantCard.

The import on line 4 (frontend.view.RestaurantCard) is not used anywhere in this file and should be removed.

🧹 Proposed fix
 import backend.entities.Restaurant;
-import frontend.view.RestaurantCard;
 import javafx.geometry.Rectangle2D;
src/main/java/frontend/view/RestaurantCard.java (1)

8-13: Unused imports.

Image (line 8) and Objects (line 13) are not used in this file and can be removed.

🧹 Proposed fix
 import frontend.model.SceneHandler;
 import javafx.scene.control.Label;
-import javafx.scene.image.Image;
 import javafx.scene.image.ImageView;
 import javafx.scene.layout.*;
 import javafx.scene.shape.Rectangle;
-
-import java.util.Objects;

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d909db6 and 3017262.

📒 Files selected for processing (3)
  • src/main/java/frontend/controller/RestaurantController.java
  • src/main/java/frontend/model/ImageHandler.java
  • src/main/java/frontend/view/RestaurantCard.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/frontend/controller/RestaurantController.java
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/frontend/view/RestaurantCard.java (1)
src/main/java/frontend/model/ImageHandler.java (1)
  • ImageHandler (12-46)
🔇 Additional comments (2)
src/main/java/frontend/model/ImageHandler.java (1)

13-33: LGTM!

The parameter reordering to (targetWidth, targetHeight) is more intuitive, and adding setSmooth(true) improves image rendering quality.

src/main/java/frontend/view/RestaurantCard.java (1)

29-36: LGTM on clip rectangle implementation.

The rectangle clip correctly binds to the ImageView dimensions and uses arc properties for rounded corners. The +50 offset on height ensures the bottom corners remain square while only rounding the top.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/frontend/controller/RestaurantController.java (1)

38-46: NullPointerException when restaurant is null.

setRestaurantData(restaurant) is called outside the null check on line 41. If restaurant is null, line 49 (restaurant.getName()) will throw an NPE.

Additionally, restaurantName.setText() is called twice (lines 42 and 49) - the first call is redundant.

🐛 Proposed fix
     `@FXML`
     private void initialize() {
         restaurant = RestaurantHandler.getCurrentRestaurant();
 
         if (restaurant != null) {
-            restaurantName.setText(restaurant.getName());
+            setRestaurantData(restaurant);
         }
-
-        setRestaurantData(restaurant);
     }
🤖 Fix all issues with AI agents
In `@src/main/java/frontend/controller/RestaurantController.java`:
- Around line 48-60: setRestaurantData may pass a null Image from
ImageHandler.getRestaurantImage into ImageHandler.scaleAndCropImage causing an
NPE; update setRestaurantData to capture the result of
ImageHandler.getRestaurantImage(restaurant) into a local Image variable (or
check restaurantImage.getImage()), check for null and if null either set a
fallback placeholder Image or skip calling ImageHandler.scaleAndCropImage, then
call restaurantImage.setImage(...) only with a non-null Image; ensure
javafx.scene.image.Image is imported if not already.

In `@src/main/java/frontend/model/ImageHandler.java`:
- Around line 35-44: getRestaurantImage currently returns null on failure which
causes NPEs when callers like RestaurantCard call scaleAndCropImage; change
getRestaurantImage to return a non-null fallback Image instead of null (e.g.,
load a bundled placeholder resource such as "/images/placeholder.png" and return
that when Objects.requireNonNull or resource loading fails), ensure the method
still logs the error, and leave scaleAndCropImage and RestaurantCard unchanged;
alternatively, if you prefer explicit handling, throw a custom unchecked
ImageLoadException from getRestaurantImage and update RestaurantCard to catch it
and handle the fallback there (use the symbols getRestaurantImage,
scaleAndCropImage, RestaurantCard).

In `@src/main/java/frontend/view/RestaurantCard.java`:
- Around line 25-37: ImageHandler.getRestaurantImage(restaurant) can return null
causing ImageHandler.scaleAndCropImage(view,...) to NPE; update RestaurantCard
to check the returned Image before calling scaleAndCropImage: call
ImageHandler.getRestaurantImage(restaurant) into a local variable, if it's null
set view to a default/placeholder Image (or skip scaling) and only call
ImageHandler.scaleAndCropImage(view, 100, 150) and apply the Rectangle clip when
the Image is non-null; ensure the local variable and ImageView "view" are used
so you don't call scaleAndCropImage or access image properties on a null image.

In `@src/main/resources/frontend/restaurant-view.fxml`:
- Around line 26-27: The fx:id values in the FXML contain a typo: rename fx:id
"adressIcon" to "addressIcon" and "restaurantAdress" to "restaurantAddress" in
the restaurant-view.fxml, and update the corresponding field names and any `@FXML`
injections/method references in RestaurantController.java (e.g., rename
fields/methods referencing adressIcon and restaurantAdress to addressIcon and
restaurantAddress) to keep identifiers consistent and restore bindings.
🧹 Nitpick comments (6)
src/main/java/frontend/controller/BookingController.java (2)

16-16: Potential null reference if timing is incorrect.

The restaurant field is initialized at declaration time, which occurs when the FXML is loaded. If RestaurantHandler.setCurrentRestaurant() hasn't been called before this controller is instantiated, restaurant will be null, causing a NullPointerException in BookTable().

Consider moving initialization to the initialize() method to ensure it occurs at a predictable point:

Proposed fix
-    private Restaurant restaurant = RestaurantHandler.getCurrentRestaurant();
+    private Restaurant restaurant;

Then in initialize():

`@FXML`
private void initialize() {
    restaurant = RestaurantHandler.getCurrentRestaurant();
    // ... existing code
}

78-81: Remove commented-out dead code.

Commented-out code adds noise and reduces readability. Since the setter pattern has been intentionally replaced with RestaurantHandler, this dead code should be removed entirely.

Proposed fix
-
-//    public void setRestaurant(Restaurant restaurant) {
-//        this.restaurant = restaurant;
-//    }
src/main/resources/frontend/booking-form.fxml (1)

38-38: Consider following Java naming conventions for methods.

The action handler #BookTable uses PascalCase, but Java convention for methods is camelCase (#bookTable). While this works functionally, it's inconsistent with standard Java naming conventions.

Proposed fix

In booking-form.fxml:

-        <Button text="Book" onAction="#BookTable" prefWidth="100" styleClass="bookingForm-Button"/>
+        <Button text="Book" onAction="#bookTable" prefWidth="100" styleClass="bookingForm-Button"/>

In BookingController.java:

-    private void BookTable() {
+    private void bookTable() {
src/main/java/frontend/model/ImageHandler.java (2)

3-10: Remove unused imports.

RestaurantCard (line 4) and Rectangle (line 8) are imported but not used in this file.

Proposed fix
 import backend.entities.Restaurant;
-import frontend.view.RestaurantCard;
 import javafx.geometry.Rectangle2D;
 import javafx.scene.image.Image;
 import javafx.scene.image.ImageView;
-import javafx.scene.shape.Rectangle;

40-41: Consider using a logging framework instead of System.out.

Using System.out.println and e.printStackTrace() for error handling is not ideal for production code. Consider using a logging framework (e.g., SLF4J, java.util.logging) for better control over log levels and output.

src/main/resources/frontend/restaurant-view.fxml (1)

6-9: Unused import.

The javafx.scene.image.Image import on line 8 appears unused in this FXML file. The ImageView is used, but Image objects are set programmatically in the controller.

♻️ Proposed fix
 <?import javafx.geometry.Insets?>
 <?import javafx.scene.image.ImageView?>
-<?import javafx.scene.image.Image?>
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e4753b0 and d909db6.

📒 Files selected for processing (11)
  • src/main/java/frontend/HelloFX.java
  • src/main/java/frontend/controller/BookingController.java
  • src/main/java/frontend/controller/MainController.java
  • src/main/java/frontend/controller/RestaurantController.java
  • src/main/java/frontend/model/ImageHandler.java
  • src/main/java/frontend/view/RestaurantCard.java
  • src/main/resources/frontend/application.css
  • src/main/resources/frontend/booking-form.fxml
  • src/main/resources/frontend/booking-view.fxml
  • src/main/resources/frontend/main-view.fxml
  • src/main/resources/frontend/restaurant-view.fxml
💤 Files with no reviewable changes (1)
  • src/main/resources/frontend/booking-view.fxml
🧰 Additional context used
🧬 Code graph analysis (4)
src/main/java/frontend/model/ImageHandler.java (1)
src/main/java/frontend/view/RestaurantCard.java (1)
  • RestaurantCard (15-54)
src/main/java/frontend/controller/BookingController.java (1)
src/main/java/frontend/model/RestaurantHandler.java (1)
  • RestaurantHandler (8-29)
src/main/java/frontend/controller/RestaurantController.java (1)
src/main/java/frontend/model/ImageHandler.java (1)
  • ImageHandler (12-46)
src/main/java/frontend/view/RestaurantCard.java (1)
src/main/java/frontend/model/ImageHandler.java (1)
  • ImageHandler (12-46)
🪛 Biome (2.1.2)
src/main/resources/frontend/application.css

[error] 28-28: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 29-29: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 30-30: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 31-31: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 34-34: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 35-35: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 36-36: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 37-37: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 40-40: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 41-41: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 42-42: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 43-43: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 48-48: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 49-49: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 50-50: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 53-53: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 54-54: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 57-57: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 58-58: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 61-61: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 62-62: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 63-63: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 66-66: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 67-67: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 70-70: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 71-71: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 72-72: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)

🔇 Additional comments (6)
src/main/java/frontend/HelloFX.java (1)

19-19: LGTM!

The scene size adjustment to 680x500 accommodates the expanded UI layout changes in this PR.

src/main/resources/frontend/application.css (1)

26-74: LGTM! New styling is well-organized.

The new CSS classes for the restaurant page and booking form are properly structured with clear section comments.

Note: The static analysis warnings from Biome are false positives — Biome is a web CSS linter that doesn't recognize JavaFX-specific -fx- prefixed properties (like -fx-font-family, -fx-padding, -fx-text-fill). These are valid and correct for JavaFX CSS.

src/main/resources/frontend/booking-form.fxml (1)

1-41: LGTM! Well-structured booking form layout.

The FXML structure is clean with proper use of layout containers, style classes, and FXML bindings. All fx:id values correctly correspond to the @FXML annotated fields in BookingController.

src/main/java/frontend/controller/MainController.java (1)

25-26: LGTM!

The new mainArea VBox field is properly injected and passed to RestaurantCard for scene navigation context, while restaurantContainer correctly remains the visual container for displaying cards.

Also applies to: 48-49

src/main/resources/frontend/main-view.fxml (1)

22-31: LGTM!

The restructured layout correctly nests restaurantContainer inside mainArea, aligning with the controller changes where mainArea is passed to RestaurantCard for scene navigation.

src/main/resources/frontend/restaurant-view.fxml (1)

9-40: Layout structure looks good.

The restructured layout with HBox root, nested VBox for content, spacer pane, and included booking form is well-organized and aligns with the controller changes.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +48 to 60
private void setRestaurantData(Restaurant restaurant){
restaurantName.setText(restaurant.getName());
adressIcon.setText("📍");
restaurantAdress.setText(restaurant.getAddress());
categoryIcon.setText("🍴");
restaurantCategory.setText(restaurant.getCategory());
meanPriceIcon.setText("$");
restaurantMeanPrice.setText(restaurant.getMeanPrice().toString() + " kr");
ratingIcon.setText("⭐ ");
restaurantRating.setText(String.valueOf(restaurant.getRating()));
restaurantImage.setImage(ImageHandler.getRestaurantImage(restaurant));
ImageHandler.scaleAndCropImage(restaurantImage, 250, 350);
}

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 image loading fails.

Same issue as in RestaurantCard: ImageHandler.getRestaurantImage() can return null, which will cause an NPE in scaleAndCropImage().

🛠️ Proposed fix
-        restaurantImage.setImage(ImageHandler.getRestaurantImage(restaurant));
-        ImageHandler.scaleAndCropImage(restaurantImage, 250, 350);
+        Image image = ImageHandler.getRestaurantImage(restaurant);
+        if (image != null) {
+            restaurantImage.setImage(image);
+            ImageHandler.scaleAndCropImage(restaurantImage, 250, 350);
+        }

Note: You'll need to add import javafx.scene.image.Image; if not already imported via the wildcard.

🤖 Prompt for AI Agents
In `@src/main/java/frontend/controller/RestaurantController.java` around lines 48
- 60, setRestaurantData may pass a null Image from
ImageHandler.getRestaurantImage into ImageHandler.scaleAndCropImage causing an
NPE; update setRestaurantData to capture the result of
ImageHandler.getRestaurantImage(restaurant) into a local Image variable (or
check restaurantImage.getImage()), check for null and if null either set a
fallback placeholder Image or skip calling ImageHandler.scaleAndCropImage, then
call restaurantImage.setImage(...) only with a non-null Image; ensure
javafx.scene.image.Image is imported if not already.

Comment on lines +35 to 44
public static Image getRestaurantImage(Restaurant restaurant) {
String imagePath = "/images/" + restaurant.getImagePath();
try {
return new Image(Objects.requireNonNull(ImageHandler.class.getResourceAsStream(imagePath)));
} catch (Exception e) {
System.out.println("Could not find: " + imagePath);
e.printStackTrace();
return null;
}
}

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

Returning null will cause NPE in downstream callers.

When image loading fails, this method returns null. However, RestaurantCard (line 25-26 in the relevant snippet) calls scaleAndCropImage() immediately after, which accesses image.getWidth() on line 16 of this file — causing a NullPointerException.

Consider either:

  1. Return a placeholder/fallback image instead of null
  2. Throw a custom exception to force callers to handle the error explicitly
  3. Document the null return and update callers to handle it
Option 1: Return a placeholder image (preferred)
 public static Image getRestaurantImage(Restaurant restaurant) {
     String imagePath = "/images/" + restaurant.getImagePath();
     try {
         return new Image(Objects.requireNonNull(ImageHandler.class.getResourceAsStream(imagePath)));
     } catch (Exception e) {
         System.out.println("Could not find: " + imagePath);
         e.printStackTrace();
-        return null;
+        // Return a placeholder image or handle gracefully
+        return new Image(Objects.requireNonNull(ImageHandler.class.getResourceAsStream("/images/placeholder.png")));
     }
 }
Option 2: Add null guard in RestaurantCard

In RestaurantCard.java:

Image image = ImageHandler.getRestaurantImage(restaurant);
if (image != null) {
    view.setImage(image);
    ImageHandler.scaleAndCropImage(view, 100, 150);
}
🤖 Prompt for AI Agents
In `@src/main/java/frontend/model/ImageHandler.java` around lines 35 - 44,
getRestaurantImage currently returns null on failure which causes NPEs when
callers like RestaurantCard call scaleAndCropImage; change getRestaurantImage to
return a non-null fallback Image instead of null (e.g., load a bundled
placeholder resource such as "/images/placeholder.png" and return that when
Objects.requireNonNull or resource loading fails), ensure the method still logs
the error, and leave scaleAndCropImage and RestaurantCard unchanged;
alternatively, if you prefer explicit handling, throw a custom unchecked
ImageLoadException from getRestaurantImage and update RestaurantCard to catch it
and handle the fallback there (use the symbols getRestaurantImage,
scaleAndCropImage, RestaurantCard).

Comment on lines +25 to +37
ImageView view = new ImageView();
view.setImage(ImageHandler.getRestaurantImage(restaurant));
ImageHandler.scaleAndCropImage(view, 100, 150);

//Rounds upper two corners of image, so it matches corners of VBox (container)
Rectangle clip = new Rectangle();
clip.widthProperty().bind(view.fitWidthProperty());
clip.heightProperty().bind(view.fitHeightProperty().add(50));
clip.setArcWidth(30);
clip.setArcHeight(30);

view.setClip(clip);
this.getChildren().add(view);

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 image loading fails.

ImageHandler.getRestaurantImage() returns null when the image cannot be found (see ImageHandler.java). If this happens, scaleAndCropImage() will throw an NPE when accessing image.getWidth() on the null image.

🛠️ Proposed fix
         ImageView view = new ImageView();
-        view.setImage(ImageHandler.getRestaurantImage(restaurant));
-        ImageHandler.scaleAndCropImage(view, 100, 150);
+        Image image = ImageHandler.getRestaurantImage(restaurant);
+        if (image != null) {
+            view.setImage(image);
+            ImageHandler.scaleAndCropImage(view, 100, 150);
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ImageView view = new ImageView();
view.setImage(ImageHandler.getRestaurantImage(restaurant));
ImageHandler.scaleAndCropImage(view, 100, 150);
//Rounds upper two corners of image, so it matches corners of VBox (container)
Rectangle clip = new Rectangle();
clip.widthProperty().bind(view.fitWidthProperty());
clip.heightProperty().bind(view.fitHeightProperty().add(50));
clip.setArcWidth(30);
clip.setArcHeight(30);
view.setClip(clip);
this.getChildren().add(view);
ImageView view = new ImageView();
Image image = ImageHandler.getRestaurantImage(restaurant);
if (image != null) {
view.setImage(image);
ImageHandler.scaleAndCropImage(view, 100, 150);
}
//Rounds upper two corners of image, so it matches corners of VBox (container)
Rectangle clip = new Rectangle();
clip.widthProperty().bind(view.fitWidthProperty());
clip.heightProperty().bind(view.fitHeightProperty().add(50));
clip.setArcWidth(30);
clip.setArcHeight(30);
view.setClip(clip);
this.getChildren().add(view);
🤖 Prompt for AI Agents
In `@src/main/java/frontend/view/RestaurantCard.java` around lines 25 - 37,
ImageHandler.getRestaurantImage(restaurant) can return null causing
ImageHandler.scaleAndCropImage(view,...) to NPE; update RestaurantCard to check
the returned Image before calling scaleAndCropImage: call
ImageHandler.getRestaurantImage(restaurant) into a local variable, if it's null
set view to a default/placeholder Image (or skip scaling) and only call
ImageHandler.scaleAndCropImage(view, 100, 150) and apply the Rectangle clip when
the Image is non-null; ensure the local variable and ImageView "view" are used
so you don't call scaleAndCropImage or access image properties on a null image.

Comment on lines +26 to +27
<Label fx:id="adressIcon" styleClass="restaurantPage-Icon"/>
<Label fx:id="restaurantAdress" styleClass="restaurantPage-Info"/>

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

Typo: "adress" should be "address".

The fx:id values adressIcon and restaurantAdress contain a spelling error. This should be addressIcon and restaurantAddress for consistency and clarity. The corresponding fields in RestaurantController.java would also need to be renamed.

🤖 Prompt for AI Agents
In `@src/main/resources/frontend/restaurant-view.fxml` around lines 26 - 27, The
fx:id values in the FXML contain a typo: rename fx:id "adressIcon" to
"addressIcon" and "restaurantAdress" to "restaurantAddress" in the
restaurant-view.fxml, and update the corresponding field names and any `@FXML`
injections/method references in RestaurantController.java (e.g., rename
fields/methods referencing adressIcon and restaurantAdress to addressIcon and
restaurantAddress) to keep identifiers consistent and restore bindings.

@AnnaZiafar
AnnaZiafar merged commit a754c61 into main Jan 14, 2026
1 of 2 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant