Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private def validateInn(inn: String): Boolean = {
- val tenDigitsInn = "[0-9]{10}"
- val twelveDigitsInn = "[0-9]{12}"
- inn.matches(tenDigitsInn) || inn.matches(twelveDigitsInn)
- }
- private def validateOgrn(ogrn: String): Boolean = {
- val thirteenDigitsInn = "[0-9]{13}"
- val fifteenDigitsInn = "[0-9]{15}"
- ogrn.matches(thirteenDigitsInn) || ogrn.matches(fifteenDigitsInn)
- }
- private def validateKpp(kpp: Option[String]): Boolean = {
- val nineDigitsInn = "[0-9]{9}"
- kpp.isEmpty || kpp.exists(_.matches(nineDigitsInn))
- }
- private def validateEmail(mail: String): Boolean = {
- mail.contains("@")
- }
- @ApiOperation(value = "create new company", notes = "", nickname = "company-create", httpMethod = "POST")
- @ApiImplicitParams(Array(
- new ApiImplicitParam(name = "body", required = true, dataType = "btp.cap.entity.Company", paramType = "body")
- ))
- @ApiResponses(Array(
- new ApiResponse(code = Success.code, message = Success.message, response = classOf[Company]),
- new ApiResponse(code = BadRequest.code, message = BadRequest.message, response = classOf[ErrorMessage]),
- new ApiResponse(code = Unauthorized.code, message = Unauthorized.message, response = classOf[ErrorMessage]),
- new ApiResponse(code = Forbidden.code, message = Forbidden.message, response = classOf[ErrorMessage]),
- new ApiResponse(code = InternalServerError.code, message = InternalServerError.message, response = classOf[ErrorMessage])
- ))
- def postCompany(implicit @ApiParam(hidden = true) user: User): Route = {
- (post & pathEndOrSingleSlash & entity(as[Company])) { company =>
- (validate(validateInn(company.inn), "company inn is incorrect") &
- validate(validateOgrn(company.ogrn), "company ogrn is incorrect") &
- validate(validateKpp(company.kpp), "company kpp is incorrect") &
- validate(validateEmail(company.email), "company email must contain @")) {
- complete(companyService.postCompany(user, company))
- }
- }
- }
- @ApiOperation(value = "put company", notes = "", nickname = "company-put", httpMethod = "PUT")
- @ApiImplicitParams(Array(
- new ApiImplicitParam(name = Id.name, value = Id.value, required = Id.required, dataType = Id.dataType, paramType = Id.paramType),
- new ApiImplicitParam(name = "body", required = true, dataType = "btp.cap.entity.Company", paramType = "body")
- ))
- @ApiResponses(Array(
- new ApiResponse(code = Success.code, message = Success.message, response = classOf[PutCompany]),
- new ApiResponse(code = Unauthorized.code, message = Unauthorized.message, response = classOf[ErrorMessage]),
- new ApiResponse(code = Forbidden.code, message = Forbidden.message, response = classOf[ErrorMessage]),
- new ApiResponse(code = NotFound.code, message = NotFound.message, response = classOf[ErrorMessage]),
- new ApiResponse(code = BadRequest.code, message = BadRequest.message, response = classOf[ErrorMessage]),
- new ApiResponse(code = UnprocessableEntity.code, message = UnprocessableEntity.message, response = classOf[ErrorMessage]),
- new ApiResponse(code = InternalServerError.code, message = InternalServerError.message, response = classOf[ErrorMessage])
- ))
- def putCompany(implicit @ApiParam(hidden = true) user: User): Route =
- (put & path(IntNumber) & entity(as[PutCompany])) {
- (id, company) => {
- (validate(validateInn(company.inn), "company inn is incorrect") &
- validate(validateOgrn(company.ogrn), "company ogrn is incorrect") &
- validate(validateKpp(company.kpp), "company kpp is incorrect") &
- validate(validateEmail(company.email), "company email must contain @")) {
- complete(companyService.putCompany(user, CompanyId(id), company))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement