コード例 #1
0
    def get_sub_category(*args):
        """ 상품 분류별 sub 카테고리 목록 표출 엔드포인트
        Args:
            *args:
                main_category_id(int): 1차 카테고리 인덱스 번호
        """
        connection = None

        #쿼리 스트링에 값이 없으면 에러 반환
        if args[0] is None:
            return jsonify({'message': 'MAIN_CATEGORY_ID_ERROR'}), 400

        try:
            connection = connect_db()

            if connection:
                filter_data = {'main_category_id': args[0]}
                product_service = ProductService()
                sub_categories = product_service.product_sub_category(
                    filter_data, connection)

                return jsonify({'data': sub_categories}), 200
            else:
                return jsonify({'message': 'NO_DATABASE_CONNECTION'}), 400

        except Exception as e:
            return jsonify({'message': f'{e}'}), 500

        finally:
            try:
                connection.close()
            except Exception as e:
                return jsonify({'message': f'{e}'}), 500
コード例 #2
0
    def get_product_list(*args):
        connection = None
        """상품 리스트 엔드포인트
        상품 관리 페이지에서 필터링된 상품 리스트를 표출
        쿼리 파라미터로 필터링에 사용할 파라미터 값을 받음     
        
        Return:
            200: 상품 리스트
            403: NO_AUTHORIZATION
            500: NO_DATABASE_CONNECTION, DB_CURSOR_ERROR
                 NO_DATABASE_CONNECTION
        History:
            2020-11-28 : 초기 생성
            2020-11-19 : pagination 수정
                 
        수정할 사항
        @login_validator로 g.account_info 받을 예정
            g.account_info ={
                'account_id' :  ,
                'account_type_id' :  ,
                'seller_id' : id or None
            }
        """

        #유효성 검사 완료한 쿼리 값 저장
        filter_data = {
            'started_date': args[0],
            'ended_date': args[1],
            'seller_name': args[2],
            'product_name': args[3],
            'product_number': args[4],
            'product_code': args[5],
            'seller_subcategory_id': args[6],
            'is_selling': args[7],
            'is_visible': args[8],
            'is_discount': args[9],
            'limit': args[10],
            'page': args[11],
            'account_type_id': g.token_info['account_type_id']
        }

        try:
            connection = connect_db()

            if connection:
                product_service = ProductService()
                products = product_service.get_product_list(
                    filter_data, connection)
                return jsonify(products), 200
            else:
                return jsonify({'message': 'NO_DATABASE_CONNECTION'}), 500

        except Exception as e:
            return jsonify({'message': f'{e}'}), 400

        finally:
            try:
                connection.close()
            except Exception as e:
                return jsonify({'message': f'{e}'}), 500
コード例 #3
0
class ProductController:

    service = ProductService()  # 전역변수도 될까???? (O) 가능. 오류없음.

    def register(self, product):
        message = self.service.register(product)
        message_display(message)

    def getAllSchedule(self):
        products = self.service.getAllSchedule()
        list_display(products)  # message 출력이 아니라 products의 product를 출력하는 메소드.

    def update(self, id, price):
        if id == "" or price == "":  # 입력이 되지 않았을 경우를 체크해야 한다.
            message_display("제품번호와 제품가격을 모두 입력하여 주세요.")
        message = self.service.update(id, price)
        message_display(message)

    def remove(self, id):
        if id == "":
            message_display("제품번호를 입력하세요.")
        message = self.service.remove(id)
        message_display(message)

    def allRemove(self, check):
        message = self.service.allRemove(check)
        message_display(message)

    def file_read(self):
        self.service.file_read()

    def file_write(self):
        self.service.file_write()
コード例 #4
0
    def get_option_list(*args):
        connection = None
        try:
            connection = connect_db()
            if connection:
                product_service = ProductService()
                options = product_service.get_options(connection)
                return options
            else:
                return jsonify({'message': 'NO_DATABASE_CONNECTION'}), 500

        except Exception as e:
            return jsonify({'message': f'{e}'}), 500
        finally:
            try:
                connection.close()

            except Exception as e:
                return jsonify({'message': f'{e}'}), 500
コード例 #5
0
    def product_list_excel(*args):
        connection = None

        filter_data = {
            'started_date': args[0],
            'ended_date': args[1],
            'seller_name': args[2],
            'product_name': args[3],
            'product_number': args[4],
            'product_code': args[5],
            'seller_subcategory_id': args[6],
            'is_selling': args[7],
            'is_visible': args[8],
            'is_discount': args[9],
            'account_type_id': g.token_info['account_type_id'],
            'account_id': g.token_info['account_id']
        }

        try:
            connection = connect_db()
            if connection:
                product_service = ProductService()

                product_service.product_excel(filter_data, connection)

                return jsonify({'message': 'SUCCESS'}), 201
            else:
                return jsonify({'message': 'NO_DATABASE_CONNECTION'}), 500

        except Exception as e:
            return jsonify({'message': f'{e}'}), 400

        finally:
            try:
                connection.close()
            except Exception as e:
                return jsonify({'message': f'{e}'}), 500
コード例 #6
0
    def get_main_category(*args):
        """ 상품 분류별 main 카테고리 표출 엔드포인트
        - master이면 seller검색
        - seller이면 validator 본인 id

        Return:
            200: 셀러가 속한 상품 분류에 따른 1차 카테고리 이름과 id
                 {  "main_category_id": 8,
                    "main_category_name": "주얼리"}
            400: 데이터베이스 연결 에러
            500: server error"""
        connection = None
        # 마스터인데 셀러이름 검색 안한 경우(커넥션 열기전에 처리해줌)
        if g.token_info['account_type_id'] == 1 and args[0] is None:
            return jsonify({'message': 'SELLER_CATEGORY_SEARCHING_ERROR'}), 400

        try:
            connection = connect_db()
            if connection:

                filter_data = {
                    'account_type_id': g.token_info['account_type_id'],
                    'seller_name': args[0]
                }

                product_service = ProductService()
                main_categories_data = product_service.product_main_category(
                    filter_data, connection)
        except Exception as e:
            return jsonify({'message': f'{e}'}), 400
        else:
            return jsonify(main_categories_data), 200
        finally:
            try:
                connection.close()
            except Exception as e:
                return jsonify({'message': f'{e}'}), 500
コード例 #7
0
ファイル: app.py プロジェクト: yenilee/brandi-admin-clone
def create_app(test_config=None):
    app = Flask(__name__)
    app.debug = True
    # JSON 설정
    app.config['JSON_SORT_KEYS'] = False
    app.json_encoder = CustomJSONEncoder
    # CORS 설정
    CORS(app, resources={r'*': {'origins': '*'}})
    # Config 설정
    app.config.from_pyfile('config.py')
    # DAO 생성
    user_dao = UserDao()
    product_dao = ProductDao()
    # Service 생성
    user_service = UserService(user_dao, app.config)
    product_service = ProductService(product_dao, app.config)
    # Controller 생성
    create_user_endpoints(app, user_service)
    create_product_endpoints(app, product_service)

    return app
コード例 #8
0
    def create_product(*args):
        connection = None

        # min_order, max_order 예외처리
        if args[16] > 20 or args[17] > 20:
            return jsonify({'message': 'ORDER_VALUE_ERROR'}), 400

        filter_data = {
            'editor_id': g.token_info['account_id'],
            'is_selling': args[0],
            'is_visible': args[1],
            'sub_category_id': args[2],
            'product_name': args[3],
            'is_information_notice': args[4],
            'manufacturer': args[5],
            'manufacture_date': args[6],
            'made_in': args[7],
            'short_description': args[8],
            'is_inventory_management': args[9],
            'inventory': args[10],
            'price': args[11],
            'discount_rate': args[12],
            'is_discount_period': args[13],
            'discount_start_datetime': args[14],
            'discount_end_datetime': args[15],
            'min_order': args[16],
            'max_order': args[17]
        }
        if args[18]:
            filter_data['seller_id'] = args[18]
        else:
            filter_data['seller_id'] = g.token_info['seller_id']

        print(filter_data['seller_id'])

        try:
            connection = connect_db()

            if connection:

                # option_list = '[{"name":"bb","age":29},{"name":"hh","age":20}]'
                options = request.form.get('option_list')
                option_list = json.loads(options)

                #image 저장을 위한 S3 connection instance 생성
                """
                images : File Request(List)
                [
                    { 'product_image_<int>' : <FileStorage: {filename} ({content_type})>}
                ]
                """
                images = request.files
                image_bucket_dir = datetime.datetime.now().strftime('%Y-%m-%d')

                desc_image = request.files.get('desc_image')
                desc_image_url = Image_uploader.upload_desc_images(
                    desc_image, image_bucket_dir)

                filter_data['desc_img_url'] = desc_image_url

                product_service = ProductService()
                create_info = product_service.create_product(
                    filter_data, option_list, connection)

                product_id = create_info['product_id']
                editor_id = filter_data['editor_id']
                insert_count = create_info['create_count']

                #상품 이미지 URL화, S3에 올리기
                product_images = Image_uploader.upload_product_images(
                    images, image_bucket_dir)

                #상품 이미지를 DB에 Insert하는 함수 실행
                product_service.upload_product_image(product_images,
                                                     product_id, editor_id,
                                                     connection)

                connection.commit()
                return jsonify(
                    {'message': f'{insert_count}products are created'}), 201
            else:
                return jsonify({'message': 'NO_DATABASE_CONNECTION'}), 500

        except KeyError:
            connection.rollback()
            return jsonify({'message': 'KEY_ERROR'}), 400

        except Exception as e:
            connection.rollback()
            # raise e
            return jsonify({'message': f'{e}'}), 500

        finally:
            try:
                connection.close()
            except Exception as e:
                return jsonify({'message': f'{e}'}), 500
コード例 #9
0
from slackbot.bot import default_reply
from service.product_service import ProductService

product_service = ProductService()


@default_reply()
def mentaion_func(message):
    product_service.insert(message.body['text'])
    message.reply(message.body['text'] + "をショッピングリストに追加しました")