From 138ad908f0edefb432d949dada9634a9a8bf0802 Mon Sep 17 00:00:00 2001 From: "dmitriy.churmeev" Date: Wed, 8 Apr 2026 22:13:03 +0300 Subject: [PATCH] change rest controller --- src/main/kotlin/com/test/rest/TestController.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/test/rest/TestController.kt b/src/main/kotlin/com/test/rest/TestController.kt index 328cb5a..77f91e9 100644 --- a/src/main/kotlin/com/test/rest/TestController.kt +++ b/src/main/kotlin/com/test/rest/TestController.kt @@ -3,6 +3,7 @@ package com.test.rest import com.test.model.TestModel import com.test.service.TestService import org.slf4j.LoggerFactory +import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable @@ -22,19 +23,19 @@ open class TestController(private val testService: TestService) { //@PreAuthorize("hasRole('USER')") @PostMapping("/add") - fun add(@RequestBody testModel: TestModel): TestModel { - return testService.add(testModel) + fun add(@RequestBody testModel: TestModel): ResponseEntity { + return ResponseEntity.ok(testService.add(testModel)) } @PutMapping("/update") - fun users(@RequestBody testModel: TestModel): TestModel { - return testService.update(testModel) + fun users(@RequestBody testModel: TestModel): ResponseEntity { + return ResponseEntity.ok(testService.update(testModel)) } @GetMapping("/{id}") - fun get(@PathVariable(value = "id") id: Long): TestModel { - return testService.get(id)!! + fun get(@PathVariable(value = "id") id: Long): ResponseEntity { + return testService.get(id)?.let { ResponseEntity.ok(it) } ?: ResponseEntity.notFound().build() } @DeleteMapping("/{id}")