Explorar o código

Organisation list controller

Andrew Grant hai 6 meses
pai
achega
3dda91f6e0

+ 16 - 0
src/main/java/scot/carricksoftware/grants/controllers/places/organisations/OrganisationListController.java

@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.controllers.places.organisations;
+
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import scot.carricksoftware.grants.constants.MappingConstants;
+
+public interface OrganisationListController {
+    @SuppressWarnings("SameReturnValue")
+    @GetMapping(MappingConstants.ORGANISATION_LIST)
+    String getListPage(Model model);
+}

+ 52 - 0
src/main/java/scot/carricksoftware/grants/controllers/places/organisations/OrganisationListControllerImpl.java

@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.controllers.places.organisations;
+
+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 scot.carricksoftware.grants.constants.AttributeConstants;
+import scot.carricksoftware.grants.constants.MappingConstants;
+import scot.carricksoftware.grants.constants.ViewConstants;
+import scot.carricksoftware.grants.controllers.ControllerHelper;
+import scot.carricksoftware.grants.services.places.organisations.OrganisationService;
+
+@Controller
+public class OrganisationListControllerImpl implements OrganisationListController {
+
+
+    private static final Logger logger = LogManager.getLogger(OrganisationListControllerImpl.class);
+
+    private int currentPage = 0;
+
+    private final ControllerHelper controllerHelper;
+    private final OrganisationService organisationService;
+
+    public OrganisationListControllerImpl(ControllerHelper controllerHelper,
+                                          OrganisationService organisationService) {
+        this.controllerHelper = controllerHelper;
+        this.organisationService = organisationService;
+    }
+
+    @SuppressWarnings("SameReturnValue")
+    @GetMapping(MappingConstants.ORGANISATION_LIST)
+    @Override
+    public final String getListPage(final Model model) {
+        logger.debug("PersonListControllerImpl::getOrganisationPage");
+        currentPage = 0;
+        return sendAttributesAndReturn(model);
+    }
+
+    @SuppressWarnings("SameReturnValue")
+    private String sendAttributesAndReturn(Model model) {
+        model.addAttribute(AttributeConstants.ORGANISATIONS, organisationService.getPagedOrganisations(currentPage));
+        controllerHelper.addAttributes(model);
+        return ViewConstants.ORGANISATION_LIST;
+    }
+
+}

+ 13 - 13
src/main/resources/templates/organisation/list.html

@@ -18,26 +18,26 @@
 <div class="container text-center">
     <div class="container border border-info
                     rounded-3 text-center p-4">
-        <h3>Countries</h3>
+        <h3>Organisation</h3>
         <table class="table table-striped table-bordered">
             <thead class="table-dark">
             <tr>
                 <th>ID</th>
-                <th>Country</th>
+                <th>Organisation</th>
                 <th></th>
             </tr>
             </thead>
 
-            <tr th:each="country   : ${countries}">
+            <tr th:each="organisation   : ${organisations}">
                 <!--/*@thymesVar id="country" type="scot.carricksoftware.grants.domains.places.Country"*/-->
-                <td th:text="${country.id}">123</td>
-                <td th:text="${country.name}"> First</td>
+                <td th:text="${organisation.id}">123</td>
+                <td th:text="${organisation.name}"> First</td>
                 <td><span>
                         <a th:action="delete" class="btn btn-danger btn-sm"
-                           th:href="@{/country/{id}/delete(id=${country.id})}"
+                           th:href="@{/orgaisation/{id}/delete(id=${organisation.id})}"
                            th:text="Delete"></a>
                     <a th:action="edit" class="btn btn-warning btn-sm"
-                       th:href="@{/country/{id}/edit(id=${country.id})}"
+                       th:href="@{/organisation/{id}/edit(id=${organisation.id})}"
                        th:text="Edit"></a>
 
                     </span></td>
@@ -45,17 +45,17 @@
             <tfoot>
             <tr>
                 <td colspan="4"><span>
-                        <a th:action="rewind" class="btn btn-secondary btn-sm" th:href="@{/countries/rewind}"
+                        <a th:action="rewind" class="btn btn-secondary btn-sm" th:href="@{/organisations/rewind}"
                            th:text="'<<'"></a>
                          <a th:action="back" class="btn btn-secondary btn-sm"
-                            th:href="@{/countries/prev}" th:text="'<'"></a>
-                         <a th:action="new" class="btn btn-primary btn-sm" th:href="@{/country/new}"
-                            th:text="'New Country'"></a>
+                            th:href="@{/organisations/prev}" th:text="'<'"></a>
+                         <a th:action="new" class="btn btn-primary btn-sm" th:href="@{/organisation/new}"
+                            th:text="'New Organisation'"></a>
                          <a th:action="home" class="btn btn-success btn-sm"
                             th:href="@{/}" th:text="'Home'"></a>
                          <a th:action="forward" class="btn btn-secondary btn-sm"
-                            th:href="@{/countries/next}" th:text="'>'"></a>
-                         <a th:action="end" class="btn btn-secondary btn-sm" th:href="@{/countries/ff}"
+                            th:href="@{/organisations/next}" th:text="'>'"></a>
+                         <a th:action="end" class="btn btn-secondary btn-sm" th:href="@{/organisations/ff}"
                             th:text="'>>'"></a>
                         </span></td>
             </tr>