def post(self, valid: ValidRequest):
        """주문하기 기능

        Author:
            백승찬

        Args:
            {
                "orderer_name"         : 주문자 이름
                "orderer_phone_number" : 주문자 번호
                "orderer_email         : 주문자 이메일
                "address_id"           : 주소 아이디
                "shipment_memo_id"     : 배송 메모 아이디
                "message"              : 직접입력 시 입력하는 message
                "total_price"          : 결제 총액
            }

        Raises:
            CartIdTypeError: 리스트로 들어온 다수의 cart_id가 int 타입이 아니면 에러처리
            e: 예상하지 못한 에러처리

        Returns:
            { "data": {
                "order_id": 주문번호
                }
            }
        """
        order_service = OrderService()
        connection = None

        filters = valid.get_json()
        filters["account_id"] = g.account_info["account_id"]
        filters["carts"] = request.json["carts"]

        for filter in filters["carts"]:
            if type(filter['cart_id']) != int:
                raise CartIdTypeError(CART_ID_TYPE_ERROR, 400)

        try:
            connection = connect_db()

            result = order_service.post_order(connection, filters)

            connection.commit()

            return jsonify({"data": result})

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

        finally:
            if connection is not None:
                connection.close()
Beispiel #2
0
    def get(*args, order_id):
        """결제 완료 페이지 정보 가져오기

        Author:
            백승찬

        Args:
            (PATH): order_id를 path parameter로 받음 

        Raises:
            OrderIdTypeError: order_id 가 int 타입이 아닐때
            e: 예상하지 못한 에러처리

        Returns:
            200 : {
                "data": {
                    "id": 주문번호
                    "total_price": 총 결제 금액
                    }
                }
        """

        order_service = OrderService()
        connection = None

        filters = {
            "order_id": int(order_id),
            "account_id": g.account_info["account_id"]
        }

        if type(filters["order_id"]) != int:
            raise OrderIdTypeError(ORDER_ID_TYPE_ERROR, 400)

        try:
            connection = connect_db()

            result = order_service.get_order_complete(connection, filters)

            connection.commit()

            return jsonify({"data": result})

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

        finally:
            if connection is not None:
                connection.close()
Beispiel #3
0
def create_app(test_config=None):
    app = Flask(__name__)
    app.json_encoder = CustomEncoder
    CORS(app, resources={r'*': {'origins': '*'}})
    if test_config is None:
        app.config.from_pyfile('config.py')
    else:
        app.config.update(test_config)

    #persistence layer

    account_dao = AccountDao()
    seller_dao = SellerDao()
    order_dao = OrderDao()
    product_dao = ProductDao()

    #business layer
    account_service = AccountService(account_dao, config)
    seller_service = SellerService(seller_dao, config)
    order_service = OrderService(order_dao)
    product_service = ProductService(product_dao)

    #presentation layer(엔드포인트 생성)
    app.register_blueprint(create_account_endpoints(account_service))
    app.register_blueprint(create_seller_endpoints(seller_service))
    app.register_blueprint(create_order_endpoints(order_service))

    app.register_blueprint(create_product_endpoints(product_service))

    return app
Beispiel #4
0
def create_app(test_config=None):
    app = Flask(__name__)
    app.config['JSON_AS_ASCII'] = False

    CORS(app)

    if test_config is None:
        app.config.from_pyfile("config.py")
    else:
        app.config.update(test_config)

    product_dao = ProductDao()
    seller_dao = SellerDao()
    order_dao = OrderDao()
    user_dao = UserDao()
    coupon_dao = CouponDao()
    event_dao = EventDao()

    services = Services

    services.product_service = ProductService(product_dao, app.config)
    services.seller_service = SellerService(seller_dao, app.config)
    services.order_service = OrderService(order_dao, app.config)
    services.user_service = UserService(user_dao, app.config)
    services.coupon_service = CouponService(coupon_dao, app.config)
    services.event_service = EventService(event_dao, app.config)

    create_endpoints(app, services)

    return app
Beispiel #5
0
def create_app(test_config=None):

    def get_session():
        session = Session()
        return session

    app = Flask(__name__)

    CORS(app, resources={r'*': {'origins': '*'}})

    @app.errorhandler(Exception)
    def handle_invalid_usage(error):
        if isinstance(error, InvalidRequest):
            return {'message': str(error)}, 400
        else:
            response = jsonify(error)
            response.status_code = error.status_code
            return response

    from contextlib import suppress
    from flask.json import JSONEncoder  
    
    class MyJSONEncoder(JSONEncoder):
        def default(self, obj):
            # Optional: convert datetime objects to ISO format
            with suppress(AttributeError):
                return obj.isoformat()
            return dict(obj)

    app.json_encoder = MyJSONEncoder

    if test_config is None:
        app.config.from_pyfile("config.py")
    else:
        app.config.update(test_config)

    database = create_engine(app.config['DB_URL'], encoding='utf-8', max_overflow=0)
    Session = sessionmaker(bind=database, autocommit=False)

    # Persistence Layer
    seller_dao = SellerDao()
    product_dao = ProductDao()
    order_dao = OrderDao()

    # Business Layer
    services = Services
    services.seller_service = SellerService(seller_dao, app.config)
    services.product_service = ProductService(product_dao)
    services.order_service = OrderService(order_dao, seller_dao)

    seller_endpoints(app, services, get_session)
    product_endpoints(app, services, get_session)
    order_endpoints(app, services, get_session)

    return app
Beispiel #6
0
def create_app(test_config=None):
    app = Flask(__name__)

    if test_config is None:
        app.config.from_pyfile('config.py')
    else:
        app.config.update(test_config)

    # pool size : 1000, max_overflow=100 인 QueuePool로 DB 연결 설정
    database = create_engine(app.config['DB_URL'],
                             encoding='utf-8',
                             pool_size=1000,
                             max_overflow=100,
                             poolclass=QueuePool)

    # database engin와 연동된 session maker 생성, connection 필요시마다 session instance 생성
    Session = sessionmaker(bind=database)

    # CORS 설정
    CORS(app, resources={r'*': {'origins': '*'}})

    # Persistence layer
    order_dao = OrderDao()
    user_dao = UserDao()
    seller_dao = SellerDao()
    product_dao = ProductDao()
    qna_dao = QnADao()
    review_dao = ReviewDao()
    coupon_dao = CouponDao()

    # Business layer
    order_service = OrderService(order_dao)
    user_service = UserService(user_dao)
    seller_service = SellerService(seller_dao)
    product_service = ProductService(product_dao)
    qna_service = QnAService(qna_dao)
    review_service = ReviewService(review_dao)
    coupon_service = CouponService(coupon_dao)

    # Presentation layer
    app.register_blueprint(create_order_endpoints(order_service, Session))
    app.register_blueprint(create_user_endpoints(user_service, Session))
    app.register_blueprint(create_seller_endpoints(seller_service, Session))
    app.register_blueprint(create_product_endpoints(product_service, Session))
    app.register_blueprint(create_qna_endpoints(qna_service, Session))
    app.register_blueprint(create_review_endpoints(review_service, Session))
    app.register_blueprint(create_coupon_endpoints(coupon_service, Session))

    return app
Beispiel #7
0
def create_app(test_config=None):
    app = Flask(__name__)

    if test_config is None:
        app.config.from_pyfile("config.py")
    else:
        app.config.update(test_config)

    # DB 연결
    database = create_engine(
        app.config["DB_URL"],
        encoding="utf-8",
        pool_size=1000,
        max_overflow=100,
        poolclass=QueuePool,
    )

    # database와 연동된 session maker 생성, connection 필요시마다 session instace 생성
    Session = sessionmaker(bind=database)

    # CORS 설정
    CORS(app, resources={r"*": {"origins": "*"}})

    # Persistance layer
    user_dao = UserDao()
    product_dao = ProductDao()
    qna_dao = QnaDao()
    order_dao = OrderDao()
    review_dao = ReviewDao()
    event_dao = EventDao()

    # Business layer
    user_service = UserService(user_dao)
    product_service = ProductService(product_dao)
    qna_service = QnaService(qna_dao)
    order_service = OrderService(order_dao)
    review_service = ReviewService(review_dao)
    event_service = EventService(event_dao)

    # Presentation layer
    app.register_blueprint(create_user_endpoints(user_service, Session))
    app.register_blueprint(create_product_endpoints(product_service, Session))
    app.register_blueprint(create_qna_endpoints(qna_service, Session))
    app.register_blueprint(create_order_endpoints(order_service, Session))
    app.register_blueprint(create_review_endpoints(review_service, Session))
    app.register_blueprint(create_event_endpoints(event_service, Session))

    return app
Beispiel #8
0
def create_app():
    """

    Returns :
        생성된 플라스크 앱 객체

    Authors :
        [email protected]  (손수정)
        [email protected] (이곤호)

    History :
        2020-08-19 ([email protected])  : 초기 생성
        2020-08-25 ([email protected]) : AdminProduct 관련 추가
    """

    app = Flask(__name__)
    app.json_encoder = CustomJSONEncoder

    #CORS 설정
    CORS(app)

    #config 설정
    app.config.from_pyfile("config.py")

    # DAO 생성
    user_dao = UserDao()
    order_dao = OrderDao()
    product_dao = ProductDao()

    # Service 생성
    user_service = UserService(user_dao)
    order_service = OrderService(order_dao)
    product_service = ProductService(product_dao)

    # view blueprint 등록
    app.register_blueprint(create_user_endpoints(user_service))
    app.register_blueprint(create_admin_user_endpoints(user_service))
    app.register_blueprint(create_admin_order_endpoints(order_service))
    app.register_blueprint(service_product_endpoint(product_service))
    app.register_blueprint(create_admin_product_endpoints(product_service))
    app.register_blueprint(create_service_order_endpoints(order_service))

    return app
Beispiel #9
0
def create_app(test_config=None):
    app = Flask(__name__)

    cors = CORS(app, resources={r"/*": {"origins": "*"}})

    if test_config is None:
        app.config.from_pyfile("config.py")
    else:
        app.config.update(test_config)

    database = create_engine(app.config['DB_URL'],
                             encoding='utf-8',
                             max_overflow=0)

    ## Persistenace Layer
    user_dao = UserDao(database)
    store_dao = StoreDao(database)
    category_dao = CategoryDao(database)
    menu_dao = MenuDao(database)
    order_dao = OrderDao(database)

    ## Business Layer
    s3_client = boto3.client("s3",
                             aws_access_key_id=app.config['S3_ACCESS_KEY'],
                             aws_secret_access_key=app.config['S3_SECRET_KEY'],
                             region_name='ap-northeast-2')
    services = Services
    services.user_service = UserService(user_dao, app.config, s3_client)
    services.store_service = StoreService(store_dao, app.config, s3_client)
    services.menu_service = MenuService(menu_dao, app.config, s3_client)
    services.order_service = OrderService(order_dao)
    services.category_service = CategoryService(category_dao)
    socket_io = SocketIO(app, cors_allowed_origins="*")
    ## 엔드포인트들을 생성
    create_endpoints(app, services, socket_io)

    return app, socket_io
Beispiel #10
0
def create_app(test_config=None):
    app = Flask(__name__)
    app.debug = True
    app.json_encoder = CustomJSONEncoder
    app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024

    # By default, submission of cookies across domains is disabled due to the security implications.
    CORS(app, resources={r'*': {'origins': '*'}})

    if test_config is None:
        app.config.from_pyfile("config.py")
    else:
        app.config.update(test_config)

    database = app.config['DB']

    # persistence Layer
    destination_dao = DestinationDao()
    cart_item_dao = CartItemDao()
    sender_dao = SenderDao()
    event_dao = EventDao()
    store_order_dao = StoreOrderDao()
    order_dao = OrderDao()
    enquiry_dao = EnquiryDao()
    seller_shop_dao = SellerShopDao()

    # admin2
    order_detail_dao = OrderDetailDao()
    seller_info_dao = SellerInfoDao()

    # service
    services = Services

    services.user_service = UserService(app.config)
    services.destination_service = DestinationService(destination_dao)
    services.cart_item_service = CartItemService(cart_item_dao)
    services.store_order_service = StoreOrderService(store_order_dao)
    services.product_list_service = ProductListService()
    services.category_list_service = CategoryListService()

    services.event_list_service = EventListService()
    services.sender_service = SenderService(sender_dao)
    services.event_service = EventService(event_dao)
    services.seller_service = SellerService(app.config)
    services.bookmark_service = BookmarkService()
    services.product_enquiry_list_service = ProductEnquiryService()
    services.seller_shop_service = SellerShopService(seller_shop_dao)
    services.seller_info_service = SellerInfoService(seller_info_dao)

    #admin1
    services.event_service = EventService(event_dao)
    services.order_service = OrderService(order_dao)
    services.order_detail_service = OrderService(order_detail_dao)
    services.enquiry_service = EnquiryService(enquiry_dao)

    #admin2
    services.seller_service = SellerService(app.config)
    services.seller_info_service = SellerInfoService(seller_info_dao)
    services.product_manage_service = ProductManageService()

    # presentation Layer
    create_endpoints(app, services, database)

    return app
    def get(self):
        """주문하기 페이지 정보 가져오기

        Author:
            백승찬

        Args:

        Raises:
            e: 예상하지 못한 에러처리

        Returns:
            {
            "data": {
                        "orderer_information": {
                            "orderer_email"        : 주문자 이메일
                            "orderer_name"         : 주문자 이름
                            "orderer_phone_number" : 주문자 전화번호
                        },
                        "shipment_information": {
                            "additional_address" : 추가 주소 정보
                            "address"            : 주소
                            "address_history_id" : 주소 히스토리 아이디
                            "address_id"         : 주소 아이디
                            "is_deleted"         : 삭제 여부
                            "name"               : 수령인
                            "phone_number"       : 수령인 전화번호
                            "zip_code"           : 우편번호
                        },
                        "shipment_memo_information": [
                            {
                                "content": 배송메모
                                "id": 1
                            },
                            {
                                "content": 배송메모
                                "id": 2
                            },
                            {
                                "content": 배송메모
                                "id": 3
                            },
                            {
                                "content": 배송메모
                                "id": 4
                            }
                        ]
                    }
            }
        """
        order_service = OrderService()
        connection = None

        try:
            filters = {"account_id": g.account_info["account_id"]}

            connection = connect_db()

            result = order_service.get_order_information(connection, filters)

            return jsonify({"data": result})

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

        finally:
            if connection is not None:
                connection.close()