@RequestMapping(
      value = {"/offers/apply/{offerId}"},
      method = RequestMethod.GET)
  public ModelAndView applyOffer(@PathVariable String offerId, HttpServletRequest request)
      throws IOException {

    ModelAndView mv = new ModelAndView("displayOffers");
    super.setFooterDisPlayON(mv);
    mv.addObject("mainClass", mainClass);

    String candidatId = (String) request.getSession().getAttribute(AController.USER_ID);
    super.setAuth();

    ClientOffers byId = clientsJobsService.getById(offerId);
    mv.addObject("offers", byId);
    if (super.authName != null
        && !super.authName.isEmpty()
        && !"anonymousUser".equals(super.authName)
        && !"ROLE_CLIENT".equals(super.getAuthType())) {

      ArrayList<CandidatOffers> byOfferId = candidatOffersService.getByOfferId(offerId);
      boolean alreadyApply = false;
      for (CandidatOffers offer : byOfferId) {

        if (candidatId == null
            ? offer.getPartialCandidat().getId() == null
            : candidatId.equals(offer.getPartialCandidat().getId())) {
          alreadyApply = true;
          break;
        }
      }
      if (!alreadyApply) {

        CandidatOffers candidatOffers = new CandidatOffers();
        candidatOffers.setId(UUID.randomUUID().toString());
        candidatOffers.setDate(new Date().toString());
        PartialCandidat partialCandidat = new PartialCandidat();
        partialCandidat.setId(candidatId);
        candidatOffers.setOfferId(offerId);
        candidatOffers.setPartialCandidat(partialCandidat);
        candidatOffersService.addCandidatOffers(candidatOffers);
        this.sendApplicationMail(candidatOffers, byId);
        mv.addObject("applyOk", true);
      } else {
        mv.addObject("alreadyApply", alreadyApply);
      }

    } else {
      mv.addObject("noAuth", true);
    }

    return mv;
  }