From d7c7de4764fad9a74ed7cce8db4bfbe2c23cc7ea Mon Sep 17 00:00:00 2001 From: "dmitriy.churmeev" Date: Sat, 4 Apr 2026 18:22:51 +0300 Subject: [PATCH] test value --- build.gradle | 14 ++--- .../kotlin/com/test/entities/TestEntity.kt | 26 +++++----- .../test/repository/TestEntityRepository.kt | 5 +- .../kotlin/com/test/rest/TestController.kt | 49 ++++++++--------- .../kotlin/com/test/service/TestService.kt | 52 +++++++++---------- src/main/resources/application.yaml | 36 ++++++++----- 6 files changed, 95 insertions(+), 87 deletions(-) diff --git a/build.gradle b/build.gradle index d81bd79..8a094c5 100644 --- a/build.gradle +++ b/build.gradle @@ -36,8 +36,8 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-actuator:3.5.7") - //implementation("org.springframework.boot:spring-boot-starter-data-jpa") - //implementation("org.flywaydb:flyway-database-postgresql:10.10.0") + implementation("org.springframework.boot:spring-boot-starter-data-jpa") + implementation("org.flywaydb:flyway-database-postgresql:10.10.0") runtimeOnly("org.postgresql:postgresql") @@ -56,8 +56,8 @@ tasks.named('test') { useJUnitPlatform() } -//flyway { -// url = 'jdbc:postgresql://localhost:5432/app_db' -// user = 'root' -// password = 'root' -//} +flyway { + url = 'jdbc:postgresql://localhost:5432/app_db' + user = 'root' + password = 'root' +} diff --git a/src/main/kotlin/com/test/entities/TestEntity.kt b/src/main/kotlin/com/test/entities/TestEntity.kt index bc3bdd1..c142514 100644 --- a/src/main/kotlin/com/test/entities/TestEntity.kt +++ b/src/main/kotlin/com/test/entities/TestEntity.kt @@ -1,23 +1,23 @@ package com.test.entities -// -//import jakarta.persistence.Column -//import jakarta.persistence.Entity -//import jakarta.persistence.GeneratedValue -//import jakarta.persistence.GenerationType -//import jakarta.persistence.Id -//import jakarta.persistence.Table -//@Entity -//@Table(name = "test_table") +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.Table + +@Entity +@Table(name = "test_table") data class TestEntity ( - // @Id - // @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, - //@Column(name = "key") + @Column(name = "key") var key: String? = null, - //@Column(name = "value") + @Column(name = "value") var value: String? = null ) \ No newline at end of file diff --git a/src/main/kotlin/com/test/repository/TestEntityRepository.kt b/src/main/kotlin/com/test/repository/TestEntityRepository.kt index 8270f29..f991c49 100644 --- a/src/main/kotlin/com/test/repository/TestEntityRepository.kt +++ b/src/main/kotlin/com/test/repository/TestEntityRepository.kt @@ -1,10 +1,9 @@ package com.test.repository import com.test.entities.TestEntity -//import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository @Repository -interface TestEntityRepository //: JpaRepository -{ +interface TestEntityRepository : JpaRepository { } \ No newline at end of file diff --git a/src/main/kotlin/com/test/rest/TestController.kt b/src/main/kotlin/com/test/rest/TestController.kt index 9b7bd79..328cb5a 100644 --- a/src/main/kotlin/com/test/rest/TestController.kt +++ b/src/main/kotlin/com/test/rest/TestController.kt @@ -21,29 +21,30 @@ open class TestController(private val testService: TestService) { //@PreAuthorize("hasRole('ADMIN')") //@PreAuthorize("hasRole('USER')") -// @PostMapping("/add") -// fun add(@RequestBody testModel: TestModel): TestModel { -// return testService.add(testModel) -// } -// -// @PutMapping("/update") -// fun users(@RequestBody testModel: TestModel): TestModel { -// return testService.update(testModel) -// } -// -// @GetMapping("/{id}") -// fun get(@PathVariable(value = "id") id: Long): TestModel { -// return testService.get(id)!! -// } -// -// @DeleteMapping("/{id}") -// fun delete(@RequestBody id: Long) { -// testService.remove(id) -// } -// -// @GetMapping("/") -// fun getAll(): List { -// return testService.getAll() -// } + @PostMapping("/add") + fun add(@RequestBody testModel: TestModel): TestModel { + return testService.add(testModel) + } + + + @PutMapping("/update") + fun users(@RequestBody testModel: TestModel): TestModel { + return testService.update(testModel) + } + + @GetMapping("/{id}") + fun get(@PathVariable(value = "id") id: Long): TestModel { + return testService.get(id)!! + } + + @DeleteMapping("/{id}") + fun delete(@RequestBody id: Long) { + testService.remove(id) + } + + @GetMapping("/") + fun getAll(): List { + return testService.getAll() + } } \ No newline at end of file diff --git a/src/main/kotlin/com/test/service/TestService.kt b/src/main/kotlin/com/test/service/TestService.kt index c858f3b..78f3959 100644 --- a/src/main/kotlin/com/test/service/TestService.kt +++ b/src/main/kotlin/com/test/service/TestService.kt @@ -3,34 +3,34 @@ package com.test.service import com.test.entities.TestEntity import com.test.model.TestModel import com.test.repository.TestEntityRepository -//import org.springframework.data.repository.findByIdOrNull +import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service @Service -class TestService() { +class TestService(private val testEntityRepository: TestEntityRepository) { -// fun add(model: TestModel): TestModel { -// var entity = testEntityRepository.save(TestEntity(null, model.key, model.value)) -// return TestModel(entity.id, entity.key, entity.value) -// } -// -// fun remove(id: Long) { -// testEntityRepository.deleteById(id) -// } -// -// fun update(model: TestModel): TestModel { -// var entity = testEntityRepository.save(TestEntity(model.id, model.key, model.value)) -// return TestModel(null, entity.key, entity.value) -// } -// -// fun get(id: Long): TestModel? { -// return testEntityRepository.findByIdOrNull(id)?.let { -// TestModel(it.id, it.key, it.value) -// } -// } -// -// fun getAll(): List { -// return testEntityRepository.findAll() -// .map { entity -> TestModel(entity.id, entity.key, entity.value)} -// } + fun add(model: TestModel): TestModel { + var entity = testEntityRepository.save(TestEntity(null, model.key, model.value)) + return TestModel(entity.id, entity.key, entity.value) + } + + fun remove(id: Long) { + testEntityRepository.deleteById(id) + } + + fun update(model: TestModel): TestModel { + var entity = testEntityRepository.save(TestEntity(model.id, model.key, model.value)) + return TestModel(null, entity.key, entity.value) + } + + fun get(id: Long): TestModel? { + return testEntityRepository.findByIdOrNull(id)?.let { + TestModel(it.id, it.key, it.value) + } + } + + fun getAll(): List { + return testEntityRepository.findAll() + .map { entity -> TestModel(entity.id, entity.key, entity.value)} + } } \ No newline at end of file diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 65c51ab..debd64b 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -11,21 +11,29 @@ spring: # Datasource datasource: + hikari: + connection-timeout: 30000 + minimum-idle: 5 + maximum-pool-size: 20 + connection-init-sql: SELECT 1 + validation-timeout: 5000 + max-lifetime: 1800000 + idle-timeout: 600000 url: jdbc:postgresql://192.168.2.101:5432/test_db username: postgres password: ${SPRING_DATASOURCE_PASSWORD} driver-class-name: org.postgresql.Driver # JPA -# jpa: -# hibernate: -# # ddl-auto: validate -# show-sql: true -# properties: -# hibernate: -# format_sql: true -# database: postgresql -# database-platform: org.hibernate.dialect.PostgreSQLDialect + jpa: + hibernate: + # ddl-auto: validate + show-sql: true + properties: + hibernate: + format_sql: true + database: postgres + database-platform: org.hibernate.dialect.PostgreSQLDialect # Keycloak Security security: @@ -44,8 +52,8 @@ logging: org.springframework.security: DEBUG -# # Flyway -# flyway: -# enabled: true -# locations: classpath:db/migration -# baseline-on-migrate: true \ No newline at end of file + # Flyway + flyway: + enabled: true + locations: classpath:db/migration + baseline-on-migrate: true \ No newline at end of file