test value
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
dmitriy.churmeev
2026-04-04 03:01:07 +03:00
parent 480087f6e5
commit c175d9895b
5 changed files with 67 additions and 64 deletions

View File

@@ -36,7 +36,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator:3.5.7") implementation("org.springframework.boot:spring-boot-starter-actuator:3.5.7")
implementation("org.springframework.boot:spring-boot-starter-data-jpa") //implementation("org.springframework.boot:spring-boot-starter-data-jpa")
//implementation("org.flywaydb:flyway-database-postgresql:10.10.0") //implementation("org.flywaydb:flyway-database-postgresql:10.10.0")
runtimeOnly("org.postgresql:postgresql") runtimeOnly("org.postgresql:postgresql")

View File

@@ -1,23 +1,23 @@
package com.test.entities 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
import jakarta.persistence.Column //@Entity
import jakarta.persistence.Entity //@Table(name = "test_table")
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.Table
@Entity
@Table(name = "test_table")
data class TestEntity ( data class TestEntity (
@Id // @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) // @GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null, val id: Long? = null,
@Column(name = "key") //@Column(name = "key")
var key: String? = null, var key: String? = null,
@Column(name = "value") //@Column(name = "value")
var value: String? = null var value: String? = null
) )

View File

@@ -1,9 +1,10 @@
package com.test.repository package com.test.repository
import com.test.entities.TestEntity import com.test.entities.TestEntity
import org.springframework.data.jpa.repository.JpaRepository //import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository import org.springframework.stereotype.Repository
@Repository @Repository
interface TestEntityRepository : JpaRepository<TestEntity, Long> { interface TestEntityRepository //: JpaRepository<TestEntity, Long>
{
} }

View File

@@ -19,30 +19,32 @@ open class TestController(private val testService: TestService) {
private val logger = LoggerFactory.getLogger(TestController::class.java) private val logger = LoggerFactory.getLogger(TestController::class.java)
//@PreAuthorize("hasRole('ADMIN')") //@PreAuthorize("hasRole('ADMIN')")
@PostMapping("/add")
fun add(@RequestBody testModel: TestModel): TestModel {
return testService.add(testModel)
}
//@PreAuthorize("hasRole('USER')") //@PreAuthorize("hasRole('USER')")
@PutMapping("/update")
fun users(@RequestBody testModel: TestModel): TestModel {
return testService.update(testModel)
}
@GetMapping("/{id}") //
fun get(@PathVariable(value = "id") id: Long): TestModel { // @PostMapping("/add")
return testService.get(id)!! // fun add(@RequestBody testModel: TestModel): TestModel {
} // return testService.add(testModel)
// }
@DeleteMapping("/{id}") //
fun delete(@RequestBody id: Long) { // @PutMapping("/update")
testService.remove(id) // fun users(@RequestBody testModel: TestModel): TestModel {
} // return testService.update(testModel)
// }
@GetMapping("/") //
fun getAll(): List<TestModel> { // @GetMapping("/{id}")
return testService.getAll() // 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<TestModel> {
// return testService.getAll()
// }
} }

View File

@@ -3,34 +3,34 @@ package com.test.service
import com.test.entities.TestEntity import com.test.entities.TestEntity
import com.test.model.TestModel import com.test.model.TestModel
import com.test.repository.TestEntityRepository import com.test.repository.TestEntityRepository
import org.springframework.data.repository.findByIdOrNull //import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@Service @Service
class TestService(private val testEntityRepository: TestEntityRepository) { class TestService(private val testEntityRepository: TestEntityRepository) {
fun add(model: TestModel): TestModel { // fun add(model: TestModel): TestModel {
var entity = testEntityRepository.save(TestEntity(null, model.key, model.value)) // var entity = testEntityRepository.save(TestEntity(null, model.key, model.value))
return TestModel(entity.id, entity.key, entity.value) // return TestModel(entity.id, entity.key, entity.value)
} // }
//
fun remove(id: Long) { // fun remove(id: Long) {
testEntityRepository.deleteById(id) // testEntityRepository.deleteById(id)
} // }
//
fun update(model: TestModel): TestModel { // fun update(model: TestModel): TestModel {
var entity = testEntityRepository.save(TestEntity(model.id, model.key, model.value)) // var entity = testEntityRepository.save(TestEntity(model.id, model.key, model.value))
return TestModel(null, entity.key, entity.value) // return TestModel(null, entity.key, entity.value)
} // }
//
fun get(id: Long): TestModel? { // fun get(id: Long): TestModel? {
return testEntityRepository.findByIdOrNull(id)?.let { // return testEntityRepository.findByIdOrNull(id)?.let {
TestModel(it.id, it.key, it.value) // TestModel(it.id, it.key, it.value)
} // }
} // }
//
fun getAll(): List<TestModel> { // fun getAll(): List<TestModel> {
return testEntityRepository.findAll() // return testEntityRepository.findAll()
.map { entity -> TestModel(entity.id, entity.key, entity.value)} // .map { entity -> TestModel(entity.id, entity.key, entity.value)}
} // }
} }