From 22a8d5f7fa4273019353114ef6da5e6e7eb4765a Mon Sep 17 00:00:00 2001 From: Jari Date: Sat, 18 Oct 2025 13:03:02 +0200 Subject: [PATCH] replace psql with m2 --- .gitignore | 3 +- build.gradle.kts | 2 ++ compose.yaml | 32 +------------------ .../octopus/internal/common/models/Entry.kt | 3 +- .../org/octopus/internal/db/EntryJpa.kt | 3 +- .../internal/db/entities/EntryEntity.kt | 3 +- .../internal/repositories/EntryRepository.kt | 4 ++- .../repositories/impl/EntryRepositoryImpl.kt | 13 ++++++-- .../services/impl/EntryServiceImpl.kt | 3 +- src/main/resources/application.properties | 17 ++++++---- 10 files changed, 36 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 360c04a..dcb6c75 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,5 @@ bin/ .DS_Store .idea/* -.env \ No newline at end of file +.env +data/* \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 907c3df..23814a3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,6 +45,8 @@ dependencies { compileOnly("org.projectlombok:lombok") annotationProcessor("org.projectlombok:lombok") + runtimeOnly("com.h2database:h2") + implementation("org.mapstruct:mapstruct:1.6.0") kapt("org.mapstruct:mapstruct-processor:1.6.0") implementation("org.springframework.boot:spring-boot-starter-web") diff --git a/compose.yaml b/compose.yaml index e850bb4..e2d3940 100755 --- a/compose.yaml +++ b/compose.yaml @@ -4,35 +4,5 @@ services: container_name: be ports: - "8080:8081" - environment: - SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/planning_db - SPRING_DATASOURCE_USERNAME: lorca_usr - SPRING_DATASOURCE_PASSWORD: lorca_pwd - depends_on: - - db - - db: - container_name: postgres - image: postgres:latest - restart: always - environment: - - POSTGRES_USER=${POSTGRES_USER} - - POSTGRES_PASSWORD=${POSTGRES_PW} - - POSTGRES_DB=${POSTGRES_DB} - ports: - - "5432:5432" volumes: - - pgdata:/var/lib/postgresql/data - - pgadmin: - container_name: pgadmin - image: dpage/pgadmin4:latest - environment: - - PGADMIN_DEFAULT_EMAIL=${PGADMIN_MAIL} - - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PW} - ports: - - "5050:80" - restart: always - -volumes: - pgdata: \ No newline at end of file + - ./data:/app/data \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/internal/common/models/Entry.kt b/src/main/kotlin/org/octopus/internal/common/models/Entry.kt index 9350d04..70621c4 100755 --- a/src/main/kotlin/org/octopus/internal/common/models/Entry.kt +++ b/src/main/kotlin/org/octopus/internal/common/models/Entry.kt @@ -1,6 +1,7 @@ package org.octopus.internal.common.models import org.octopus.internal.common.enums.EEntryType +import java.time.Month import java.util.* data class Entry( @@ -9,6 +10,6 @@ data class Entry( val amount: Double, val fixedDate: Date? = null, val recurrent: Boolean? = false, - val recurrentMonths: List? = mutableListOf(), + val recurrentMonths: List? = mutableListOf(), val endDate: Date? = null ) \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/internal/db/EntryJpa.kt b/src/main/kotlin/org/octopus/internal/db/EntryJpa.kt index bc9589d..a239584 100755 --- a/src/main/kotlin/org/octopus/internal/db/EntryJpa.kt +++ b/src/main/kotlin/org/octopus/internal/db/EntryJpa.kt @@ -3,11 +3,12 @@ package org.octopus.internal.db import org.octopus.internal.common.enums.EEntryType import org.octopus.internal.db.entities.EntryEntity import org.springframework.data.jpa.repository.JpaRepository +import java.time.Month import java.util.Date interface EntryJpa : JpaRepository { fun findAllByType(type: EEntryType): MutableList fun findAllByFixedDateIsNullAndRecurrentIsTrueAndEndDateIsNotNullAndEndDateBefore(endDate: Date): MutableList -// fun findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIsNotEmpty(): MutableList + fun findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIn(months: List): MutableList fun findAllByFixedDateIsNotNullAndFixedDateBefore(fixedDate: Date): MutableList } \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/internal/db/entities/EntryEntity.kt b/src/main/kotlin/org/octopus/internal/db/entities/EntryEntity.kt index b6d564e..d6487eb 100644 --- a/src/main/kotlin/org/octopus/internal/db/entities/EntryEntity.kt +++ b/src/main/kotlin/org/octopus/internal/db/entities/EntryEntity.kt @@ -5,6 +5,7 @@ import jakarta.persistence.GeneratedValue import jakarta.persistence.GenerationType import jakarta.persistence.Id import org.octopus.internal.common.enums.EEntryType +import java.time.Month import java.util.Date @Entity(name = "data_entries") @@ -15,6 +16,6 @@ data class EntryEntity( val amount: Double, val fixedDate: Date? = null, val recurrent: Boolean? = false, - val recurrentMonths: List? = mutableListOf(), + val recurrentMonths: List? = mutableListOf(), val endDate: Date? = null ) \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/internal/repositories/EntryRepository.kt b/src/main/kotlin/org/octopus/internal/repositories/EntryRepository.kt index f8d3e53..3a3cdd5 100755 --- a/src/main/kotlin/org/octopus/internal/repositories/EntryRepository.kt +++ b/src/main/kotlin/org/octopus/internal/repositories/EntryRepository.kt @@ -2,13 +2,15 @@ package org.octopus.internal.repositories import org.octopus.internal.common.enums.EEntryType import org.octopus.internal.common.models.Entry +import java.time.Month import java.util.Date interface EntryRepository { fun getById(id: Long): Entry fun createEntry(entry: Entry): Entry fun getAllRecurrentMonthlyToEndDate(endDate: Date): MutableList - fun getAllRecurrentOnSpecificMonths(): MutableList + fun getAllRecurrentOnSpecificMonths(months: List): MutableList + fun getAllRecurrentOnAllMonths(): MutableList fun getAllFixedUpToEndDate(endDate: Date): MutableList fun getAllByType(type: EEntryType): MutableList } diff --git a/src/main/kotlin/org/octopus/internal/repositories/impl/EntryRepositoryImpl.kt b/src/main/kotlin/org/octopus/internal/repositories/impl/EntryRepositoryImpl.kt index 0cc608c..3121ade 100755 --- a/src/main/kotlin/org/octopus/internal/repositories/impl/EntryRepositoryImpl.kt +++ b/src/main/kotlin/org/octopus/internal/repositories/impl/EntryRepositoryImpl.kt @@ -1,5 +1,6 @@ package org.octopus.internal.repositories.impl +import org.hibernate.type.descriptor.DateTimeUtils import org.octopus.internal.common.enums.EBusinessException import org.octopus.internal.common.enums.EEntryType import org.octopus.internal.common.exceptions.OctopusPlanningException @@ -8,6 +9,7 @@ import org.octopus.internal.common.models.Entry import org.octopus.internal.db.EntryJpa import org.octopus.internal.repositories.EntryRepository import org.springframework.stereotype.Component +import java.time.Month import java.util.* @Component @@ -41,10 +43,15 @@ class EntryRepositoryImpl( ) } - override fun getAllRecurrentOnSpecificMonths(): MutableList { + override fun getAllRecurrentOnSpecificMonths(months: List): MutableList { return mapper.toModels( -// jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIsNotEmpty() - jpa.findAllByType(EEntryType.INCOME) + jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIn(months) + ) + } + + override fun getAllRecurrentOnAllMonths(): MutableList { + return mapper.toModels( + jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIn(Month.entries) ) } diff --git a/src/main/kotlin/org/octopus/internal/services/impl/EntryServiceImpl.kt b/src/main/kotlin/org/octopus/internal/services/impl/EntryServiceImpl.kt index 9eec26f..f4d3b21 100755 --- a/src/main/kotlin/org/octopus/internal/services/impl/EntryServiceImpl.kt +++ b/src/main/kotlin/org/octopus/internal/services/impl/EntryServiceImpl.kt @@ -1,5 +1,6 @@ package org.octopus.internal.services.impl +import org.octopus.internal.common.enums.EEntryType import org.octopus.internal.common.models.Entry import org.octopus.internal.repositories.EntryRepository import org.octopus.internal.services.EntryService @@ -8,7 +9,7 @@ import org.springframework.stereotype.Service @Service class EntryServiceImpl(val repo: EntryRepository) : EntryService { override fun getAllEntries(): MutableList { - return repo.getAllRecurrentOnSpecificMonths() + return repo.getA } } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8415232..9ee1f1b 100755 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,11 +4,14 @@ spring.application.name=octopus-planning-application # # DATABASE # -spring.datasource.url=jdbc:postgresql://0.0.0.0:5432/planning_db -spring.datasource.username=lorca_usr -spring.datasource.password=lorca_pwd -spring.datasource.driver-class-name=org.postgresql.Driver -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -spring.jpa.generate-ddl=true -spring.jpa.hibernate.ddl-auto=update +spring.datasource.url=jdbc:h2:file:./data/planning-db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= + +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true + +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console