SHARE
TWEET

Untitled

a guest Sep 3rd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  private def validateInn(inn: String): Boolean = {
  2.     val tenDigitsInn = "[0-9]{10}"
  3.     val twelveDigitsInn = "[0-9]{12}"
  4.     inn.matches(tenDigitsInn) || inn.matches(twelveDigitsInn)
  5.   }
  6.  
  7.   private def validateOgrn(ogrn: String): Boolean = {
  8.     val thirteenDigitsInn = "[0-9]{13}"
  9.     val fifteenDigitsInn = "[0-9]{15}"
  10.     ogrn.matches(thirteenDigitsInn) || ogrn.matches(fifteenDigitsInn)
  11.   }
  12.  
  13.   private def validateKpp(kpp: Option[String]): Boolean = {
  14.     val nineDigitsInn = "[0-9]{9}"
  15.     kpp.isEmpty || kpp.exists(_.matches(nineDigitsInn))
  16.   }
  17.  
  18.   private def validateEmail(mail: String): Boolean = {
  19.     mail.contains("@")
  20.   }
  21.  
  22.   @ApiOperation(value = "create new company", notes = "", nickname = "company-create", httpMethod = "POST")
  23.   @ApiImplicitParams(Array(
  24.     new ApiImplicitParam(name = "body", required = true, dataType = "btp.cap.entity.Company", paramType = "body")
  25.   ))
  26.   @ApiResponses(Array(
  27.     new ApiResponse(code = Success.code, message = Success.message, response = classOf[Company]),
  28.     new ApiResponse(code = BadRequest.code, message = BadRequest.message, response = classOf[ErrorMessage]),
  29.     new ApiResponse(code = Unauthorized.code, message = Unauthorized.message, response = classOf[ErrorMessage]),
  30.     new ApiResponse(code = Forbidden.code, message = Forbidden.message, response = classOf[ErrorMessage]),
  31.     new ApiResponse(code = InternalServerError.code, message = InternalServerError.message, response = classOf[ErrorMessage])
  32.   ))
  33.   def postCompany(implicit @ApiParam(hidden = true) user: User): Route = {
  34.     (post & pathEndOrSingleSlash & entity(as[Company])) { company =>
  35.       (validate(validateInn(company.inn), "company inn is incorrect") &
  36.         validate(validateOgrn(company.ogrn), "company ogrn is incorrect") &
  37.         validate(validateKpp(company.kpp), "company kpp is incorrect") &
  38.         validate(validateEmail(company.email), "company email must contain @")) {
  39.         complete(companyService.postCompany(user, company))
  40.       }
  41.     }
  42.   }
  43.  
  44.   @ApiOperation(value = "put company", notes = "", nickname = "company-put", httpMethod = "PUT")
  45.   @ApiImplicitParams(Array(
  46.     new ApiImplicitParam(name = Id.name, value = Id.value, required = Id.required, dataType = Id.dataType, paramType = Id.paramType),
  47.     new ApiImplicitParam(name = "body", required = true, dataType = "btp.cap.entity.Company", paramType = "body")
  48.   ))
  49.   @ApiResponses(Array(
  50.     new ApiResponse(code = Success.code, message = Success.message, response = classOf[PutCompany]),
  51.     new ApiResponse(code = Unauthorized.code, message = Unauthorized.message, response = classOf[ErrorMessage]),
  52.     new ApiResponse(code = Forbidden.code, message = Forbidden.message, response = classOf[ErrorMessage]),
  53.     new ApiResponse(code = NotFound.code, message = NotFound.message, response = classOf[ErrorMessage]),
  54.     new ApiResponse(code = BadRequest.code, message = BadRequest.message, response = classOf[ErrorMessage]),
  55.     new ApiResponse(code = UnprocessableEntity.code, message = UnprocessableEntity.message, response = classOf[ErrorMessage]),
  56.     new ApiResponse(code = InternalServerError.code, message = InternalServerError.message, response = classOf[ErrorMessage])
  57.   ))
  58.   def putCompany(implicit @ApiParam(hidden = true) user: User): Route =
  59.     (put & path(IntNumber) & entity(as[PutCompany])) {
  60.       (id, company) => {
  61.         (validate(validateInn(company.inn), "company inn is incorrect") &
  62.           validate(validateOgrn(company.ogrn), "company ogrn is incorrect") &
  63.           validate(validateKpp(company.kpp), "company kpp is incorrect") &
  64.           validate(validateEmail(company.email), "company email must contain @")) {
  65.           complete(companyService.putCompany(user, CompanyId(id), company))
  66.         }
  67.       }
  68.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top