From dfe75bb13736cb477cae97a5d336f6601a11113d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 27 Aug 2018 12:20:16 +0300 Subject: /info/{uname} API --- juick-server/src/main/java/com/juick/server/api/Users.java | 11 +++++++++++ .../src/test/java/com/juick/server/tests/ServerTests.java | 4 ++++ 2 files changed, 15 insertions(+) (limited to 'juick-server') diff --git a/juick-server/src/main/java/com/juick/server/api/Users.java b/juick-server/src/main/java/com/juick/server/api/Users.java index 41deddb8..1258e43c 100644 --- a/juick-server/src/main/java/com/juick/server/api/Users.java +++ b/juick-server/src/main/java/com/juick/server/api/Users.java @@ -18,6 +18,7 @@ package com.juick.server.api; import com.juick.User; +import com.juick.server.helpers.UserInfo; import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.HttpNotFoundException; import com.juick.service.MessagesService; @@ -135,6 +136,16 @@ public class Users { throw new HttpNotFoundException(); } + @ApiOperation(value = "This returns detailed user info") + @GetMapping("/info/{uname}") + public UserInfo getUserInfo(@PathVariable String uname) { + User user = userService.getUserByName(uname); + if (!user.isBanned()) { + return userService.getUserInfo(user); + } + throw new HttpNotFoundException(); + } + class SecureUser extends User { public String getHash() { return getAuthHash(); diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index 88cdd24c..95f459b4 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -1271,6 +1271,10 @@ public class ServerTests { .andExpect(status().isNotFound()); mockMvc.perform(get("/messages?uname=isilmine").with(httpBasic(ugnichName, ugnichPassword))) .andExpect(status().isNotFound()); + mockMvc.perform(get("/info/isilmine").with(httpBasic(ugnichName, ugnichPassword))) + .andExpect(status().isNotFound()); + mockMvc.perform(get("/info/ugnich").with(httpBasic(ugnichName, ugnichPassword))) + .andExpect(status().isOk()); } @Test -- cgit v1.2.3