Example #1
0
 @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);
 }
Example #3
0
 @RequestMapping("/")
 public String index(Model model) {
   // якщо користувач вже увійшов, то перекинути його з реєстрації на домашню сторінку
   if (!User.isAnonymous()) {
     return "redirect:/list";
   }
   // model.addAttribute("form", new RegistrationForm());
   return "index";
 }
Example #4
0
  @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";
  }
Example #5
0
 @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";
 }
Example #6
0
 @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;
 }
Example #7
0
 @RequestMapping(value = "/login", method = RequestMethod.GET)
 public String loginForm(RedirectAttributes attr, HttpSession session) {
   if (!User.isAnonymous()) return "redirect:/list";
   return "redirect:/";
 }
Example #8
0
 @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);
 }