From 686c0696e33197d3156d01d8ed6149350e3331ef Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Sat, 26 Nov 2016 23:11:59 +0700 Subject: using @RequestParam for request parameters --- .../java/com/juick/api/controllers/Messages.java | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'juick-api/src/main') diff --git a/juick-api/src/main/java/com/juick/api/controllers/Messages.java b/juick-api/src/main/java/com/juick/api/controllers/Messages.java index 414e9ba1..78c8ecc6 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Messages.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Messages.java @@ -10,7 +10,6 @@ import com.juick.service.MessagesService; import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.util.UserUtils; -import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -136,7 +135,8 @@ public class Messages { @RequestMapping("/thread") public ResponseEntity> getThread( - HttpServletRequest request) { + HttpServletRequest request, + @RequestParam(defaultValue = "0") int mid) { // TODO: use spring-security String auth = request.getHeader("Authorization"); int vuid = userService.getUIDByHttpAuth(auth); @@ -149,7 +149,6 @@ public class Messages { vuid = userService.getUIDbyHash(hash); } } - int mid = NumberUtils.toInt(request.getParameter("mid"), 0); com.juick.Message msg = messagesService.getMessage(mid); if (msg != null) { if (!messagesService.canViewThread(mid, vuid)) { @@ -164,7 +163,9 @@ public class Messages { } @RequestMapping("/messages/recommended") - public ResponseEntity> doGetRecommended(HttpServletRequest request) { + public ResponseEntity> doGetRecommended( + HttpServletRequest request, + @RequestParam(defaultValue = "0") int before_mid) { // TODO: use spring-security String auth = request.getHeader("Authorization"); int vuid = userService.getUIDByHttpAuth(auth); @@ -180,8 +181,6 @@ public class Messages { if (vuid == 0) { return FORBIDDEN; } - int before_mid = NumberUtils.toInt(request.getParameter("before_mid"), 0); - List mids = messagesService.getUserRecommendations(vuid, before_mid); if (mids != null && !mids.isEmpty()) { List msgs = messagesService.getMessages(mids); @@ -196,7 +195,9 @@ public class Messages { @RequestMapping("/messages/set_privacy") @ResponseBody - public Status doSetPrivacy(HttpServletRequest request) { + public Status doSetPrivacy( + HttpServletRequest request, + @RequestParam(defaultValue = "0") int mid) { // TODO: use spring-security String auth = request.getHeader("Authorization"); int vuid = userService.getUIDByHttpAuth(auth); @@ -212,20 +213,17 @@ public class Messages { if (vuid == 0) { throw new HttpForbiddenException(); } - int mid = NumberUtils.toInt(request.getParameter("mid"), 0); com.juick.User user = messagesService.getMessageAuthor(mid); if (user != null && user.getUid() == vuid && messagesService.setMessagePrivacy(mid)) { return Status.OK; - } else { - throw new HttpBadRequestException(); } + throw new HttpBadRequestException(); } @RequestMapping("/messages/set_popular") - public Status doSetPopular(HttpServletRequest request) { - int mid = NumberUtils.toInt(request.getParameter("mid"), 0); - int popular = NumberUtils.toInt(request.getParameter("popular"), 0); - + public Status doSetPopular( + @RequestParam(defaultValue = "0") int mid, + @RequestParam(defaultValue = "0") int popular) { if (mid > 0) { boolean ret = messagesService.setMessagePopular(mid, popular); -- cgit v1.2.3