Implement uuid functionality, update api description
This commit is contained in:
parent
6753b316d1
commit
f63655bac4
@ -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<Object, Object> index() {
|
||||
public Object index() {
|
||||
|
||||
class Endpoint {
|
||||
public String name;
|
||||
public Map<Object, Object> params;
|
||||
}
|
||||
|
||||
Map<Object, Object> map = new HashMap<>();
|
||||
map.put("name", "PasswordAPI");
|
||||
map.put("endpoint", "/api");
|
||||
class Api {
|
||||
public String name;
|
||||
public List<Endpoint> endpoints;
|
||||
}
|
||||
|
||||
Map<Object, Object> 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<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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user