-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new endpointa for deletions, introduce service class for dockerma…
…chine
- Loading branch information
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/tech/niklas/ariesbackend/service/DockerMachineService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package tech.niklas.ariesbackend.service | ||
|
||
import tech.niklas.ariesbackend.db.DockerMachineRepository | ||
import tech.niklas.ariesbackend.exception.MachineAlreadyExistsException | ||
import tech.niklas.ariesbackend.model.DockerMachine | ||
import kotlin.jvm.optionals.getOrElse | ||
|
||
class DockerMachineService(private val dockerMachineRepository: DockerMachineRepository, | ||
private val dockerMachineService: DockerMachineService) { | ||
|
||
|
||
fun registerNew(dockerMachine: DockerMachine): DockerMachine { | ||
if(dockerMachineRepository.existsByMachineName(dockerMachine.machineName) ) { | ||
throw MachineAlreadyExistsException("The machine ${dockerMachine.machineName} already exists in the database!") | ||
} | ||
return dockerMachineRepository.save(dockerMachine) | ||
} | ||
|
||
fun getAll(): List<DockerMachine> { | ||
return dockerMachineRepository.findAll() | ||
} | ||
|
||
fun getSpecificMachine(id: String): DockerMachine { | ||
return dockerMachineRepository.findById(id).getOrElse { | ||
throw MachineAlreadyExistsException("not found lol") | ||
} | ||
} | ||
|
||
fun deleteMachine(id: String): String { | ||
dockerMachineRepository.deleteById(id) | ||
return "Deleted machine with id $id" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters