feature/h2 (#1)

Reviewed-on: #1
Co-authored-by: Jari <scijar@gmail.com>
Co-committed-by: Jari <scijar@gmail.com>
This commit is contained in:
Jari 2025-10-18 13:05:04 +02:00 committed by zobrock
parent 07492f5423
commit 80292af22a
10 changed files with 36 additions and 49 deletions

1
.gitignore vendored
View File

@ -46,3 +46,4 @@ bin/
.idea/*
.env
data/*

View File

@ -33,18 +33,18 @@ repositories {
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-mail")
// implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-actuator")
developmentOnly("org.springframework.boot:spring-boot-devtools")
implementation("org.postgresql:postgresql:42.7.2")
implementation("org.jetbrains.kotlin:kotlin-reflect")
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")

View File

@ -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:
- ./data:/app/data

View File

@ -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<Date>? = mutableListOf(),
val recurrentMonths: List<Month>? = mutableListOf(),
val endDate: Date? = null
)

View File

@ -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<EntryEntity, Long> {
fun findAllByType(type: EEntryType): MutableList<EntryEntity>
fun findAllByFixedDateIsNullAndRecurrentIsTrueAndEndDateIsNotNullAndEndDateBefore(endDate: Date): MutableList<EntryEntity>
// fun findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIsNotEmpty(): MutableList<EntryEntity>
fun findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIn(months: List<Month>): MutableList<EntryEntity>
fun findAllByFixedDateIsNotNullAndFixedDateBefore(fixedDate: Date): MutableList<EntryEntity>
}

View File

@ -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<Date>? = mutableListOf(),
val recurrentMonths: List<Month>? = mutableListOf(),
val endDate: Date? = null
)

View File

@ -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<Entry>
fun getAllRecurrentOnSpecificMonths(): MutableList<Entry>
fun getAllRecurrentOnSpecificMonths(months: List<Month>): MutableList<Entry>
fun getAllRecurrentOnAllMonths(): MutableList<Entry>
fun getAllFixedUpToEndDate(endDate: Date): MutableList<Entry>
fun getAllByType(type: EEntryType): MutableList<Entry>
}

View File

@ -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<Entry> {
override fun getAllRecurrentOnSpecificMonths(months: List<Month>): MutableList<Entry> {
return mapper.toModels(
// jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIsNotEmpty()
jpa.findAllByType(EEntryType.INCOME)
jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIn(months)
)
}
override fun getAllRecurrentOnAllMonths(): MutableList<Entry> {
return mapper.toModels(
jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIn(Month.entries)
)
}

View File

@ -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<Entry> {
return repo.getAllRecurrentOnSpecificMonths()
return repo.getA
}
}

View File

@ -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