예제 #1
0
class SessionController(Resource):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.__productservice = ProductService()
        self.__sessionservice = SessionService()

    @auth_required()
    @sessionNS.doc(security=["token"])
    @sessionNS.param("sessionid",
                     description="The desired session ID",
                     _in="path",
                     required=True)
    @sessionNS.param("payload",
                     description="Optional",
                     _in="body",
                     required=False)
    @sessionNS.expect(REQUESTMODEL)
    @sessionNS.response(200, "Success", RESPONSEMODEL)
    @sessionNS.response(204, "No products found", ERRORMODEL)
    @sessionNS.response(400, "Bad Request", ERRORMODEL)
    @sessionNS.response(401, "Unauthorized", ERRORMODEL)
    @sessionNS.response(404, "Not Found", {})
    @sessionNS.response(500, "Unexpected Error", ERRORMODEL)
    @sessionNS.response(504, "Error while accessing the gateway server",
                        ERRORMODEL)
    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
class GenderController(Resource):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.__productservice = ProductService()
        self.__sessionservice = SessionService()

    @auth_required()
    @genderNS.doc(security=["token"])
    @genderNS.param("gender",
                    description="The desired gender",
                    _in="path",
                    required=True)
    @genderNS.param("payload",
                    description="Optional",
                    _in="body",
                    required=False)
    @genderNS.expect(REQUESTMODEL)
    @genderNS.response(200, "Success", RESPONSEMODEL)
    @genderNS.response(204, "No Content", {})
    @genderNS.response(400, "Bad Request", ERRORMODEL)
    @genderNS.response(401, "Unauthorized", ERRORMODEL)
    @genderNS.response(500, "Unexpected Error", ERRORMODEL)
    @genderNS.response(504, "Error while accessing the gateway server",
                       ERRORMODEL)
    def post(self, gender="Men"):
        """Gender information."""
        try:
            in_data = GenderRequest.parse_json()
            discounts = self.__productservice.super_discounts(gender=gender,
                                                              **in_data)
            sessions = self.__sessionservice.select(gender=gender)
            brands = self.__productservice.select_brands(gender=gender)
            kinds = self.__productservice.select_kinds(gender=gender)

            jsonsend = GenderResultsResponse.marshall_json({
                "discounts": [d.get_dict_min() for d in discounts],
                "sessions":
                sessions,
                "brands":
                brands,
                "kinds":
                kinds
            })
            return jsonsend
        except Exception as error:
            return ErrorHandler(error).handle_error()