diff options
author | Vitaly Takmazov | 2017-04-07 10:29:52 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-04-07 10:29:52 +0300 |
commit | 9820abe11c0c037f50bb2f7ddbb0bd19646264dc (patch) | |
tree | 5a33901fc294546c40b0cdbc65640b041e4c694e /juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java | |
parent | 6951e2ad47ed4db3dc7d0b08aeadeb09bc3b994d (diff) |
juick-www: merge juick-spring-www i18n, drop thymeleaf
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java')
-rw-r--r-- | juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java | 112 |
1 files changed, 0 insertions, 112 deletions
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 deleted file mode 100644 index 8c4ab46d..00000000 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.juick.www.controllers; - -import com.juick.Message; -import com.juick.User; -import com.juick.server.util.HttpNotFoundException; -import com.juick.service.AdsService; -import com.juick.service.MessagesService; -import com.juick.service.TagService; -import com.juick.service.UserService; -import com.juick.util.UserUtils; -import com.juick.www.helpers.QueryString; -import org.apache.commons.lang3.CharEncoding; -import org.apache.commons.lang3.StringEscapeUtils; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -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; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * Created by aalexeev on 11/21/16. - */ -@Controller -public class TagController { - @Inject - private TagService tagService; - @Inject - private MessagesService messagesService; - @Inject - private AdsService adsService; - @Inject - private UserService userService; - - - @RequestMapping("/tag/{tagName}") - protected String doGet( - @PathVariable("tagName") String paramTagStr, - @RequestParam(value = "before", required = false, defaultValue = "0") Integer paramBefore, - @QueryString Optional<String> queryString, - ModelMap model) throws UnsupportedEncodingException { - User visitor = UserUtils.getCurrentUser(); - - com.juick.Tag paramTag = tagService.getTag(paramTagStr, false); - if (paramTag == null) { - throw new HttpNotFoundException(); - } else if (paramTag.SynonymID > 0 && paramTag.TID != paramTag.SynonymID) { - com.juick.Tag synTag = tagService.getTag(paramTag.SynonymID); - String url = "/tag/" + URLEncoder.encode(synTag.getName(), CharEncoding.UTF_8); - if (queryString.isPresent()) { - url += "?" + queryString.get(); - } - return "redirect:" + url; - } else if (!paramTag.getName().equals(paramTagStr)) { - String url = "/tag/" + URLEncoder.encode(paramTag.getName(), CharEncoding.UTF_8); - if (queryString.isPresent()) { - url += "?" + queryString.get(); - } - return "redirect:" + url; - } - - int visitor_uid = visitor != null ? visitor.getUid() : 0; - - String title = "*" + StringEscapeUtils.escapeHtml4(paramTag.getName()); - List<Integer> mids = messagesService.getTag(paramTag.TID, visitor_uid, paramBefore, (visitor == null) ? 40 : 20); - model.addAttribute("title", title); - if (tagService.getTagNoIndex(paramTag.TID)) { - model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex,nofollow\"/>"); - } else if (paramBefore > 0 || mids.size() < 5) { - model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>"); - } - if (mids.size() > 0) { - int vuid = visitor != null ? visitor.getUid() : 0; - int ad_mid = adsService.getAdMid(vuid); - if (ad_mid > 0 && mids.indexOf(ad_mid) == -1) { - mids.add(0, ad_mid); - adsService.logAdMid(vuid, ad_mid); - } else { - ad_mid = 0; - } - } - List<Message> msgs = messagesService.getMessages(mids); - List<Integer> blUIDs = userService.checkBL(visitor_uid, - msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList())); - model.addAttribute("msgs", - msgs.stream().map(msg -> { - msg.ReadOnly |= blUIDs.contains(msg.getUser().getUid()); - if (msg.ReadOnly) { - msg.ReadOnly = visitor.getUid() != msg.getUser().getUid(); - } - return msg; - }).collect(Collectors.toList()) - ); - if (mids.size() >= 20) { - String nextpage = "/tag/" + URLEncoder.encode(paramTag.getName(), CharEncoding.UTF_8) + "?before=" + mids.get(mids.size() - 1); - model.addAttribute("nextpage", nextpage); - } - model.addAttribute("tags", tagService.getPopularTags()); - return "views/index"; - } - - @RequestMapping("/tag") - public String redirectToMain() { - return "redirect:/"; - } -} |