Implement uuid functionality, update api description

This commit is contained in:
Marcel Schwarz 2020-09-05 04:54:11 +02:00
parent 6753b316d1
commit f63655bac4

View File

@ -5,31 +5,51 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap; import java.util.*;
import java.util.LinkedList; import java.util.stream.Collectors;
import java.util.Map;
@RestController @RestController
public class DefaultController { public class DefaultController {
@RequestMapping("/") @RequestMapping("/")
public Map<Object, Object> index() { public Object index() {
class Endpoint {
public String name;
public Map<Object, Object> params;
}
Map<Object, Object> map = new HashMap<>(); class Api {
map.put("name", "PasswordAPI"); public String name;
map.put("endpoint", "/api"); public List<Endpoint> endpoints;
}
Map<Object, Object> params = new HashMap<>(); Api api = new Api();
params.put("length", "int"); api.name = "PasswordAPI";
params.put("upper", "[on | off]"); api.endpoints = new ArrayList<>();
params.put("lower", "[on | off]");
params.put("number", "[on | off]");
params.put("special", "[on | off]");
params.put("exclude", "string");
params.put("repeat", "int");
map.put("params", params); //Password endpoint
return map; 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 // https://passwordwolf.com/?length=8&upper=off&lower=off&special=off&exclude=012345&repeat=20
@ -54,4 +74,20 @@ public class DefaultController {
.generate(); .generate();
} }
@RequestMapping("/uuid")
public LinkedList<String> generateUUID(
@RequestParam(required = false, defaultValue = "8") int repeat,
@RequestParam(required = false, defaultValue = "false") String braces) {
var list = new LinkedList<String>();
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;
}
} }