From 771c27021c033f5b6b9a3d9fdcd4048f9d8023af Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Mon, 21 Nov 2016 13:38:27 +0700 Subject: spring-www project skeleton --- .../com/juick/www/controllers/HelpController.java | 12 +++++ .../com/juick/www/controllers/IndexController.java | 24 ++++++++++ .../juick/www/controllers/SettingsController.java | 16 +++++++ .../www/controllers/ShowMessageController.java | 52 ++++++++++++++++++++++ .../com/juick/www/controllers/TagController.java | 37 +++++++++++++++ 5 files changed, 141 insertions(+) create mode 100644 juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java create mode 100644 juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java create mode 100644 juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java create mode 100644 juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java create mode 100644 juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java (limited to 'juick-spring-www/src/main/java/com/juick/www/controllers') diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java new file mode 100644 index 00000000..dad3ff9f --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java @@ -0,0 +1,12 @@ +package com.juick.www.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * Created by aalexeev on 11/21/16. + */ +@Controller +@RequestMapping("/help") +public class HelpController { +} diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java new file mode 100644 index 00000000..2973bf30 --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java @@ -0,0 +1,24 @@ +package com.juick.www.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * Created by aalexeev on 11/21/16. + */ +@Controller +public class IndexController { + + @RequestMapping("/") + public String index( + java.security.Principal userPrincipal, + @RequestParam(required = false, defaultValue = "0") int before, + Model model) { + + model.addAttribute("currentUser", userPrincipal); + + return "index"; + } +} diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java new file mode 100644 index 00000000..eef41c38 --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java @@ -0,0 +1,16 @@ +package com.juick.www.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * Created by aalexeev on 11/21/16. + */ +@Controller +public class SettingsController { + + @RequestMapping("/settings") + public String showSettings() { + return "index"; + } +} diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java new file mode 100644 index 00000000..338dc9be --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java @@ -0,0 +1,52 @@ +package com.juick.www.controllers; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.regex.Pattern; + +/** + * Created by aalexeev on 11/21/16. + */ +@Controller +public class ShowMessageController { + private static final Pattern USER_NAME_PATTERN = Pattern.compile("[a-zA-Z-_\\d]{2,16}"); + + private static final Pattern POST_NUMBER_PATTERN = Pattern.compile("\\d+"); + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + + @RequestMapping("/{anything}") + public String parseAnything( + @PathVariable String anything, + @RequestParam(required = false, defaultValue = "0") int before, + Model model) { + + boolean isUsername = USER_NAME_PATTERN.matcher(anything).matches(); + boolean isPostNumber = POST_NUMBER_PATTERN.matcher(anything).matches(); + + return "redirect:/"; + } + + @RequestMapping("/{userName}/{postNumber}") + public String checkShowPost( + @PathVariable String userName, + @PathVariable String postNumber, + @RequestParam(required = false, defaultValue = "0") int before, + Model model) { + + if (!USER_NAME_PATTERN.matcher(userName).matches() || + !POST_NUMBER_PATTERN.matcher(postNumber).matches()) { + logger.warn("Invalid user name or post number, user name \"{}\", post number \"{}\"", userName, postNumber); + return "redirect:/"; + } + + return "index"; + } +} diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java new file mode 100644 index 00000000..5c3b6287 --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java @@ -0,0 +1,37 @@ +package com.juick.www.controllers; + +import com.juick.service.MessagesService; +import com.juick.service.TagService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import javax.inject.Inject; + +/** + * Created by aalexeev on 11/21/16. + */ +@Controller +public class TagController { + @Inject + private TagService tagService; + @Inject + private MessagesService messagesService; + + + @RequestMapping("/tag/{tagName}") + public String showTags( + @PathVariable String tagName, + @RequestParam(required = false, defaultValue = "0") int before, + Model model) { + + return "index"; + } + + @RequestMapping("/tag") + public String redirectToMain() { + return "redirect:/"; + } +} -- cgit v1.2.3