class SellerSignupView(MethodView): def __init__(self, service, database): self.service = service self.database = database @validate_params( Param('username', JSON, str), Param('password', JSON, str, rules=[PasswordRule()]), Param('seller_attribute_type_id', JSON, str, rules=[SellerTypeRule()]), Param('name', JSON, str), Param('english_name', JSON, str), Param('contact_phone', JSON, str, rules=[PhoneRule()]), Param('service_center_number', JSON, str, rules=[PhoneRule()]), ) def post(self, *args): data = { 'username': args[0], 'password': args[1], 'seller_attribute_type_id': args[2], 'name': args[3], 'english_name': args[4], 'contact_phone': args[5], 'service_center_number': args[6], } try: connection = get_connection(self.database) self.service.seller_signup_service(connection, data) connection.commit() return jsonify({'message': 'success'}), 200 except Exception as e: connection.rollback() raise e finally: try: if connection: connection.close() except Exception: raise DatabaseCloseFail('database close fail')
class OrderDetailView(MethodView): def __init__(self, service, database): self.service = service self.database = database @signin_decorator @validate_params(Param('order_item_id', PATH, int)) def get(self, *args): data = {"permission": g.permission_type_id, "order_item_id": args[0]} """GET 메소드: 주문 상세 정보 조회 Args: args = ('order_item_id') Author: 김민서 Returns: { "message": "success", "result": { "order_detail_info": [ { "customer_phone": "12345667890", "order_detail_number": "oidt00001", "order_item_id": 1, "order_item_purchased_date": "2020-12-31 13:25:03", "status": "배송중" } ], "order_info": [ { "order_id": 1, "order_number": "20201225000000001", "order_purchased_date": "2020-12-31 13:25:03", "total_price": 18000.0 } ], "order_status_history": [ { "date": "2021-01-03 01:26:05", "status": "배송중" }, { "date": "2020-12-31 13:25:01", "status": "상품준비" } ], "product_info": [ { "brand_name": "나는셀러3", "discount_rate": 0.1, "option_information": "Black/Free", "price": "10000 원 (할인가 9000원)", "product_name": "성보의하루1", "product_number": "P0000000000000000001", "qauntity": 1 } ], "recipient_info": [ { "customer_name": "user1", "delivery_memo": "문 앞에 놓아주세요", "destination": "서울시 강남 위코드 아파 (123321)", "recipient_name": "둘리", "recipient_phone": "01022222222", "user_id": 102 } ], "updated_at_time": "2021-01-03 00:42:12" } } Raises: 400, {'message': 'key_error', 'errorMessage': 'key error'} : 잘못 입력된 키값 400, { "error_message:": "order_item_id이 유효하지 않습니다.", "message": { "order_item_id": [ "Value is required" ] } } : 필수 입력값 없음 400, {'message': 'does_not_exist_order_detail', 'errorMessage': '주문 상세 정보가 존재하지 않습니다.'} : 주문 상세 정보 없음 403, {'message': 'no_permission', 'errorMessage': '권한이 없습니다.'} : 권한 없음 400, {'message': 'unable_to_close_database', 'errorMessage': 'unable to close database'}: 커넥션 종료 실패 500, {'message': 'internal_server_error', 'errorMessage': 'internal server error'} : 알 수 없는 에러 History: 2021-01-01(김민서): 초기 생성 """ try: connection = get_connection(self.database) result = self.service.get_order_detail_service(connection, data) return jsonify({"message": "success", "result": result}), 200 except Exception as e: raise e finally: try: connection.close() except Exception: raise DatabaseCloseFail('database close fail') @signin_decorator @validate_params(Param('order_item_id', GET, str, rules=[NumberRule()]), Param("updated_at_time", GET, str, rules=[SecondDateTimeRule()]), Param("sender_phone", GET, str, required=False, rules=[PhoneRule()]), Param("recipient_phone", GET, str, required=False, rules=[PhoneRule()]), Param("address1", GET, str, required=False), Param("address2", GET, str, required=False)) def patch(self, *args): data = { "permission": g.permission_type_id, "order_item_id": args[0], "updated_at_time": args[1], "sender_phone": args[2], "recipient_phone": args[3], "address1": args[4], "address2": args[5] } """PATCH 메소드: 주문 상세 정보 수정 Args: args = ('order_item_id', 'updated_at_time', 'sender_phone', 'recipient_phone', 'address1', 'address2') Author: 김민서 Returns: {'message': 'success'} Raises: 400, {'message': 'key_error', 'errorMessage': 'key error'} : 잘못 입력된 키값 400, {'message': 'unable_to_close_database', 'errorMessage': 'unable to close database'}: 커넥션 종료 실패 403, {'message': 'no_permission', 'errorMessage': '권한이 없습니다.'} : 권한 없음 400, {'message': input_does_not_exist, 'errorMessage': '수정 정보가 없습니다.'} : 수정 정보 존재하지 않음 400, {'message': 'one_of_address_inputs_does_not_exist', 'errorMessage': '수정 주소 정보가 누락되었습니다.'} : 수정할 주소 정보 부족 400, {'message': 'unable_to_update', 'errorMessage': '업데이트가 불가합니다.'} : 수정 불가 400, {'message': 'denied_to_update', 'errorMessage': '업데이트가 실행되지 않았습니다.'} : 수정 실패 500, {'message': 'internal_server_error', 'errorMessage': 'internal server error'} : 알 수 없는 에러 History: 2021-01-01(김민서): 초기 생성 """ try: connection = get_connection(self.database) self.service.update_order_detail_service(connection, data) connection.commit() return jsonify({"message": "success"}), 200 except Exception as e: connection.rollback() raise e finally: try: connection.close() except Exception: raise DatabaseCloseFail('database close fail')
class DestinationView(MethodView): def __init__(self, service, database): self.service = service self.database = database @signin_decorator(False) def get(self): """GET 메소드: 해당 유저에 대한 배송지 정보 받아오기 유저에 관련된 모든 배송지 정보를 조회 및 반환한다. Args: g.account_id : 데코레이터에서 넘겨받은 유저 정보 g.permission_type_id: 권한정보 Author: 김기용 Returns: 200, {'message': 'success', 'result': 유저 배송지 정보들}: 배송지 조회 성공 Raises: 400, {'message': 'key error', 'errorMessage': '키 값이 일치하지 않습니다.'} 500, {'message': 'unable to close database', 'errorMessage': '커넥션 종료 실패'}: 500, {'message': 'internal server error', 'errorMessage': format(e)}) History: 2020-12-29(김기용): 초기 생성 2021-01-02(김기용): 데코레이터 수정 """ connection = None try: data = dict() if 'account_id' in g: data['account_id'] = g.account_id if 'permission_type_id' in g: data['permission_type_id'] = g.permission_type_id connection = get_connection(self.database) destination_detail = self.service.get_destination_detail_by_user_service(connection, data) return {'message': 'success', 'result': destination_detail} except Exception as e: raise e finally: try: if connection: connection.close() except Exception: raise DatabaseCloseFail('서버에서 알 수 없는 에러가 발생했습니다.') @signin_decorator(True) @validate_params( Param('recipient', JSON, str), Param('phone', JSON, str, rules=[PhoneRule()]), Param('address1', JSON, str), Param('address2', JSON, str), Param('post_number', JSON, str, rules=[PostalCodeRule()]), ) def post(self, *args): """POST 메소드: 배송지 추가 사용자가 입력한 배송지 정보를 받아 데이터베이스에 추가한다. 최대 배송지 생성 개수는 5개이다. Args: args: 'recipient' : 수신자 'phone' : 폰번호 'address1' : 메인주소 'address2' : 상세주소 'post_number': 우편번호 g.account_id : 데코레이터에서 넘겨받은 어카운트 아이디 g.permission_type_id: 데코레이터에서 넘겨받은 권한 아이디 Author: 김기용 Returns: 201, {'message': 'success'}: 배송지 생성 성공 Raises: 400, {'message': 'invalid_parameter', 'error_message': '[데이터]가(이) 유효하지 않습니다.'} 500, {'message': 'unable_to_close_database', 'errorMessage': '커넥션 종료 실패'} 500, {'message': 'internal_server_error', 'errorMessage': format(e)}) History: 2020-12-28(김기용): 초기 생성 2020-12-29(김기용): 데코레이터 추가 2020-12-30(김기용): 수정된 데코레이터반영: 데코레이터에서 permission_type 을 받음 2021-01-02(김기용): 수정된 데코레이터 반영: signin_decorator(True) """ connection = None try: data = { 'user_id': g.account_id, 'permission_type_id': g.permission_type_id, 'recipient': args[0], 'phone': args[1], 'address1': args[2], 'address2': args[3], 'post_number': args[4], } connection = get_connection(self.database) self.service.create_destination_service(connection, data) connection.commit() return {'message': 'success'} except Exception as e: connection.rollback() raise e finally: try: if connection: connection.close() except Exception: raise DatabaseCloseFail('서버에서 알 수 없는 에러가 발생했습니다.') @signin_decorator(True) @validate_params( Param('destination_id', JSON, str, rules=[NumberRule()]), Param('recipient', JSON, str), Param('phone', JSON, str, rules=[PhoneRule()]), Param('address1', JSON, str), Param('address2', JSON, str), Param('post_number', JSON, str, rules=[PostalCodeRule()]), Param('default_location', JSON, str, rules=[IsDeleteRule()]) ) def patch(self, *args): """ PATCH 메소드: 배송지 정보 수정 사용자가 입력한 배송지 정보를 받아 수정한다. Args: 'destination_id' : 배송지 아이디 'recipient' : 수신자 'phone' : 폰번호 'address1' : 메인주소 'address2' : 상세주소 'post_number' : 우편번호 'default_location': 기본 배송지 g.account_id : 데코레이터에서 넘겨받은 어카운트 아이디 g.permission_type_id: 데코레이터에서 넘겨받은 권한 아이디 Author: 김기용 Returns: {'message':'success'} Raises: 500, {'message': 'unable to close database', 'errorMessage': '커넥션 종료 실패'} 500, {'message': 'internal server error', 'errorMessage': format(e)}) """ connection = None try: data = dict() data['destination_id'] = args[0] data['recipient'] = args[1] data['phone'] = args[2] data['address1'] = args[3] data['address2'] = args[4] data['post_number'] = args[5] data['default_location'] = args[6] data['account_id'] = g.account_id data['permission_type_id'] = g.permission_type_id connection = get_connection(self.database) self.service.update_destination_info_service(connection, data) connection.commit() return {'message': 'success'} except Exception as e: connection.rollback() raise e finally: try: if connection: connection.close() except Exception: raise DatabaseCloseFail('서버에서 알 수 없는 에러가 발생했습니다') @signin_decorator(True) @validate_params( Param('destination_id', JSON, str, rules=[NumberRule()]) ) def delete(self, *args): """DELETE 메소드: 배송지 삭제 Args: 'destination_id': 배송지 아이디 g.account_id : 데코레이터에서 넘겨받은 account_id g.permission_type_id : 데코레이터에서 넘겨받은 권한 아이디 Author: 김기용 Returns: 200, {'message': 'success'}: 배송지 삭제 성공 Raises: 500, {'message': 'unable_to_close_database', 'errorMessage': '커넥션 종료 실패'} 500, {'message': 'internal_server_error', 'errorMessage': format(e)}): 서버 에러 History: 2020-12-29(김기용): 초기 생성 2020-12-30(김기용): 데코레이터 추가 """ connection = None try: data = dict() data['destination_id'] = args[0] data['account_id'] = g.account_id data['permission_type_id'] = g.permission_type_id connection = get_connection(self.database) self.service.delete_destination_service(connection, data) connection.commit() return {'message': 'success'} except Exception as e: connection.rollback() raise e finally: try: if connection: connection.close() except Exception: raise DatabaseCloseFail('서버에서 알 수 없는 에러가 발생했습니다')
class StoreOrderAddView(MethodView): """ Presentation Layer Attributes: database: app.config['DB']에 담겨있는 정보(데이터베이스 관련 정보) service : StoreOrderService 클래스 Author: 고수희 History: 2020-12-30(고수희): 초기 생성 """ def __init__(self, service, database): self.service = service self.database = database @signin_decorator(True) @validate_params( Param('cartId', JSON, int), Param('productId', JSON, int), Param('stockId', JSON, int), Param('quantity', JSON, int), Param('originalPrice', JSON, int), Param('sale', JSON, str, rules=[DecimalRule()]), Param('discountedPrice', JSON, int), Param('totalPrice', JSON, int), Param('soldOut', JSON, bool), Param('senderName', JSON, str), Param('senderPhone', JSON, str, rules=[PhoneRule()]), Param('senderEmail', JSON, str, rules=[EmailRule()]), Param('recipientName', JSON, str), Param('recipientPhone', JSON, str, rules=[PhoneRule()]), Param('address1', JSON, str), Param('address2', JSON, str), Param('postNumber', JSON, str, rules=[PostalCodeRule()]), Param('deliveryId', JSON, int), Param('deliveryMemo', JSON, str, required=False), ) def post(self, *args): """POST 메소드: 장바구니 상품 생성 Args: args = ( 'user_id', 'user_permission', 'cart_id', 'product_id', 'stock_id', 'quantity', 'original_price', 'sale', 'discounted_price', 'total_price', 'sold_out', 'sender_name', 'sender_phone', 'sender_email', 'recipient_name', 'recipient_phone', 'address1', 'address2', 'post_number', 'delivery_memo_type_id', 'delivery_content' ) Author: 고수희 Returns: 200, {'message': 'success'} : 결제 성공 Raises: 400, {'message': 'key error', 'errorMessage': 'key_error'} : 잘못 입력된 키값 400, {'message': 'unable to close database', 'errorMessage': 'unable_to_close_database'} : 커넥션 종료 실패 403, {'message': 'customer permission denied', 'errorMessage': 'customer_permission_denied'} : 사용자 권한이 아님 500, {'message': 'internal server error', 'errorMessage': format(e)}) : 서버 에러 History: 2020-12-30(고수희): 초기 생성 """ data = { 'user_id': g.account_id, 'user_permission': g.permission_type_id, 'cart_id': args[0], 'product_id': args[1], 'stock_id': args[2], 'quantity': args[3], 'original_price': args[4], 'sale': args[5], 'discounted_price': args[6], 'total_price': args[7], 'sold_out': args[8], 'sender_name': args[9], 'sender_phone': args[10], 'sender_email': args[11], 'recipient_name': args[12], 'recipient_phone': args[13], 'address1': args[14], 'address2': args[15], 'post_number': args[16], 'delivery_memo_type_id': args[17], 'delivery_content': args[18], } try: connection = get_connection(self.database) order_id = self.service.post_order_service(connection, data) connection.commit() return { 'message': 'success', 'result': { "order_id": order_id } }, 201 except Exception as e: connection.rollback() raise e finally: try: if connection: connection.close() except Exception: raise DatabaseCloseFail('database close fail')
class SignUpView(MethodView): """ Presentation Layer Attributes: user_service : UserService 클래스 database : app.config['DB']에 담겨있는 정보(데이터베이스 관련 정보) Author: 김민구 History: 2020-12-28(김민구): 초기 생성 / bcrypt 까지 완료 2020-12-29(김민구): 각 Param에 rules 추가, 에러 구문 수정 2020-12-31(김민구): 모든 service를 담고 있는 services 클래스로 유연하게 처리 / 에러 문구 변경 2021-01-02(김민구): 데이터 조작 에러 추가 """ def __init__(self, services, database): self.user_service = services.user_service self.database = database @validate_params( Param('username', JSON, str, rules=[UsernameRule()]), Param('password', JSON, str, rules=[PasswordRule()]), Param('phone', JSON, str, rules=[PhoneRule()]), Param('email', JSON, str, rules=[EmailRule()]) ) def post(self, *args): """POST 메소드: 유저생성 Args: args = ('username', 'password', 'phone', 'email') Author: 김민구 Returns: 200, {'message': 'success'} : 유저 생성 성공 Raises: 400, {'message': 'invalid_parameter', 'errorMessage': '[데이터]가(이) 유효하지 않습니다.'} : 잘못된 요청값 400, {'message': 'key_error', 'error_message': format(e)} : 잘못 입력된 키값 403, {'message': 'user_already_exist', 'error_message': '이미 사용중인 [데이터] 입니다.'} : 중복 유저 존재 500, { 'message': 'database_connection_fail', 'error_message': '서버에 알 수 없는 에러가 발생했습니다.' } : 커넥션 종료 실패 500, {'message': 'database_error', 'error_message': '서버에 알 수 없는 에러가 발생했습니다.'} : 데이터베이스 에러 500, {'message': 'data_manipulation_fail', 'error_message': '유저 등록을 실패하였습니다.'} : 데이터 조작 에러 500, {'message': 'internal_server_error', 'error_message': format(e)}) : 서버 에러 History: 2020-12-28(김민구): 초기 생성 2020-12-31(김민구): 에러 문구 변경 2021-01-02(김민구): 데이터 조작 에러 추가 """ connection = None try: data = { 'username': args[0], 'password': args[1], 'phone': args[2], 'email': args[3] } connection = get_connection(self.database) self.user_service.sign_up_logic(data, connection) connection.commit() return jsonify({'message': 'success'}), 200 except Exception as e: traceback.print_exc() connection.rollback() raise e finally: try: if connection is not None: connection.close() except Exception: raise DatabaseCloseFail('서버에 알 수 없는 에러가 발생했습니다.')
class SellerSearchView(MethodView): def __init__(self, service, database): self.service = service self.database = database @validate_params(Param('page', GET, int, required=True, rules=[PageRule()]), Param('page_view', GET, int, required=True), Param('account_id', GET, int, required=False, rules=[PositiveInteger()]), Param('username', GET, str, required=False), Param('seller_english_name', GET, str, required=False), Param('seller_name', GET, str, required=False), Param('contact_name', GET, str, required=False), Param('contact_phone', GET, str, required=False, rules=[PhoneRule()]), Param('contact_email', GET, str, required=False, rules=[EmailRule()]), Param('seller_attribute_type_name', GET, str, required=False), Param('seller_status_type_name', GET, str, required=False), Param('updated_at', JSON, str, required=False), Param('start_date', JSON, str, required=False), Param('end_date', JSON, str, required=False)) def get(self, *args): try: data = { 'account_id': args[2], 'username': args[3], 'seller_english_name': args[4], 'seller_name': args[5], 'contact_name': args[6], 'contact_phone': args[7], 'contact_email': args[8], 'seller_attribute_type_name': args[9], 'seller_status_type_name': args[10], 'updated_at': args[11], 'start_date': args[12], 'end_date': args[13] } page = request.args.get('page') page_view = request.args.get('page_view') connection = get_connection(self.database) result = self.service.seller_search_service( connection, data, page, page_view) return jsonify({'message': 'success', 'seller_list': result}), 200 except Exception as e: raise e finally: try: if connection: connection.close() except Exception: raise DatabaseCloseFail( 'database close fail in seller_list_view')