From 2093b1b82c31f0e97df497f63702f06a7972e5e6 Mon Sep 17 00:00:00 2001 From: Kiyan Date: Sat, 4 Oct 2025 08:19:04 +0200 Subject: [PATCH] Refactor image handling in Photo Gallery - Update Java version in pom.xml from 21 to 17. - Modify PageController to retrieve image file names instead of HTML. - Implement getImageFileNames method in PhotoService and ImageHtmlBuilder. - Update index.html to display images using Thymeleaf with new data structure. --- pom.xml | 3 +- .../Controller/PageController.java | 5 +- .../Services/ImageHtmlBuilder.java | 29 +- .../PhotoGallery/Services/PhotoService.java | 4 +- src/main/resources/templates/index.html | 327 ++++++++++-------- 5 files changed, 191 insertions(+), 177 deletions(-) diff --git a/pom.xml b/pom.xml index 15e79b6..a8b179a 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ - 21 + 17 @@ -85,6 +85,7 @@ org.apache.maven.plugins maven-compiler-plugin + ${java.version} org.projectlombok diff --git a/src/main/java/com/example/PhotoGallery/Controller/PageController.java b/src/main/java/com/example/PhotoGallery/Controller/PageController.java index ad700d4..9995fd6 100644 --- a/src/main/java/com/example/PhotoGallery/Controller/PageController.java +++ b/src/main/java/com/example/PhotoGallery/Controller/PageController.java @@ -1,6 +1,7 @@ package com.example.PhotoGallery.Controller; import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -15,8 +16,8 @@ public class PageController { @GetMapping("/") public String index(Model model) { - String imagesHtml = photoService.buildImageHtml(model); - model.addAttribute("images", imagesHtml); + List imageFileNames = photoService.getImageFileNames(); + model.addAttribute("imageFileNames", imageFileNames); return "index"; } diff --git a/src/main/java/com/example/PhotoGallery/Services/ImageHtmlBuilder.java b/src/main/java/com/example/PhotoGallery/Services/ImageHtmlBuilder.java index 9e568a1..9e87725 100644 --- a/src/main/java/com/example/PhotoGallery/Services/ImageHtmlBuilder.java +++ b/src/main/java/com/example/PhotoGallery/Services/ImageHtmlBuilder.java @@ -1,8 +1,8 @@ package com.example.PhotoGallery.Services; import java.io.File; +import java.util.ArrayList; import java.util.List; -import java.util.Random; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,36 +16,17 @@ public class ImageHtmlBuilder { @Autowired private PhotoRepo photoRepo; - public String htmlImageBuilder() { - String html = ""; + public List getImageFileNames() { + List fileNames = new ArrayList<>(); List allPhotos = photoRepo.findAll(); for (Photo photo : allPhotos) { String thumbnailPath = photo.getThumbnail_path(); String filename = new File(thumbnailPath).getName(); - - // if (metaData.getDate is before x and after y) - html = createHtml(filename); - //if searching && is search in tag - //html createHtml(filename); - + fileNames.add(filename); } - return html; + return fileNames; } - - private String createHtml(String fileName) { - StringBuilder html = new StringBuilder(); - - html.append("
") - .append("") - .append("
"); - - - return html.toString(); - } - } diff --git a/src/main/java/com/example/PhotoGallery/Services/PhotoService.java b/src/main/java/com/example/PhotoGallery/Services/PhotoService.java index 2ad1e16..709ea04 100644 --- a/src/main/java/com/example/PhotoGallery/Services/PhotoService.java +++ b/src/main/java/com/example/PhotoGallery/Services/PhotoService.java @@ -25,8 +25,8 @@ public class PhotoService { databasePopulation.populateDatabase(); } - public String buildImageHtml(Model model) { - return imageHtmlBuilder.htmlImageBuilder(); + public List getImageFileNames() { + return imageHtmlBuilder.getImageFileNames(); } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index d63faf7..a52a1ec 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -1,170 +1,201 @@ + - - -Photo Gallery + + + Photo Gallery - - + + - + .navbar-brand { + font-weight: 600; + font-size: 1.5rem; + } + + /* Masonry Grid */ + .gallery-container { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); + grid-auto-rows: 10px; + gap: 10px; + } + + .masonry-item img { + width: 100%; + height: auto; + border-radius: 10px; + box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15); + cursor: pointer; + transition: transform 0.3s ease, box-shadow 0.3s ease; + } + + .masonry-item img:hover { + transform: scale(1.03); + box-shadow: 0 16px 30px rgba(0, 0, 0, 0.25); + } + + /* Modal styling */ + .modal-content { + background-color: rgba(0, 0, 0, 0.95); + border: none; + border-radius: 10px; + } + + .modal-body img { + max-height: 85vh; + border-radius: 10px; + } + + .modal-navigation { + position: absolute; + top: 50%; + width: 100%; + display: flex; + justify-content: space-between; + transform: translateY(-50%); + padding: 0 1rem; + } + + .modal-navigation button { + background: rgba(0, 0, 0, 0.5); + border: none; + color: #fff; + font-size: 2rem; + border-radius: 50%; + width: 50px; + height: 50px; + cursor: pointer; + transition: background 0.2s; + } + + .modal-navigation button:hover { + background: rgba(0, 0, 0, 0.8); + } + - - + + - -
-

Welcome To The Gallery

-

Memories

-
+ +
+

Welcome To The Gallery

+

Memories

+
- - - - -