From 4d435084bc485e75609add068dd0c8742f70f740 Mon Sep 17 00:00:00 2001 From: Niklas Haiden Date: Tue, 10 Oct 2023 08:28:21 +0200 Subject: [PATCH] new endpoints for docker machines --- .../MachineAlreadyExistsException.kt | 2 +- .../ariesbackend/web/MachineController.kt | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/tech/niklas/ariesbackend/exception/MachineAlreadyExistsException.kt b/src/main/kotlin/tech/niklas/ariesbackend/exception/MachineAlreadyExistsException.kt index 457f2c4..345b634 100644 --- a/src/main/kotlin/tech/niklas/ariesbackend/exception/MachineAlreadyExistsException.kt +++ b/src/main/kotlin/tech/niklas/ariesbackend/exception/MachineAlreadyExistsException.kt @@ -5,4 +5,4 @@ import java.lang.Exception class MachineAlreadyExistsException: Exception { constructor() : super() constructor(message: String): super(message) -} \ No newline at end of file +} diff --git a/src/main/kotlin/tech/niklas/ariesbackend/web/MachineController.kt b/src/main/kotlin/tech/niklas/ariesbackend/web/MachineController.kt index 0f7d279..5e51b79 100644 --- a/src/main/kotlin/tech/niklas/ariesbackend/web/MachineController.kt +++ b/src/main/kotlin/tech/niklas/ariesbackend/web/MachineController.kt @@ -1,14 +1,14 @@ package tech.niklas.ariesbackend.web +import org.springframework.data.crossstore.ChangeSetPersister.NotFoundException import org.springframework.http.HttpStatus -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* import org.springframework.web.server.ResponseStatusException import tech.niklas.ariesbackend.db.DockerMachineRepository import tech.niklas.ariesbackend.exception.MachineAlreadyExistsException import tech.niklas.ariesbackend.model.DockerMachine +import kotlin.jvm.optionals.getOrElse +import kotlin.jvm.optionals.getOrNull @RestController @RequestMapping("/machine") @@ -21,5 +21,17 @@ class MachineController(private val dockerMachineRepository: DockerMachineReposi return dockerMachineRepository.save(dockerMachine) } + @GetMapping("/get") + fun getAll(): List { + return dockerMachineRepository.findAll() + } + + @GetMapping("/get/{id}") + fun getSpecificMachine(@PathVariable id: String): DockerMachine { + return dockerMachineRepository.findById(id).getOrElse { + throw MachineAlreadyExistsException("not found lol") + } + } + } \ No newline at end of file