@RequestMapping("/userpage") public String starpage(Model model, @RequestParam(value = "page", defaultValue = "1") int page) { Page<Post> postsPage = postsService.getPosts(page, 5); // 5 постів на сторінку model.addAttribute("posts", postsPage.getContent()); model.addAttribute("pagesCount", postsPage.getTotalPages()); model.addAttribute("currentPage", page); model.addAttribute("currentUser", User.getCurrentUser()); model.addAttribute("user", User.getCurrentUser()); return "user_page"; }
@Transactional public void addPost( String title, String text, Long partners, Long days, Date mdate, ArrayList<Point> track) { User currentUser = usersRepo.findOne(User.getCurrentUserId()); // Post p = new Post(currentUser, title, text, partners, days, mdate, new Date())); Post p = new Post(currentUser, title, text, partners, days, new Date(), new Date(), track); postsRepo.save(p); }
@RequestMapping("/") public String index(Model model) { // якщо користувач вже увійшов, то перекинути його з реєстрації на домашню сторінку if (!User.isAnonymous()) { return "redirect:/list"; } // model.addAttribute("form", new RegistrationForm()); return "index"; }
@RequestMapping(value = "/userprofile", method = RequestMethod.GET) public String userProfile( Model model, @RequestParam(value = "user_id", defaultValue = "") String userId) { Long id = 0L; boolean parsingSucces = true; if (userId.length() > 0) { try { id = Long.parseLong(userId); if (usersService.getUser(id) == null) id = User.getCurrentUser().getId(); } catch (NumberFormatException numFormatException) { parsingSucces = false; } } if (!parsingSucces || userId.length() == 0) id = User.getCurrentUser().getId(); model.addAttribute("user", usersService.getUser(id)); model.addAttribute("current_user_id", User.getCurrentUser().getId()); return "user_profile"; }
@RequestMapping("/list") public String list(Model model, @RequestParam(value = "page", defaultValue = "1") int page) { System.out.println("before get posts"); Page<Post> postsPage = postsService.getAllPosts(page, 5); // 5 постів на сторінку model.addAttribute("posts", postsPage.getContent()); model.addAttribute("pagesCount", postsPage.getTotalPages()); model.addAttribute("currentPage", page); model.addAttribute("currentUser", User.getCurrentUser()); return "list"; }
@RequestMapping(value = "/storeuserinfo", method = RequestMethod.POST) public String storeUserInfo( HttpServletRequest request, @RequestParam(value = "address", defaultValue = "") String address, @RequestParam(value = "phone", defaultValue = "") String phone, @RequestParam(value = "fullName", defaultValue = "") String fullName, @RequestParam(value = "gender", defaultValue = "") Gender gender) { User u = User.getCurrentUser(); u.setAddress(address); u.setPhone(phone); u.setFullName(fullName); u.setGender(gender); usersService.updateUserInfo(u); String referer = request.getHeader("Referer"); return "redirect:" + referer; }
@RequestMapping(value = "/login", method = RequestMethod.GET) public String loginForm(RedirectAttributes attr, HttpSession session) { if (!User.isAnonymous()) return "redirect:/list"; return "redirect:/"; }
@RequestMapping(value = "/remove_comment", method = RequestMethod.POST) public ResponseEntity removeComment(@RequestBody Long commentId) { if (commentService.findComment(commentId).getAuthor().getId() == User.getCurrentUserId()) commentService.removeComment(commentId); return new ResponseEntity(HttpStatus.OK); }