def get(identifier=None): """Return the complete business info.""" if not identifier: try: con = DB.connection con.begin() corp_type = request.args.get('legal_type', None).upper() corp_num = Business.get_next_corp_num(corp_type, con) con.commit() except Exception as err: # pylint: disable=broad-except; want to catch all errors current_app.logger.error(err.with_traceback(None)) if con: con.rollback() if corp_num: return jsonify({'corpNum': corp_num}), 200 return jsonify({'message': 'Identifier required'}), 404 try: business = Business.find_by_identifier(identifier) if not business: return jsonify({'message': f'{identifier} not found'}), 404 return jsonify(business.as_dict()) except GenericException as err: # pylint: disable=duplicate-code return jsonify( {'message': err.error}), err.status_code except Exception as err: # pylint: disable=broad-except; want to catch all errors # general catch-all exception current_app.logger.error(err.with_traceback(None)) return jsonify( {'message': 'Error when trying to retrieve business record from COLIN'}), 500
def post(legal_type: str): """Create and return a new corp number for the given legal type.""" if legal_type not in [x.value for x in Business.LearBusinessTypes]: return jsonify({'message': 'Must provide a valid legal type.' }), HTTPStatus.BAD_REQUEST try: con = DB.connection con.begin() corp_num = Business.get_next_corp_num(con=con, corp_type=legal_type) con.commit() except Exception as err: # pylint: disable=broad-except; want to catch all errors current_app.logger.error(err.with_traceback(None)) if con: con.rollback() if corp_num: return jsonify({'corpNum': corp_num}), HTTPStatus.OK return jsonify({'message': 'Failed to get new corp number' }), HTTPStatus.INTERNAL_SERVER_ERROR