File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
src/main/kotlin/de/jakkoble/plugins Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,13 @@ fun Application.configureHTTP() {
2727 post(Fruit .path) {
2828 if (isInvalidKey(call.parameters[" key" ].toString())) return @post // Check if the Key is WRONG => Stop Here
2929 val fruit = call.receive<Fruit >() // Receive Content of Request as Fruit
30- if (! Fruits .list.none { it.name == fruit.name }) error(" Name already in use" ) // If name is already in the List throw IllegalStateException
30+ if (! Fruits .list.none { it.name == fruit.name }) { // Check if incomming Fruit is already in List
31+ println (" [Failed] Adding Fruit '${fruit.name} ' - Fruit already exists." )
32+ return @post
33+ }
3134 Fruits .list.add(fruit) // Add Fruit to Fruit List
3235 call.respond(HttpStatusCode .OK ) // Respond Status Code for clean Communication
36+ println (" [Success] Added Fruit '${fruit.name} ' to Fruit List." )
3337 }
3438
3539 // Delete-Request with the companion object parameter of Fruit Class
@@ -38,6 +42,7 @@ fun Application.configureHTTP() {
3842 val name = call.receive<Fruit >().name // Receive Content of Request as Fruit
3943 Fruits .list.removeIf { it.name == name } // Removes the Element with the name of the Request item
4044 call.respond(HttpStatusCode .OK ) // Respond Status Code for clean Communication
45+ println (" [Success] Deleted Fruit '$name ' from Fruit List." )
4146 }
4247 }
4348}
You can’t perform that action at this time.
0 commit comments