Package ru.org.linux.comment

Source Code of ru.org.linux.comment.ShowCommentsController

/*
* Copyright 1998-2014 Linux.org.ru
*    Licensed under the Apache License, Version 2.0 (the "License");
*    you may not use this file except in compliance with the License.
*    You may obtain a copy of the License at
*
*        http://www.apache.org/licenses/LICENSE-2.0
*
*    Unless required by applicable law or agreed to in writing, software
*    distributed under the License is distributed on an "AS IS" BASIS,
*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*    See the License for the specific language governing permissions and
*    limitations under the License.
*/

package ru.org.linux.comment;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import ru.org.linux.auth.AccessViolationException;
import ru.org.linux.site.Template;
import ru.org.linux.user.User;
import ru.org.linux.user.UserDao;
import ru.org.linux.user.UserNotFoundException;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ShowCommentsController {
  @Autowired
  private UserDao userDao;

  @Autowired
  private CommentService commentService;

  @RequestMapping("/show-comments.jsp")
  public RedirectView showComments(
          @RequestParam String nick
  ) throws Exception {
    User user = userDao.getUser(nick);

    return new RedirectView("search.jsp?range=COMMENTS&user="+user.getNick()+"&sort=DATE");
  }

  @RequestMapping(value="/people/{nick}/deleted-comments")
  public ModelAndView showCommentsOld(
    @PathVariable String nick,
    HttpServletRequest request
  ) throws Exception {
    Template tmpl = Template.getTemplate(request);
    if (!tmpl.isModeratorSession()) {
      throw new AccessViolationException("Not moderator");
    }

    ModelAndView mv = new ModelAndView("deleted-comments");

    User user = userDao.getUser(nick);

    mv.getModel().put("user", user);

    mv.getModel().put("deletedList", commentService.getDeletedComments(user));

    return mv;
  }

  @ExceptionHandler(UserNotFoundException.class)
  @ResponseStatus(HttpStatus.NOT_FOUND)
  public ModelAndView handleUserNotFound() {
    ModelAndView mav = new ModelAndView("errors/good-penguin");
    mav.addObject("msgTitle", "Ошибка: пользователя не существует");
    mav.addObject("msgHeader", "Пользователя не существует");
    mav.addObject("msgMessage", "");
    return mav;
  }
}
TOP

Related Classes of ru.org.linux.comment.ShowCommentsController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.