@RequestMapping(
      value = {"/updatesto/{id}"},
      method = {RequestMethod.POST})
  public ModelAndView updatesto(
      @PathVariable Long id,
      @ModelAttribute("sto") Sto sto,
      BindingResult bindingResult,
      Model model,
      HttpSession session,
      Authentication auth) {
    ModelAndView mav = new ModelAndView();
    rentValidator.validate(sto, bindingResult);
    if (bindingResult.hasErrors()) {
      logger.info("Returning updatesto.jsp page");
      UserPrincipal user = userService.getUserByName(auth.getName());
      mav.addObject("user", user);
      mav.addObject("sto", directorService.getStoById(id));
      mav.setViewName("director.updatesto");
      return mav;
    }

    Sto sto1 = directorService.getStoById(id);
    sto1.setName(sto.getName());
    sto1.setPrice(sto.getPrice());
    directorService.addSto(sto1);
    mav.setViewName("redirect:/home");
    return mav;
  }
  @PreAuthorize("isFullyAuthenticated()")
  @RequestMapping(value = "/mechaniclistbysto/{id}", method = RequestMethod.GET)
  public ModelAndView getmechaniclistbysto(
      @RequestParam(value = "page", required = false) Integer page,
      @PathVariable Long id,
      HttpSession session,
      Authentication auth) {
    ModelAndView mav = new ModelAndView();
    UserPrincipal user = userService.getUserByName(auth.getName());
    Sto sto = directorService.getStoById(id);
    Number size1 = directorService.getSizeMechanicOnSto(sto);
    int size = Integer.parseInt(size1.toString());
    System.out.println("Test test test" + sto.getName());
    if (page == null) page = 1;
    Integer pageSize = 3;
    Integer startPage = page;
    Integer endPage = page + 5;
    Integer lastPage = (size + (pageSize - 1)) / pageSize;

    if (endPage >= lastPage) endPage = lastPage;
    if (endPage >= 5 && (endPage - startPage) < 5) startPage = endPage - 5;

    mav.addObject("page", page);
    mav.addObject("startpage", startPage);
    mav.addObject("endpage", endPage);

    mav.addObject("user", user);
    mav.addObject(
        "mechanic", directorService.getMechanicsOnSto(sto, (page - 1) * pageSize, pageSize));
    mav.setViewName("director.mechaniclistbysto");
    return mav;
  };
  @RequestMapping(
      value = {"/addsto"},
      method = {RequestMethod.POST})
  public ModelAndView addsto(
      @ModelAttribute("sto") Sto sto,
      BindingResult bindingResult,
      Model model,
      HttpSession session,
      Authentication auth) {
    ModelAndView mav = new ModelAndView();
    stoValidator.validate(sto, bindingResult);
    if (bindingResult.hasErrors()) {
      UserPrincipal user = userService.getUserByName(auth.getName());
      mav.addObject("user", user);
      logger.info("Returning addsto.jsp page");
      mav.setViewName("director.addsto");
      return mav;
    }

    sto.setRating((float) 0);
    directorService.addSto(sto);
    mav.setViewName("redirect:/home");
    return mav;
  }