def post(self, request): request_data = request.data self.logger_info.info('[UserReceiptList][post][' + str(request_data) + ']') auth_info = header_parser.parse_auth_info(request) lang_info = parse_language_v2(request.META) try: check_auth_info_v2(auth_info.open_id, auth_info.access_token) receipt_util.request_validation(auth_info.open_id, request_data) receipt_manager = ReceiptManager(self.logger_info, self.logger_error) receipt_list = receipt_manager.create_user_receipt( auth_info.open_id, request_data, lang_info.cn_header) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('user_receipts', receipt_list) return Response(result.get_response(), result.get_code())
def get(self, request, address_id): self.logger_info.info('[UserAddressDetail][get][' + str(address_id) + ']') auth_info = header_parser.parse_auth_info(request) try: address_req_validation(auth_info.open_id, auth_info.access_token) check_auth_info_v2(auth_info.open_id, auth_info.access_token) # Read specific address address_manager = AddressManagerV2(self.logger_info, self.logger_error) user_address = address_manager.get_address(auth_info.open_id, int(address_id)) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('user_address', user_address) return Response(result.get_response(), result.get_code())
def put(self, request, hub_id): self.logger_info.info('[UserAddressHubSelector][put][' + str(hub_id) + ']') auth_info = header_parser.parse_auth_info(request) lang_info = parse_language_v2(request.META) try: check_auth_info_v2(auth_info.open_id, auth_info.access_token) address_manager = AddressManagerV2(self.logger_info, self.logger_error) address_list = address_manager.select_hub(auth_info.open_id, lang_info.cn_header, int(hub_id)) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('user_addresses', address_list) return Response(result.get_response(), result.get_code())
def put(self, request, address_id): self.logger_info.info('[UserAddressSelector][put][' + str(address_id) + ']') auth_info = header_parser.parse_auth_info(request) try: check_auth_info_v2(auth_info.open_id, auth_info.access_token) # Get address data address_manager = AddressManagerV2(self.logger_info, self.logger_error) address_data = address_manager.get_address(auth_info.open_id, address_id) # Check delivery area address_select_validation(address_data['delivery_area']) # Select address address_list = address_manager.select_address(auth_info.open_id, int(address_id)) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('user_addresses', address_list) return Response(result.get_response(), result.get_code())
def get(self, request): auth_info = header_parser.parse_auth_info(request) language_info = header_parser.parse_language_v2(request.META) logger_info.info('[views_coupon][CouponPage][get][' + auth_info.open_id + ',' + auth_info.access_token + ']') try: coupon_manager = CouponManagerV3(logger_info, logger_error) check_auth_info_v2(auth_info.open_id, auth_info.access_token) page = int(request.GET.get('page', 1)) limit = int(request.GET.get('limit', 20)) coupon_data = coupon_manager.get_coupon_list( auth_info.open_id, auth_info.access_token, language_info.target_db, page, limit, self.EXPIRED_DAY) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set_map(coupon_data) return Response(result.get_response(), result.get_code())
def post(self, request): request_data = request.data self.logger_info.info('[UserAddressList][post][' + str(request_data) + ']') auth_info = header_parser.parse_auth_info(request) try: address_req_validation(auth_info.open_id, auth_info.access_token) check_auth_info_v2(auth_info.open_id, auth_info.access_token) # Request data check address_create_data_check(request_data) # Create user address address_manager = AddressManagerV2(self.logger_info, self.logger_error) created_address = address_manager.create_address(auth_info.open_id, request_data) # Read latest address list address_list = address_manager.get_address_list(auth_info.open_id) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('user_addresses', address_list) result.set('user_address_id', created_address['id']) return Response(result.get_response(), result.get_code())
def get(self, request): auth_info = header_parser.parse_auth_info(request) lang_info = parse_language_v2(request.META) open_id = auth_info.open_id access_token = auth_info.access_token cn_header = lang_info.cn_header accept_lang = lang_info.accept_lang try: check_auth_info_v2(auth_info.open_id, auth_info.access_token) user_manager = UserManagerV2(self.logger_info, self.logger_error) # User information user_data = user_manager.get_user_data(open_id) user_info = user_manager.get_user_info(open_id) # Default hub id default_hub_id = user_data['default_hub_id'] # Latest payment method and shipping method latest_payment_method = user_info['latest_payment_method'] latest_shipping_method = user_info['latest_shipping_method'] # Latest cart information and special instruction template cart_info = user_manager.get_user_cart_info_data(open_id) include_cutlery = cart_info['include_cutlery'] user_inst_template = cart_util.get_user_inst_list(cn_header, cart_info['instruction_history']) special_instruction_template = cart_util.get_sp_inst_template(cn_header) # Delivery time table information (map) delivery_map = cart_util.get_delivery_time(default_hub_id, lang_info.accept_lang) # Add order unavailable message order_available = delivery_map['order_available'] order_un_msg = payment_util.get_order_unavailable_msg(cn_header) if not order_available else '' # Purchase information (map) purchase_map = cart_util.get_purchases_data(open_id, access_token, accept_lang) # Next day information phase_next_day = product_util.get_phase_next_day() # Recommend product information products = cart_util.get_recommend_product(default_hub_id, accept_lang) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('latest_payment_method', latest_payment_method) result.set('latest_shipping_method', latest_shipping_method) result.set('special_instruction_template', special_instruction_template + user_inst_template) result.set('order_unavailable_message', order_un_msg) result.set('phase_next_day', phase_next_day) result.set('products', products) result.set('include_cutlery', include_cutlery) result.set_map(delivery_map) result.set_map(purchase_map) return Response(result.get_response(), result.get_code())