示例#1
0
class SellerPasswordView(MethodView):
    """ Presentation Layer

        Attributes:
            database: app.config['DB']에 담겨있는 정보(데이터베이스 관련 정보)
            service : SellerPasswordService 클래스

        Author:
            이영주

        History:
            2021-01-04(이영주): 초기 생성
    """
    def __init__(self, service, database):
        self.service = service
        self.database = database

    # @signin_decorator
    @validate_params(
        Param('account_id', JSON, str, required=False, rules=[DefaultRule()]),
        Param('password', JSON, str, required=False, rules=[DefaultRule()]))
    def patch(self, *args):
        """PATCH 메소드:
                셀러 비밀번호 수정
        Author:
            이영주

        Returns:
            200, {'message': 'success'}                                                             : 셀러 정보변경

        # Raises:
        #     400, {'message': 'key error', 'errorMessage': 'key_error'}                              : 잘못 입력된 키값
        #     400, {'message': 'unable to update', 'errorMessage': 'unable_to_update'}                : 셀러 정보 수정 실패
        #     400, {'message': 'unable to close database', 'errorMessage': 'unable_to_close_database'}: 커넥션 종료 실패
        #     500, {'message': 'internal server error', 'errorMessage': format(e)})                   : 서버 에러

        History:
            2021-01-04(이영주): 초기 생성
        """
        try:
            data = {'account_id': args[0], 'password': args[1]}
            connection = get_connection(self.database)
            self.service.patch_seller_password(connection, data)
            return jsonify({
                'message': 'success',
                'result': 'PasswordChange'
            }), 200

        except Exception as e:
            connection.rollback()
            raise e

        finally:
            try:
                if connection:
                    connection.close()
            except Exception:
                raise DatabaseCloseFail('database close fail')
class ProductManageSearchView(MethodView):
    """ Presentation Layer

        Attributes:
            service  : MainCategoryListService 클래스
            database : app.config['DB']에 담겨있는 정보(데이터베이스 관련 정보)

        Author: 심원두

        History:
            2020-12-31(심원두): 초기 작성
            2021-01-03(심원두): 상품 리스트 검색 기능 구현
    """
    def __init__(self, service, database):
        self.service = service
        self.database = database

    @signin_decorator()
    @validate_params(
        Param('lookup_start_date',
              GET,
              str,
              required=False,
              rules=[DateRule(), NotEmpty()]),
        Param('lookup_end_date',
              GET,
              str,
              required=False,
              rules=[DateRule(), NotEmpty()]),
        Param('seller_name',
              GET,
              str,
              required=False,
              rules=[DefaultRule(), NotEmpty(),
                     MaxLength(20)]),
        Param('product_name',
              GET,
              str,
              required=False,
              rules=[DefaultRule(), NotEmpty(),
                     MaxLength(100)]),
        Param('product_id',
              GET,
              str,
              required=False,
              rules=[NumberRule(), NotEmpty()]),
        Param('product_code',
              GET,
              str,
              required=False,
              rules=[DefaultRule(), NotEmpty(),
                     MaxLength(20)]),
        Param('is_sale', GET, int, required=False, rules=[Enum(1, 2)]),
        Param('is_display', GET, int, required=False, rules=[Enum(1, 2)]),
        Param('is_discount', GET, int, required=False, rules=[Enum(1, 2)]),
        Param('page_number', GET, int, required=True, rules=[PageRule()]),
        Param('limit', GET, int, required=True, rules=[Enum(10, 20, 50)]))
    def get(self, *args):
        """GET 메소드: 특정 조건에 해당하는 상품 리스트를 조회한다.
            
            Args:
                'lookup_start_date'       : 조회 시작 기간
                'lookup_end_date'         : 조회 종료 기간
                'seller_name'             : 셀러명
                'product_name'            : 상품명
                'product_id'              : 상품 아이디
                'product_code'            : 상품 코드
                'seller_attribute_type_id : 셀러 속성
                'is_sale'                 : 할인 여부
                'is_display'              : 진열 여부
                'is_discount'             : 할인 여부
                'page_number'             : 페이지 번호
                'limit'                   : 한 화면에 보여줄 상품의 갯수
                
            Author: 심원두
            
            Returns:
                return {"message": "success", "result": result}
            
            Raises:
                400, {'message': 'key error',
                      'errorMessage': 'key_error' + format(e)} : 잘못 입력된 키값
                      
                400, {'message': 'both date field required',
                      'errorMessage': 'both_date_field_required'}: 필수 값 유효성 체크 에러
                      
                400, {'message': 'start date is greater than end date',
                      'errorMessage': 'start_date_is_greater_than_end_date'}: 날짜 비교 유효성 체크 에러
                
                400, {'message': 'invalid seller attribute type',
                      'errorMessage': 'invalid_seller_attribute_type'}: 셀러 타입 유효성 체크 에러
            
            History:
                2020-12-31(심원두): 초기생성
                2021-01-03(심원두): 상품 리스트 검색 기능 구현, Login Decorator 구현 예정
        """

        try:
            search_condition = {
                'seller_id':
                g.account_id if g.permission_type_id == 2 else None,
                'lookup_start_date':
                request.args.get('lookup_start_date', None),
                'lookup_end_date':
                request.args.get('lookup_end_date', None),
                'seller_name':
                request.args.get('seller_name', None),
                'product_name':
                request.args.get('product_name', None),
                'product_id':
                request.args.get('product_id', None),
                'product_code':
                request.args.get('product_code', None),
                'seller_attribute_type_ids':
                json.loads(request.args.get('seller_attribute_type_id'))
                if request.args.get('seller_attribute_type_id') else None,
                'is_sale':
                request.args.get('is_sale', None),
                'is_display':
                request.args.get('is_display', None),
                'is_discount':
                request.args.get('is_discount', None),
                'page_number':
                request.args.get('page_number'),
                'limit':
                request.args.get('limit')
            }

            search_condition_back_to_front = {
                'lookup_start_date':
                search_condition['lookup_start_date'],
                'lookup_end_date':
                search_condition['lookup_end_date'],
                'seller_name':
                search_condition['seller_name'],
                'product_name':
                search_condition['product_name'],
                'product_id':
                search_condition['product_id'],
                'product_code':
                search_condition['product_code'],
                'seller_attribute_type':
                search_condition['seller_attribute_type_ids'],
                'is_sale':
                0 if search_condition['is_sale'] is None else int(
                    search_condition['is_sale']),
                'is_display':
                0 if search_condition['is_display'] is None else int(
                    search_condition['is_display']),
                'is_discount':
                0 if search_condition['is_discount'] is None else int(
                    search_condition['is_discount']),
                'page_number':
                int(search_condition['page_number']),
                'limit':
                int(search_condition['limit'])
            }

            connection = get_connection(self.database)
            result = self.service.search_product_service(
                connection, search_condition)
            result['search_condition'] = search_condition_back_to_front

            return jsonify({'message': 'success', 'result': result})

        except KeyError as e:
            traceback.print_exc()
            raise e

        except Exception as e:
            traceback.print_exc()
            raise e

        finally:
            try:
                if connection:
                    connection.close()
            except Exception:
                raise DatabaseCloseFail('database close fail')
示例#3
0
class SellerStatusView(MethodView):
    """ Presentation Layer
    Attributes:
        database: app.config['DB']에 담겨있는 정보(데이터베이스 관련 정보)
        service : SellerInfoService 클래스

    Author:
        이영주

    History:
        2021-01-03(이영주): 초기 생성
    """
    def __init__(self, service, database):
        self.service = service
        self.database = database

    @validate_params(
        Param('account_id', JSON, str, required=True, rules=[DefaultRule()]),
        Param('seller_status_type_id',
              JSON,
              str,
              required=True,
              rules=[DefaultRule()]),
        Param('seller_id', JSON, str, required=True, rules=[DefaultRule()]),
        Param('updater_id', JSON, str, required=True, rules=[DefaultRule()]))
    def patch(self, *args):
        """PATCH 메소드:
                셀러 상태 정보 수정
        Args:

        Author:
            이영주

        Returns:
            200, {'message': 'success'}                                                             : 셀러 정보변경

        Raises:
            400, {'message': 'key error', 'errorMessage': 'key_error'}                              : 잘못 입력된 키값
            400, {'message': 'unable to update', 'errorMessage': 'unable_to_update'}                : 셀러 정보 수정 실패
            400, {'message': 'unable to close database', 'errorMessage': 'unable_to_close_database'}: 커넥션 종료 실패
            500, {'message': 'internal server error', 'errorMessage': format(e)})                   : 서버 에러

        History:
            2021-01-03(이영주): 초기 생성
        """
        try:
            data = {
                'account_id': args[0],
                'seller_status_type_id': args[1],
                'seller_id': args[2],
                'updater_id': args[3]
            }
            connection = get_connection(self.database)
            self.service.patch_seller_status(connection, data)
            self.service.patch_seller_history(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('database close fail')
示例#4
0
class SellerInfoView(MethodView):
    """ Presentation Layer

        Attributes:
            database: app.config['DB']에 담겨있는 정보(데이터베이스 관련 정보)
            service : SellerInfoService 클래스

        Author:
            이영주

        History:
            2020-12-28(이영주): 초기 생성
    """
    def __init__(self, service, database):
        self.service = service
        self.database = database

    @validate_params(
        Param('account_id', PATH, str, required=True, rules=[NumberRule()]), )
    def get(self, *args):
        """ GET 메소드: 셀러 상세정보 조회

            Args:
                account_id

            Author:
                이영주

            Returns:
                200, {'message': 'success', 'result': result}                                           : 상세정보 조회 성공

            Raises:
                400, {'message': 'key error', 'errorMessage': 'key_error'}                              : 잘못 입력된 키값
                400, {'message': 'seller does not exist error', 'errorMessage': 'seller_does_not_exist'}: 셀러 정보 조회 실패
                400, {'message': 'unable to close database', 'errorMessage': 'unable_to_close_database'}: 커넥션 종료 실패
                500, {'message': 'internal server error', 'errorMessage': format(e)})                   : 서버 에러

            History:
                2020-12-28(이영주): 초기 생성
        """

        # @ 데코레이터
        data = {
            'account_id': args[0],
        }
        try:
            connection = get_connection(self.database)
            result = self.service.get_seller_info(connection, data)
            return jsonify({'message': 'success', 'result': result}), 200

        except Exception as e:
            raise e

        finally:
            try:
                if connection:
                    connection.close()
            except Exception:
                raise DatabaseCloseFail('database close fail')

    @validate_params(
        # required True
        Param('profile_image_url',
              FORM,
              str,
              required=True,
              rules=[DefaultRule()]),
        Param('seller_title', FORM, str, required=True, rules=[DefaultRule()]),
        Param('contact_name', FORM, str, required=True, rules=[DefaultRule()]),
        Param('contact_phone', FORM, str, required=True,
              rules=[DefaultRule()]),
        Param('contact_email', FORM, str, required=True,
              rules=[DefaultRule()]),
        Param('service_center_number',
              FORM,
              str,
              required=True,
              rules=[DefaultRule()]),
        Param('post_number', FORM, str, required=True, rules=[DefaultRule()]),
        Param('address1', FORM, str, required=True, rules=[DefaultRule()]),
        Param('address2', FORM, str, required=True, rules=[DefaultRule()]),
        Param('operation_start_time', FORM, str, required=True),
        Param('operation_end_time', FORM, str, required=True),
        Param('shipping_information',
              FORM,
              str,
              required=True,
              rules=[DefaultRule()]),
        Param('exchange_information',
              FORM,
              str,
              required=True,
              rules=[DefaultRule()]),
        # required False
        Param('background_image_url',
              FORM,
              str,
              required=False,
              rules=[DefaultRule()]),
        Param('seller_discription',
              FORM,
              str,
              required=False,
              rules=[DefaultRule()]),
        Param('is_weekend', FORM, str, required=False, rules=[DefaultRule()]),
        Param('weekend_operation_start_time',
              FORM,
              str,
              required=False,
              rules=[DefaultRule()]),
        Param('weekend_operation_end_time',
              FORM,
              str,
              required=False,
              rules=[DefaultRule()]),
        # master
        Param('name', FORM, str, required=False, rules=[DefaultRule()]),
        Param('english_name', FORM, str, required=False,
              rules=[DefaultRule()]),
        # permission_type
        Param('account_id', FORM, str, required=True, rules=[DefaultRule()]),
        Param('permission_types',
              FORM,
              str,
              required=True,
              rules=[DefaultRule()]),
        # histories
        Param('seller_status_type_id',
              FORM,
              str,
              required=True,
              rules=[DefaultRule()]),
        Param('seller_id', FORM, str, required=True, rules=[DefaultRule()]),
        Param('updater_id', FORM, str, required=True, rules=[DefaultRule()]))
    # password 변경
    def patch(self, *args):
        """ PATCH 메소드: 셀러 정보 수정

            Author: 이영주

            Returns:
                200, {'message': 'success', 'result': result}                                           : 셀러 정보변경

            Raises:
                400, {'message': 'key error', 'errorMessage': 'key_error'}                              : 잘못 입력된 키값
                400, {'message': 'unable to update', 'errorMessage': 'unable_to_update'}                : 셀러 정보 수정 실패
                400, {'message': 'unable to close database', 'errorMessage': 'unable_to_close_database'}: 커넥션 종료 실패
                500, {'message': 'internal server error', 'errorMessage': format(e)})                   : 서버 에러

            History:
                2020-12-29(이영주): 초기 생성
        """
        try:
            add_contact = json.loads(request.form.get("add_contact", "1"))
            data = {
                'profile_image_url':
                request.form.get('profile_image_url'),
                'background_image_url':
                request.form.get('background_image_url'),
                'seller_title':
                request.form.get('seller_title'),
                'seller_discription':
                request.form.get('seller_discription'),
                'contact_name':
                request.form.get('contact_name'),
                'contact_phone':
                request.form.get('contact_phone'),
                'contact_email':
                request.form.get('contact_email'),
                'post_number':
                request.form.get('post_number'),
                'service_center_number':
                request.form.get('service_center_number'),
                'address1':
                request.form.get('address1'),
                'address2':
                request.form.get('address2'),
                'operation_start_time':
                request.form.get('operation_start_time'),
                'operation_end_time':
                request.form.get('operation_end_time'),
                'is_weekend':
                request.form.get('is_weekend'),
                'weekend_operation_start_time':
                request.form.get('weekend_operation_start_time'),
                'weekend_operation_end_time':
                request.form.get('weekend_operation_end_time'),
                'shipping_information':
                request.form.get('shipping_information'),
                'exchange_information':
                request.form.get('exchange_information'),
                'name':
                request.form.get('name'),
                'english_name':
                request.form.get('english_name'),
                'account_id':
                request.form.get('account_id'),
                'permission_types':
                request.form.get('permission_types'),
                'seller_status_type_id':
                request.form.get('seller_status_type_id'),
                'seller_id':
                request.form.get('account_id'),
                'updater_id':
                request.form.get('permission_types'),
                'add_contact':
                add_contact
            }
            connection = get_connection(self.database)

            # master - update seller table
            self.service.patch_master_info(connection, data)

            # update sellers table
            self.service.patch_seller_info(connection, data)

            # update additional_contacts table
            self.service.patch_add_contact(connection, data)

            # update seller_histories
            self.service.patch_seller_history(connection, data)

            connection.commit()
            return jsonify({'message': 'success', 'result': data}), 200

        except Exception as e:
            connection.rollback()
            raise e

        finally:
            try:
                if connection:
                    connection.close()
            except Exception:
                raise DatabaseCloseFail('database close fail')