From f63655bac4c4927dd78d2f8b59b99a75093db261 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 5 Sep 2020 04:54:11 +0200 Subject: [PATCH] Implement uuid functionality, update api description --- .../icaotix/controller/DefaultController.java | 70 ++++++++++++++----- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/icaotix/controller/DefaultController.java b/src/main/java/de/icaotix/controller/DefaultController.java index 5bd9528..8eadc3d 100644 --- a/src/main/java/de/icaotix/controller/DefaultController.java +++ b/src/main/java/de/icaotix/controller/DefaultController.java @@ -5,31 +5,51 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; @RestController public class DefaultController { @RequestMapping("/") - public Map index() { + public Object index() { + + class Endpoint { + public String name; + public Map params; + } - Map map = new HashMap<>(); - map.put("name", "PasswordAPI"); - map.put("endpoint", "/api"); + class Api { + public String name; + public List endpoints; + } - Map params = new HashMap<>(); - params.put("length", "int"); - params.put("upper", "[on | off]"); - params.put("lower", "[on | off]"); - params.put("number", "[on | off]"); - params.put("special", "[on | off]"); - params.put("exclude", "string"); - params.put("repeat", "int"); + Api api = new Api(); + api.name = "PasswordAPI"; + api.endpoints = new ArrayList<>(); - map.put("params", params); - return map; + //Password endpoint + Endpoint passwordEndpoint = new Endpoint(); + passwordEndpoint.name = "/api"; + passwordEndpoint.params = new HashMap<>(); + passwordEndpoint.params.put("length", "int"); + passwordEndpoint.params.put("upper", "[on | off]"); + passwordEndpoint.params.put("lower", "[on | off]"); + passwordEndpoint.params.put("number", "[on | off]"); + passwordEndpoint.params.put("special", "[on | off]"); + passwordEndpoint.params.put("exclude", "string"); + passwordEndpoint.params.put("repeat", "int"); + api.endpoints.add(passwordEndpoint); + + //UUID endpoint + Endpoint uuidEndpoint = new Endpoint(); + uuidEndpoint.name = "/uuid"; + uuidEndpoint.params = new HashMap<>(); + uuidEndpoint.params.put("repeat", "int"); + uuidEndpoint.params.put("braces", "[on | off]"); + api.endpoints.add(uuidEndpoint); + + return api; } // https://passwordwolf.com/?length=8&upper=off&lower=off&special=off&exclude=012345&repeat=20 @@ -54,4 +74,20 @@ public class DefaultController { .generate(); } + @RequestMapping("/uuid") + public LinkedList generateUUID( + @RequestParam(required = false, defaultValue = "8") int repeat, + @RequestParam(required = false, defaultValue = "false") String braces) { + var list = new LinkedList(); + for (int i = 0; i < repeat; i++) { + list.add(UUID.randomUUID().toString()); + } + if (braces.equals("on")) { + list = list.stream() + .map(s -> "{" + s + "}") + .collect(Collectors.toCollection(LinkedList::new)); + } + return list; + } + } \ No newline at end of file