Repository: jhipster/jhipster-lite
Pull request #10405 (2024-07-27 07:29:02)

TS pagination domain
Simple module to add TS page domain model


Patch:
diff --git a/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/application/TsPaginationDomainApplicationService.java b/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/application/TsPaginationDomainApplicationService.java
new file mode 100644
index 000000000..f969abc00
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/application/TsPaginationDomainApplicationService.java
@@ -0,0 +1,16 @@
+package tech.jhipster.lite.generator.client.pagination_domain.application;
+
+import org.springframework.stereotype.Service;
+import tech.jhipster.lite.generator.client.pagination_domain.domain.TSPaginationDomainModuleFactory;
+import tech.jhipster.lite.module.domain.JHipsterModule;
+import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
+
+@Service
+public class TsPaginationDomainApplicationService {
+
+  private static final TSPaginationDomainModuleFactory factory = new TSPaginationDomainModuleFactory();
+
+  public JHipsterModule buildModule(JHipsterModuleProperties properties) {
+    return factory.buildModule(properties);
+  }
+}
diff --git a/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/domain/TSPaginationDomainModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/domain/TSPaginationDomainModuleFactory.java
new file mode 100644
index 000000000..7841039ce
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/domain/TSPaginationDomainModuleFactory.java
@@ -0,0 +1,25 @@
+package tech.jhipster.lite.generator.client.pagination_domain.domain;
+
+import static tech.jhipster.lite.module.domain.JHipsterModule.*;
+
+import tech.jhipster.lite.module.domain.JHipsterModule;
+import tech.jhipster.lite.module.domain.file.JHipsterDestination;
+import tech.jhipster.lite.module.domain.file.JHipsterSource;
+import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
+
+public class TSPaginationDomainModuleFactory {
+
+  public JHipsterModule buildModule(JHipsterModuleProperties properties) {
+    JHipsterSource source = from("client/pagination/domain");
+    JHipsterDestination destination = to("src/main/webapp/app/shared/pagination/domain");
+
+    // @formatter:off
+    return moduleBuilder(properties)
+      .files()
+        .add(source.template("Page.ts"), destination.append("Page.ts"))
+        .add(source.template("DisplayedOnPage.ts"), destination.append("DisplayedOnPage.ts"))
+        .and()
+      .build();
+    //@formatter:on
+  }
+}
diff --git a/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/infrastructure/primary/TsPaginationDomainModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/infrastructure/primary/TsPaginationDomainModuleConfiguration.java
new file mode 100644
index 000000000..ec2029fd0
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/infrastructure/primary/TsPaginationDomainModuleConfiguration.java
@@ -0,0 +1,23 @@
+package tech.jhipster.lite.generator.client.pagination_domain.infrastructure.primary;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import tech.jhipster.lite.generator.client.pagination_domain.application.TsPaginationDomainApplicationService;
+import tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug;
+import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization;
+import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource;
+
+@Configuration
+class TsPaginationDomainModuleConfiguration {
+
+  @Bean
+  JHipsterModuleResource tsPaginationDomainModule(TsPaginationDomainApplicationService tsPaginationDomain) {
+    return JHipsterModuleResource.builder()
+      .slug(JHLiteModuleSlug.TS_PAGINATION_DOMAIN)
+      .withoutProperties()
+      .apiDoc("client", "Add TS domain for pagination")
+      .organization(JHipsterModuleOrganization.builder().addDependency(JHLiteModuleSlug.INIT).build())
+      .tags("client")
+      .factory(tsPaginationDomain::buildModule);
+  }
+}
diff --git a/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/package-info.java b/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/package-info.java
new file mode 100644
index 000000000..a00abbb4e
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/generator/client/pagination_domain/package-info.java
@@ -0,0 +1,2 @@
+@tech.jhipster.lite.BusinessContext
+package tech.jhipster.lite.generator.client.pagination_domain;
diff --git a/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java b/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java
index 65469a17d..5552df047 100644
--- a/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java
+++ b/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java
@@ -142,7 +142,8 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory {
   SVELTE_CORE("svelte-core"),
   TYPESCRIPT("typescript"),
   VUE_CORE("vue-core"),
-  VUE_PINIA("vue-pinia");
+  VUE_PINIA("vue-pinia"),
+  TS_PAGINATION_DOMAIN("ts-pagination-domain");
 
   private static final Map<String, JHLiteModuleSlug> moduleSlugMap = Stream.of(values()).collect(
     Collectors.toMap(JHLiteModuleSlug::get, Function.identity())
diff --git a/src/main/resources/generator/client/pagination/domain/DisplayedOnPage.ts.mustache b/src/main/resources/generator/client/pagination/domain/DisplayedOnPage.ts.mustache
new file mode 100644
index 000000000..32615d8d5
--- /dev/null
+++ b/src/main/resources/generator/client/pagination/domain/DisplayedOnPage.ts.mustache
@@ -0,0 +1,4 @@
+export type DisplayedOnPage = {
+  start: number;
+  end: number;
+};
diff --git a/src/main/resources/generator/client/pagination/domain/Page.ts.mustache b/src/main/resources/generator/client/pagination/domain/Page.ts.mustache
new file mode 100755
index 000000000..0983280f1
--- /dev/null
+++ b/src/main/resources/generator/client/pagination/domain/Page.ts.mustache
@@ -0,0 +1,11 @@
+import { DisplayedOnPage } from './DisplayedOnPage';
+
+export type Page<Content> = {
+  currentPage: number;
+  pagesCount: number;
+  hasPrevious: boolean;
+  hasNext: boolean;
+  totalElementsCount: number;
+  displayed: DisplayedOnPage;
+  content: Content[];
+};


Test patch:
diff --git a/src/test/features/client/ts-pagination-domain.feature b/src/test/features/client/ts-pagination-domain.feature
new file mode 100644
index 000000000..d56929276
--- /dev/null
+++ b/src/test/features/client/ts-pagination-domain.feature
@@ -0,0 +1,9 @@
+Feature: TS pagination domain
+
+  Scenario: Should apply TS pagination module
+    When I apply modules to default project
+      | init                 |
+      | prettier             |
+      | ts-pagination-domain |
+    Then I should have files in "src/main/webapp/app/shared/pagination/domain"
+      | Page.ts |
diff --git a/src/test/java/tech/jhipster/lite/generator/client/pagination_domain/domain/PaginationDomainModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/pagination_domain/domain/PaginationDomainModuleFactoryTest.java
new file mode 100644
index 000000000..5ea7ac922
--- /dev/null
+++ b/src/test/java/tech/jhipster/lite/generator/client/pagination_domain/domain/PaginationDomainModuleFactoryTest.java
@@ -0,0 +1,29 @@
+package tech.jhipster.lite.generator.client.pagination_domain.domain;
+
+import static tech.jhipster.lite.module.domain.JHipsterModulesFixture.*;
+import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*;
+
+import org.junit.jupiter.api.Test;
+import tech.jhipster.lite.TestFileUtils;
+import tech.jhipster.lite.UnitTest;
+import tech.jhipster.lite.module.domain.JHipsterModule;
+import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
+
+@UnitTest
+class PaginationDomainModuleFactoryTest {
+
+  private static final TSPaginationDomainModuleFactory factory = new TSPaginationDomainModuleFactory();
+
+  @Test
+  void shouldBuildModule() {
+    JHipsterModuleProperties properties = propertiesBuilder(TestFileUtils.tmpDirForTest()).build();
+
+    JHipsterModule module = factory.buildModule(properties);
+
+    assertThatModuleWithFiles(module, packageJsonFile()).hasPrefixedFiles(
+      "src/main/webapp/app/shared/pagination/domain",
+      "Page.ts",
+      "DisplayedOnPage.ts"
+    );
+  }
+}
diff --git a/tests-ci/generate.sh b/tests-ci/generate.sh
index 6c1f3973d..3c578a690 100755
--- a/tests-ci/generate.sh
+++ b/tests-ci/generate.sh
@@ -133,6 +133,7 @@ elif [[ $application == 'fullapp' ]]; then
   sonar_back_front
 
   applyModules \
+  "ts-pagination-domain" \
   "prettier" \
   "infinitest-filters" \
   "pagination-domain" \