aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src/main/java/com/juick/www/controllers
diff options
context:
space:
mode:
authorGravatar Alexander Alexeev2016-11-21 13:38:27 +0700
committerGravatar Vitaly Takmazov2016-11-23 13:03:05 +0300
commit771c27021c033f5b6b9a3d9fdcd4048f9d8023af (patch)
tree558442fc7e5244953a8acc7444fb5c9a764f646a /juick-spring-www/src/main/java/com/juick/www/controllers
parente9aa20922c82bfad64adbcb6466ebdac23a84244 (diff)
spring-www project skeleton
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www/controllers')
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/HelpController.java12
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java24
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java16
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java52
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java37
5 files changed, 141 insertions, 0 deletions
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:/";
+ }
+}