feature/h2 #1
|
|
@ -45,4 +45,5 @@ bin/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
.idea/*
|
.idea/*
|
||||||
.env
|
.env
|
||||||
|
data/*
|
||||||
|
|
@ -45,6 +45,8 @@ dependencies {
|
||||||
compileOnly("org.projectlombok:lombok")
|
compileOnly("org.projectlombok:lombok")
|
||||||
annotationProcessor("org.projectlombok:lombok")
|
annotationProcessor("org.projectlombok:lombok")
|
||||||
|
|
||||||
|
runtimeOnly("com.h2database:h2")
|
||||||
|
|
||||||
implementation("org.mapstruct:mapstruct:1.6.0")
|
implementation("org.mapstruct:mapstruct:1.6.0")
|
||||||
kapt("org.mapstruct:mapstruct-processor:1.6.0")
|
kapt("org.mapstruct:mapstruct-processor:1.6.0")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
|
|
|
||||||
32
compose.yaml
32
compose.yaml
|
|
@ -4,35 +4,5 @@ services:
|
||||||
container_name: be
|
container_name: be
|
||||||
ports:
|
ports:
|
||||||
- "8080:8081"
|
- "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:
|
volumes:
|
||||||
- pgdata:/var/lib/postgresql/data
|
- ./data:/app/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:
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package org.octopus.internal.common.models
|
package org.octopus.internal.common.models
|
||||||
|
|
||||||
import org.octopus.internal.common.enums.EEntryType
|
import org.octopus.internal.common.enums.EEntryType
|
||||||
|
import java.time.Month
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
data class Entry(
|
data class Entry(
|
||||||
|
|
@ -9,6 +10,6 @@ data class Entry(
|
||||||
val amount: Double,
|
val amount: Double,
|
||||||
val fixedDate: Date? = null,
|
val fixedDate: Date? = null,
|
||||||
val recurrent: Boolean? = false,
|
val recurrent: Boolean? = false,
|
||||||
val recurrentMonths: List<Date>? = mutableListOf(),
|
val recurrentMonths: List<Month>? = mutableListOf(),
|
||||||
val endDate: Date? = null
|
val endDate: Date? = null
|
||||||
)
|
)
|
||||||
|
|
@ -3,11 +3,12 @@ package org.octopus.internal.db
|
||||||
import org.octopus.internal.common.enums.EEntryType
|
import org.octopus.internal.common.enums.EEntryType
|
||||||
import org.octopus.internal.db.entities.EntryEntity
|
import org.octopus.internal.db.entities.EntryEntity
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
import java.time.Month
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
interface EntryJpa : JpaRepository<EntryEntity, Long> {
|
interface EntryJpa : JpaRepository<EntryEntity, Long> {
|
||||||
fun findAllByType(type: EEntryType): MutableList<EntryEntity>
|
fun findAllByType(type: EEntryType): MutableList<EntryEntity>
|
||||||
fun findAllByFixedDateIsNullAndRecurrentIsTrueAndEndDateIsNotNullAndEndDateBefore(endDate: Date): 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>
|
fun findAllByFixedDateIsNotNullAndFixedDateBefore(fixedDate: Date): MutableList<EntryEntity>
|
||||||
}
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ import jakarta.persistence.GeneratedValue
|
||||||
import jakarta.persistence.GenerationType
|
import jakarta.persistence.GenerationType
|
||||||
import jakarta.persistence.Id
|
import jakarta.persistence.Id
|
||||||
import org.octopus.internal.common.enums.EEntryType
|
import org.octopus.internal.common.enums.EEntryType
|
||||||
|
import java.time.Month
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@Entity(name = "data_entries")
|
@Entity(name = "data_entries")
|
||||||
|
|
@ -15,6 +16,6 @@ data class EntryEntity(
|
||||||
val amount: Double,
|
val amount: Double,
|
||||||
val fixedDate: Date? = null,
|
val fixedDate: Date? = null,
|
||||||
val recurrent: Boolean? = false,
|
val recurrent: Boolean? = false,
|
||||||
val recurrentMonths: List<Date>? = mutableListOf(),
|
val recurrentMonths: List<Month>? = mutableListOf(),
|
||||||
val endDate: Date? = null
|
val endDate: Date? = null
|
||||||
)
|
)
|
||||||
|
|
@ -2,13 +2,15 @@ package org.octopus.internal.repositories
|
||||||
|
|
||||||
import org.octopus.internal.common.enums.EEntryType
|
import org.octopus.internal.common.enums.EEntryType
|
||||||
import org.octopus.internal.common.models.Entry
|
import org.octopus.internal.common.models.Entry
|
||||||
|
import java.time.Month
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
interface EntryRepository {
|
interface EntryRepository {
|
||||||
fun getById(id: Long): Entry
|
fun getById(id: Long): Entry
|
||||||
fun createEntry(entry: Entry): Entry
|
fun createEntry(entry: Entry): Entry
|
||||||
fun getAllRecurrentMonthlyToEndDate(endDate: Date): MutableList<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 getAllFixedUpToEndDate(endDate: Date): MutableList<Entry>
|
||||||
fun getAllByType(type: EEntryType): MutableList<Entry>
|
fun getAllByType(type: EEntryType): MutableList<Entry>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package org.octopus.internal.repositories.impl
|
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.EBusinessException
|
||||||
import org.octopus.internal.common.enums.EEntryType
|
import org.octopus.internal.common.enums.EEntryType
|
||||||
import org.octopus.internal.common.exceptions.OctopusPlanningException
|
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.db.EntryJpa
|
||||||
import org.octopus.internal.repositories.EntryRepository
|
import org.octopus.internal.repositories.EntryRepository
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
|
import java.time.Month
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
|
@ -41,10 +43,15 @@ class EntryRepositoryImpl(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllRecurrentOnSpecificMonths(): MutableList<Entry> {
|
override fun getAllRecurrentOnSpecificMonths(months: List<Month>): MutableList<Entry> {
|
||||||
return mapper.toModels(
|
return mapper.toModels(
|
||||||
// jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIsNotEmpty()
|
jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIn(months)
|
||||||
jpa.findAllByType(EEntryType.INCOME)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAllRecurrentOnAllMonths(): MutableList<Entry> {
|
||||||
|
return mapper.toModels(
|
||||||
|
jpa.findAllByFixedDateIsNullAndRecurrentIsTrueAndRecurrentMonthsIn(Month.entries)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package org.octopus.internal.services.impl
|
package org.octopus.internal.services.impl
|
||||||
|
|
||||||
|
import org.octopus.internal.common.enums.EEntryType
|
||||||
import org.octopus.internal.common.models.Entry
|
import org.octopus.internal.common.models.Entry
|
||||||
import org.octopus.internal.repositories.EntryRepository
|
import org.octopus.internal.repositories.EntryRepository
|
||||||
import org.octopus.internal.services.EntryService
|
import org.octopus.internal.services.EntryService
|
||||||
|
|
@ -8,7 +9,7 @@ import org.springframework.stereotype.Service
|
||||||
@Service
|
@Service
|
||||||
class EntryServiceImpl(val repo: EntryRepository) : EntryService {
|
class EntryServiceImpl(val repo: EntryRepository) : EntryService {
|
||||||
override fun getAllEntries(): MutableList<Entry> {
|
override fun getAllEntries(): MutableList<Entry> {
|
||||||
return repo.getAllRecurrentOnSpecificMonths()
|
return repo.getA
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,11 +4,14 @@ spring.application.name=octopus-planning-application
|
||||||
#
|
#
|
||||||
# DATABASE
|
# DATABASE
|
||||||
#
|
#
|
||||||
spring.datasource.url=jdbc:postgresql://0.0.0.0:5432/planning_db
|
spring.datasource.url=jdbc:h2:file:./data/planning-db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
|
||||||
spring.datasource.username=lorca_usr
|
spring.datasource.driver-class-name=org.h2.Driver
|
||||||
spring.datasource.password=lorca_pwd
|
spring.datasource.username=sa
|
||||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
spring.datasource.password=
|
||||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
|
||||||
spring.jpa.generate-ddl=true
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.show-sql=true
|
||||||
|
|
||||||
|
spring.h2.console.enabled=true
|
||||||
|
spring.h2.console.path=/h2-console
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue