Add addType to TypeController

This commit is contained in:
2024-11-19 14:11:19 +01:00
parent ba6f38a585
commit 16784e4aff
3 changed files with 36 additions and 0 deletions

View File

@@ -4,8 +4,11 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import ltd.hlaeja.library.deviceRegistry.Type
import ltd.hlaeja.service.TypeService
import ltd.hlaeja.util.toTypeEntity
import ltd.hlaeja.util.toTypeResponse
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController
@RestController
@@ -15,4 +18,9 @@ class TypeController(
@GetMapping("/types")
fun getTypes(): Flow<Type.Response> = service.getTypes().map { it.toTypeResponse() }
@PostMapping("/type")
suspend fun addType(
@RequestBody register: Type.Request,
): Type.Response = service.addType(register.toTypeEntity()).toTypeResponse()
}