Преглед изворни кода

Document Texts List Controller

Andrew Grant пре 6 месеци
родитељ
комит
3999bd33b5

+ 42 - 0
src/main/java/scot/carricksoftware/grants/constants/TextAttributeConstants.java

@@ -0,0 +1,42 @@
+/*
+ * Copyright (c)  08 Feb 2025, Andrew Grant of Carrick Software .
+ * All rights reserved.
+ */
+
+package scot.carricksoftware.grants.constants;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class TextAttributeConstants {
+
+    private TextAttributeConstants() {
+        // to stop checkstyle complaining
+    }
+
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXTS = "document_texts";
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT_COMMAND = "document_text_Command";
+
+    @SuppressWarnings("unused")
+    public static final String PERSON_IMAGES = "personImages";
+    @SuppressWarnings({"unused"})
+    public static final String PERSON_IMAGE_COMMAND = "personImageCommand";
+
+
+    @SuppressWarnings("unused")
+    public static final String PLACE_IMAGES = "placeImages";
+    @SuppressWarnings({"unused"})
+    public static final String PLACE_IMAGE_COMMAND = "placeImageCommand";
+
+
+
+
+
+
+}
+
+
+
+

+ 47 - 0
src/main/java/scot/carricksoftware/grants/constants/TextMappingConstants.java

@@ -0,0 +1,47 @@
+/*
+ * Copyright (c)  08 Feb 2025, Andrew Grant of Carrick Software .
+ * All rights reserved.
+ */
+
+package scot.carricksoftware.grants.constants;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class TextMappingConstants {
+
+    private TextMappingConstants() {
+        // to stop checkstyle complaining
+    }
+
+
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT_LIST = "/documentTexts";
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT_NEXT = "/documentTexts/next";
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT_PREVIOUS = "/documentTexts/prev";
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT_REWIND = "/documentTexts/rewind";
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT_FF = "/documentTexts/ff";
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT_NEW = "/documentText/new";
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT = "/documentText";
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT_SHOW = "/documentText/{id}/show";
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT_DELETE = "/documentText/{id}/delete";
+    @SuppressWarnings({"unused"})
+    public static final String DOCUMENT_TEXT_EDIT = "documentText/{id}/edit";
+
+
+  
+}
+
+
+
+
+
+

+ 3 - 0
src/main/java/scot/carricksoftware/grants/constants/ViewConstants.java

@@ -56,5 +56,8 @@ public class ViewConstants {
 
     public static final String PLACE_IMAGE_LIST = "images/placeImage/list";
     public static final String PLACE_IMAGE_FORM = "images/placeImage/form";
+
+    public static final String DOCUMENT_TEXT_LIST = "text/documentText/list";
+    public static final String DOCUMENT_TEXT_FORM = "text/documentText/form";
 }
 

+ 29 - 0
src/main/java/scot/carricksoftware/grants/controllers/text/documenttext/DocumentTextListController.java

@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 29/03/2025, 13:08. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.controllers.text.documenttext;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.PathVariable;
+
+@SuppressWarnings("unused")
+@Controller
+public interface DocumentTextListController {
+
+    String getListPage(final Model model);
+
+    String getNextPage(final Model model);
+
+    String getPreviousPage(final Model model);
+
+    String getFirstPage(final Model model);
+
+    String getLastPage(final Model model);
+
+    String DocumentTextDelete(@PathVariable String id);
+
+    int getPageNumber();
+}

+ 104 - 0
src/main/java/scot/carricksoftware/grants/controllers/text/documenttext/DocumentTextListControllerImpl.java

@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 29/03/2025, 13:08. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.controllers.text.documenttext;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import scot.carricksoftware.grants.constants.*;
+import scot.carricksoftware.grants.controllers.ControllerHelper;
+import scot.carricksoftware.grants.services.images.image.ImageService;
+
+import static java.lang.Integer.max;
+
+@Controller
+public class DocumentTextListControllerImpl implements DocumentTextListController {
+
+    private static final Logger logger = LogManager.getLogger(DocumentTextListControllerImpl.class);
+
+
+    private int currentPage = 0;
+    private final ControllerHelper controllerHelper;
+    private final ImageService imageService;
+
+    public DocumentTextListControllerImpl(ControllerHelper controllerHelper,
+                                          ImageService imageService) {
+        this.controllerHelper = controllerHelper;
+        this.imageService = imageService;
+    }
+
+    @SuppressWarnings("SameReturnValue")
+    @GetMapping(TextMappingConstants.DOCUMENT_TEXT_LIST)
+    @Override
+    public final String getListPage(final Model model) {
+        logger.debug("DocumentTextListControllerImpl::getImagePage");
+        currentPage = 0;
+        return sendAttributesAndReturn(model);
+    }
+
+    @SuppressWarnings("SameReturnValue")
+    private String sendAttributesAndReturn(Model model) {
+        model.addAttribute(TextAttributeConstants.DOCUMENT_TEXTS, imageService.getPagedImages(currentPage));
+        controllerHelper.addAttributes(model);
+        return ViewConstants.DOCUMENT_TEXT_LIST;
+    }
+
+    @SuppressWarnings("SameReturnValue")
+    @GetMapping(TextMappingConstants.DOCUMENT_TEXT_NEXT)
+    @Override
+    public final String getNextPage(final Model model) {
+        logger.debug("DocumentTextListControllerImpl::getNextPage");
+        currentPage++;
+        return sendAttributesAndReturn(model);
+    }
+
+    @SuppressWarnings("SameReturnValue")
+    @GetMapping(TextMappingConstants.DOCUMENT_TEXT_PREVIOUS)
+    @Override
+    public final String getPreviousPage(final Model model) {
+        logger.debug("DocumentTextListControllerImpl::getPreviousPage");
+        currentPage = max(0, currentPage - 1);
+        return sendAttributesAndReturn(model);
+    }
+
+    @SuppressWarnings("SameReturnValue")
+    @GetMapping(TextMappingConstants.DOCUMENT_TEXT_REWIND)
+    public final String getFirstPage(final Model model) {
+        logger.debug("DocumentTextListControllerImpl::getFirstPage");
+        currentPage = 0;
+        return sendAttributesAndReturn(model);
+    }
+
+    @SuppressWarnings("SameReturnValue")
+    @GetMapping(TextMappingConstants.DOCUMENT_TEXT_FF)
+    @Override
+    public final String getLastPage(final Model model) {
+        logger.debug("DocumentTextListControllerImpl::getLastPage");
+        long imageCount = imageService.count();
+        currentPage = (int) (imageCount / ApplicationConstants.DEFAULT_PAGE_SIZE);
+        return sendAttributesAndReturn(model);
+    }
+
+
+    @SuppressWarnings("SameReturnValue")
+    @GetMapping(TextMappingConstants.DOCUMENT_TEXT_DELETE)
+    @Override
+    public final String DocumentTextDelete(@PathVariable final String id) {
+        logger.debug("DocumentTextListControllerImpl::imageDelete");
+        imageService.deleteById(Long.valueOf(id));
+        return MappingConstants.REDIRECT + TextMappingConstants.DOCUMENT_TEXT;
+    }
+
+    @Override
+    public int getPageNumber() {
+        return currentPage;
+    }
+
+
+}

+ 1 - 1
src/main/resources/templates/index.html

@@ -91,7 +91,7 @@
             <td>
             </td>
             <td>
-
+                <a class="btn btn-outline-secondary btn-sm btn-block" href="documentTexts">Document Texts</a>
             </td>
 
         </tr>

+ 0 - 0
src/main/resources/templates/text/documenttext/form.html → src/main/resources/templates/text/documentText/form.html


+ 1 - 1
src/main/resources/templates/text/documenttext/list.html → src/main/resources/templates/text/documentText/list.html

@@ -18,7 +18,7 @@
 <div class="container text-center">
     <div class="container border border-info
                     rounded-3 text-center p-4">
-        <h3>Images</h3>
+        <h3>Document Texts</h3>
         <table class="table table-striped table-bordered">
             <thead class="table-dark">
             <tr>

+ 1 - 1
src/test/java/scot/carricksoftware/grants/controllers/images/images/ImageListControllerTest.java → src/test/java/scot/carricksoftware/grants/controllers/images/images/DocumentTextListControllerTest.java

@@ -26,7 +26,7 @@ import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLo
 
 
 @ExtendWith(MockitoExtension.class)
-public class ImageListControllerTest {
+public class DocumentTextListControllerTest {
 
     private ImageListControllerImpl controller;
 

+ 1 - 1
src/test/java/scot/carricksoftware/grants/controllers/images/personimages/PersonImageListControllerTest.java → src/test/java/scot/carricksoftware/grants/controllers/images/personimages/PersonDocumentTextListControllerTest.java

@@ -27,7 +27,7 @@ import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLo
 
 
 @ExtendWith(MockitoExtension.class)
-public class PersonImageListControllerTest {
+public class PersonDocumentTextListControllerTest {
 
     private PersonImageListControllerImpl controller;
 

+ 1 - 1
src/test/java/scot/carricksoftware/grants/controllers/images/placeimages/PlaceImageListControllerTest.java → src/test/java/scot/carricksoftware/grants/controllers/images/placeimages/PlaceDocumentTextListControllerTest.java

@@ -26,7 +26,7 @@ import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLo
 
 
 @ExtendWith(MockitoExtension.class)
-public class PlaceImageListControllerTest {
+public class PlaceDocumentTextListControllerTest {
 
     private PlaceImageListControllerImpl controller;