aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/controllers')
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Users.java40
1 files changed, 13 insertions, 27 deletions
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Users.java b/juick-api/src/main/java/com/juick/api/controllers/Users.java
index 75dea5f5..396a716c 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Users.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Users.java
@@ -5,6 +5,7 @@ import com.juick.api.util.HttpForbiddenException;
import com.juick.api.util.HttpNotFoundException;
import com.juick.service.UserService;
import com.juick.util.UserUtils;
+import com.juick.util.WebUtils;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,12 +16,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.inject.Inject;
import java.security.Principal;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
/**
- *
* @author ugnich
*/
@Controller
@@ -32,39 +30,27 @@ public class Users {
@RequestMapping(value = "/users", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public List<User> doGetUsers(
- @RequestParam(value = "uname", required = false) String[] punames,
- @RequestParam(value = "jid", required = false) String[] pjids) {
+ @RequestParam(value = "uname", required = false) List<String> unames,
+ @RequestParam(value = "jid", required = false) List<String> jids) {
List<com.juick.User> users = new ArrayList<>();
- if (punames != null) {
- ArrayList<String> unames = new ArrayList<>(Arrays.asList(punames));
- Iterator<String> i = unames.iterator();
- while (i.hasNext()) {
- if (!i.next().matches("^[a-zA-Z0-9\\-]{2,16}$")) {
- i.remove();
- }
- }
- if (!unames.isEmpty() && unames.size() < 20) {
+ if (unames != null) {
+ unames.removeIf(WebUtils::isNotUserName);
+
+ if (!unames.isEmpty() && unames.size() < 20)
users.addAll(userService.getUsersByName(unames));
- }
}
- if (pjids != null) {
- List<String> jids = new ArrayList<>(Arrays.asList(pjids));
- Iterator<String> ii = jids.iterator();
- while (ii.hasNext()) {
- if (!ii.next().matches("^[a-zA-Z0-9\\-\\_\\@\\.]{6,64}$")) {
- ii.remove();
- }
- }
- if (!jids.isEmpty() && jids.size() < 20) {
+ if (jids != null) {
+ jids.removeIf(WebUtils::isNotJid);
+
+ if (!jids.isEmpty() && jids.size() < 20)
users.addAll(userService.getUsersByJID(jids));
- }
}
- if (!users.isEmpty()) {
+ if (!users.isEmpty())
return users;
- }
+
throw new HttpNotFoundException();
}