示例#1
0
    def post(self, sessionid):
        """Session information."""
        try:
            in_data = SearchRequest.parse_json()
            session = self.__sessionservice.select_by_id(sessionid)
            sessions = self.__sessionservice.select(gender=session.gender)
            total = self.__productservice.get_total(sessionid=sessionid,
                                                    **in_data)
            brands = self.__productservice.select_brands(sessionid=sessionid,
                                                         **in_data)
            kinds = self.__productservice.select_kinds(sessionid=sessionid,
                                                       **in_data)
            pricerange = self.__productservice.select_pricerange(
                sessionid=sessionid)

            jsonsend = SessionResultsResponse.marshall_json({
                "sessions":
                sessions,
                "total":
                total,
                "brands":
                brands,
                "kinds":
                kinds,
                "pricerange":
                pricerange
            })
            return jsonsend
        except Exception as error:
            return ErrorHandler(error).handle_error()
示例#2
0
    def post(self, brand):
        """Brand information."""
        try:
            in_data = SearchRequest.parse_json()
            total = self.__productservice.get_total(brand=brand, **in_data)
            brands = self.__productservice.select_brands(brand=brand, **in_data)
            kinds = self.__productservice.select_kinds(brand=brand, **in_data)
            pricerange = self.__productservice.select_pricerange(brand=brand)

            jsonsend = SearchResultsResponse.marshall_json(
                {
                    "total": total,
                    "brands": brands,
                    "kinds": kinds,
                    "pricerange": pricerange
                }
            )
            return jsonsend
        except Exception as error:
            return ErrorHandler(error).handle_error()
示例#3
0
from flask_restplus import Namespace, Resource

from backend.service import ProductService
from backend.util.request.search_request import SearchRequest
from backend.util.response.search_results import SearchResultsResponse
from backend.util.response.error import ErrorResponse
from backend.controller import ErrorHandler, auth_required


brandNS = Namespace("Brand", description="Brand related operations.")

REQUESTMODEL = SearchRequest.get_model(brandNS, "SearchRequest")
RESPONSEMODEL = SearchResultsResponse.get_model(brandNS, "SearchResultsResponse")
ERRORMODEL = ErrorResponse.get_model(brandNS, "ErrorResponse")


@brandNS.route("/<string:brand>/", strict_slashes=False)
class BrandController(Resource):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.__productservice = ProductService()

    @auth_required()
    @brandNS.doc(security=["token"])
    @brandNS.param("brand", description="The desired brand", _in="path", required=True)
    @brandNS.param("payload", description="Optional", _in="body", required=False)
    @brandNS.expect(REQUESTMODEL)
    @brandNS.response(200, "Success", RESPONSEMODEL)
    @brandNS.response(204, "No Content", ERRORMODEL)
    @brandNS.response(400, "Bad Request", ERRORMODEL)
    @brandNS.response(401, "Unauthorized", ERRORMODEL)
示例#4
0
from flask_restplus import Namespace, Resource

from backend.service import ProductService
from backend.util.request.search_request import SearchRequest
from backend.util.response.search_results import SearchResultsResponse
from backend.util.response.error import ErrorResponse
from backend.controller import ErrorHandler, auth_required

searchNS = Namespace("Search", description="Search related operations.")

REQUESTMODEL = SearchRequest.get_model(searchNS, "SearchRequest")
RESPONSEMODEL = SearchResultsResponse.get_model(searchNS,
                                                "SearchResultsResponse")
ERRORMODEL = ErrorResponse.get_model(searchNS, "ErrorResponse")


@searchNS.route("/<string:query>", strict_slashes=False)
class SearchController(Resource):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.__productservice = ProductService()

    @auth_required()
    @searchNS.doc(security=["token"])
    @searchNS.param("query",
                    description="The search query",
                    _in="path",
                    required=True)
    @searchNS.param("payload",
                    description="Optional",
                    _in="body",