Compare commits

..

2 Commits

Author SHA1 Message Date
dmitriy.churmeev
b715214b2f change crud service
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2026-04-08 22:27:21 +03:00
dmitriy.churmeev
138ad908f0 change rest controller
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2026-04-08 22:13:03 +03:00
2 changed files with 8 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ package com.test.rest
import com.test.model.TestModel import com.test.model.TestModel
import com.test.service.TestService import com.test.service.TestService
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PathVariable
@@ -22,19 +23,19 @@ open class TestController(private val testService: TestService) {
//@PreAuthorize("hasRole('USER')") //@PreAuthorize("hasRole('USER')")
@PostMapping("/add") @PostMapping("/add")
fun add(@RequestBody testModel: TestModel): TestModel { fun add(@RequestBody testModel: TestModel): ResponseEntity<TestModel> {
return testService.add(testModel) return ResponseEntity.ok(testService.add(testModel))
} }
@PutMapping("/update") @PutMapping("/update")
fun users(@RequestBody testModel: TestModel): TestModel { fun users(@RequestBody testModel: TestModel): ResponseEntity<TestModel> {
return testService.update(testModel) return ResponseEntity.ok(testService.update(testModel))
} }
@GetMapping("/{id}") @GetMapping("/{id}")
fun get(@PathVariable(value = "id") id: Long): TestModel { fun get(@PathVariable(value = "id") id: Long): ResponseEntity<TestModel> {
return testService.get(id)!! return testService.get(id)?.let { ResponseEntity.ok(it) } ?: ResponseEntity.notFound().build()
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")

View File

@@ -20,7 +20,7 @@ class TestService(private val testEntityRepository: TestEntityRepository) {
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(model.id, entity.key, entity.value)
} }
fun get(id: Long): TestModel? { fun get(id: Long): TestModel? {