From 95b0fba3c85d06bfdc034f9585fae8f74bffc151 Mon Sep 17 00:00:00 2001 From: Kaseax Date: Mon, 9 Dec 2024 20:04:58 +0100 Subject: [PATCH] refactor: add memory validation on group creation --- .../controller/runtime/group/GroupService.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/controller-runtime/src/main/kotlin/app/simplecloud/controller/runtime/group/GroupService.kt b/controller-runtime/src/main/kotlin/app/simplecloud/controller/runtime/group/GroupService.kt index 201933a..8c7ff6e 100644 --- a/controller-runtime/src/main/kotlin/app/simplecloud/controller/runtime/group/GroupService.kt +++ b/controller-runtime/src/main/kotlin/app/simplecloud/controller/runtime/group/GroupService.kt @@ -34,6 +34,11 @@ class GroupService( groupRepository.find(request.group.name) ?: throw StatusException(Status.NOT_FOUND.withDescription("This group does not exist")) val group = Group.fromDefinition(request.group) + + if (group.minMemory > group.maxMemory) { + throw StatusException(Status.INVALID_ARGUMENT.withDescription("Minimum memory must be smaller than maximum memory")) + } + try { groupRepository.save(group) } catch (e: Exception) { @@ -47,6 +52,11 @@ class GroupService( throw StatusException(Status.NOT_FOUND.withDescription("This group already exists")) } val group = Group.fromDefinition(request.group) + + if (group.minMemory > group.maxMemory) { + throw StatusException(Status.INVALID_ARGUMENT.withDescription("Minimum memory must be smaller than maximum memory")) + } + try { groupRepository.save(group) } catch (e: Exception) {