示例#1
0
import logging

import flask_restplus
from flask import request

import app.api.schema.request.user
import app.api.schema.response.user
from app import services
from app.extensions import Namespace
from app.helpers import decode_token
from app.services.register import send_confirm_email

__author__ = 'LongHB'
_logger = logging.getLogger(__name__)

ns = Namespace('admin', description='admin operations')

_get_seller_pending_req = ns.model(
    'seller_pending_req', app.api.request.admin.get_pending_seller_req)


@ns.route('/pending', methods=['POST'])
class GetPendingSellers(flask_restplus.Resource):
    @ns.expect(_get_seller_pending_req, validate=True)
    def post(self):
        data = request.args or request.json
        return services.admin.get_pending_seller(data)


_confim_seller_req = ns.model('confirm_seller_req',
                              app.api.request.admin.confirm_seller_req)
示例#2
0
# coding=utf-8
import logging

import flask_restplus
from flask import request

import app.api.schema.request.user
import app.api.schema.response.user
from app import services
from app.extensions import Namespace

__author__ = 'LongHB'
_logger = logging.getLogger(__name__)

ns = Namespace('profile', description='Profile operations')

_change_password_req = ns.model('change_password_req',
                                app.api.request.user.change_password_req)
_user_res = ns.model('user_res', app.api.response.user.user_res)


@ns.route('/change_password', methods=['POST'])
class ChangePassword(flask_restplus.Resource):
    @ns.expect(_change_password_req, validate=True)
    @ns.marshal_with(_user_res)
    def post(self):
        "validate user by current password and jwt token and set new password"
        data = request.args or request.json
        return services.user.change_password(**data).to_display_dict()

示例#3
0
import flask_restplus
from flask import request, Response

from app.extensions import Namespace
from .schema import requests
from .. import services

ns = Namespace('cralwer', description='Crawler operations')


@ns.route('/view_data/<web_url>', methods=['GET'])
class ViewCrawlData(flask_restplus.Resource):
    def get(self, web_url):
        response = Response()
        response.set_data(services.crawler.get_crawled_data(web_url))
        return response


@ns.route('/get_data/<web_url>', methods=['GET'])
class GetCrawlData(flask_restplus.Resource):
    def get(self, web_url):
        return services.crawler.get_crawled_data(web_url)


_crawl_request = ns.model('crawl_req', requests.crawl_request)


@ns.route('/crawl', methods=['POST'])
class Crawler(flask_restplus.Resource):
    @ns.expect(_crawl_request)
    def post(self):
示例#4
0
# coding=utf-8
import logging

import flask_restplus as _fr
from flask import request

from app import services
from app.extensions import Namespace

__author__ = 'LongHB'
_logger = logging.getLogger(__name__)

ns = Namespace('file', description='File operations')


@ns.route('/store-image', methods=['POST'])
class StoreImage(_fr.Resource):
    def post(self):
        images = request.files
        return services.file.upload_image(images)
示例#5
0
import logging

import flask_restplus
from flask import request

import app.api.schema.request.product
from app.extensions import Namespace
from app.services import product, keyword, category, brand, rating

__author__ = 'LongHB'

from app.helpers.catalog.product_validator import validate_product_search_param

_logger = logging.getLogger(__name__)

ns = Namespace('product', description='Product operations')

_product_search_req = ns.model('product_search_req', app.api.request.product.product_search_req)
_category_finding_req = ns.model('_category_finding_req', app.api.request.product.category_finding_req)
_brand_finding_req = ns.model('_brand_finding_req', app.api.request.product.brand_finding_req)
_keyword_req = ns.model('keyword_recommend_req', app.api.request.product.keyword_recommder_req)
_rating_req = ns.model('rating_req', app.api.request.product.rating_req)
_rating_create_req = ns.model('rating_create_req', app.api.request.product.rating_create_req)


@ns.route('/search', methods=['POST'])
class SearchProduct(flask_restplus.Resource):
    @ns.expect(_product_search_req, validate=True)
    def post(self):
        data = request.args or request.json
        validate_product_search_param(data)
示例#6
0
import flask_restplus
from flask import request

import app.api.schema.request.seller
import app.api.schema.response.seller
from app import services
from app.extensions import Namespace

__author__ = 'LongHB'

from app.helpers.catalog.product_validator import validate_upsert_product_request

_logger = logging.getLogger(__name__)

ns = Namespace('seller', description='Seller operations')

_seller_register_req = ns.model('seller_register_req',
                                app.api.request.seller.seller_register_req)
_seller_register_res = ns.model('seller_register_res',
                                app.api.response.seller.seller_res)


@ns.route('/register', methods=['POST'])
class RegisterNewSeller(flask_restplus.Resource):
    @ns.expect(_seller_register_req, validate=True)
    @ns.marshal_with(_seller_register_res)
    def post(self):
        data = request.args or request.json
        return services.seller.register_to_be_seller(**data).to_dict()
示例#7
0
# coding=utf-8
import logging

import flask_restplus
from flask import request

import app.api.schema.request.product
from app.extensions import Namespace
from app.helpers import decode_token
from app.services import order

__author__ = 'LongHB'
_logger = logging.getLogger(__name__)

ns = Namespace('order', description='Order management operations')

_order_details = ns.model('order_details',
                          app.api.request.order.order_details_req)


@ns.route('/details', methods=['POST'])
class OrderChecking(flask_restplus.Resource):
    @ns.expect(_order_details, validate=True)
    @ns.marshal_with(app.api.response.order.order_details_response)
    def post(self):
        data = request.args or request.json
        return order.get_order_details(data)


_order_checking = ns.model('order_checking',
                           app.api.request.order.order_checking_req)
示例#8
0
# coding=utf-8
import logging

import flask_restplus
from flask import request

import app.api.schema.request.user
import app.api.schema.response.user
from app import services
from app.extensions import Namespace

__author__ = 'LongHB'
_logger = logging.getLogger(__name__)

ns = Namespace('users', description='User operations')

_user_res = ns.model('user_res', app.api.response.user.user_res)


@ns.route('/get_status', methods=['GET'])
class UserStatus(flask_restplus.Resource):
    @ns.marshal_with(_user_res)
    def get(self):
        "fetch user status by checking jwt token"
        return services.user.fetch_user_status()


_login_req = ns.model('login_req', app.api.request.user.login_req)


@ns.marshal_with(_user_res)
示例#9
0
import logging

import flask_restplus
from flask import request

import app.api.schema.request.user
import app.api.schema.response.user
from app import services
from app.extensions import Namespace
from app.helpers import decode_token
from app.services.register import send_confirm_email

__author__ = 'LongHB'
_logger = logging.getLogger(__name__)

ns = Namespace('register', description='Register operations')

_register_req = ns.model('register_req',
                         app.api.request.user.register_user_req)
_register_res = ns.model('register_res', app.api.response.user.register_res)


@ns.route('/', methods=['POST'])
class Registers(flask_restplus.Resource):
    @ns.expect(_register_req, validate=True)
    @ns.marshal_with(_register_res)
    def post(self):
        data = request.args or request.json
        pending_register = services.register.create_new_register(**data)
        send_confirm_email(
            **data