from flask_restx import Namespace, Resource, fields from flask import request, current_app import requests from bson import json_util from app.db.models import UserModel from app.docs.biling_models import billing_ns, product_model, update_price_model from app.config import Config BILLING_API_URL = Config.BILLING_API_URL HEADERS = { 'Content-Type': 'application/json', 'Authorization': f'Bearer {Config.BILLING_API_TOKEN}' } @billing_ns.route('/product') class CreateProduct(Resource): @billing_ns.expect(product_model) def post(self): data = request.get_json() response = requests.post(url=f'{BILLING_API_URL}/billing/product', json=data, headers=HEADERS) return response.json(), response.status_code @billing_ns.route('/product/') class UpdateProduct(Resource): @billing_ns.expect(update_price_model) def patch(self, product_id): data = request.get_json() response = requests.patch(url=f'{BILLING_API_URL}/billing/product/{product_id}', json=data, headers=HEADERS) return response.json(), response.status_code @billing_ns.route('/products') class ListProducts(Resource): def get(self): response = requests.get(url=f'{BILLING_API_URL}/billing/products', headers=HEADERS) return response.json(), response.status_code