from flask.views import MethodView from validators.product_val import ProductRegister, ProductGeneral from db.cloudant.cloudant_manager import CloudantManager from flask import jsonify, request from helpers.db_parser import DBP from db.postgresql.postgresql_manager import PostgresqlManager from db.postgresql.model import Appearance import random cm = CloudantManager() product_schema = ProductRegister() general_schema = ProductGeneral() my_dbp = DBP() pm = PostgresqlManager() class Product(MethodView): # Lista de productos def get(self): try: cm.connect_service() my_db = cm.connect_db('cafe-db') print(my_db) sdb = my_dbp.sync(my_db, cm) products = cm.get_query_by(my_db, '2', 'role_a') for i in range(len(products)): products[i] = { 'name_a': products[i]['doc']['name_a'], 'bio_a': products[i]['doc']['bio_a'], 'price': products[i]['doc']['price'], 'id_p': products[i]['doc']['id_p'],
from flask import request, jsonify from flask.views import MethodView from db.cloudant.cloudant_manager import CloudantManager cloud_manager = CloudantManager() class Order(MethodView): def get(self, id_p): try: # Conexion a Cloudant cloud_manager.connect_service() my_db = cloud_manager.connect_db('health-db') if my_db == 'error': raise Exception # Falta agregar sincronizacion de las db user_result = cloud_manager.get_query_by(my_db, id_p, 'id_p') list_orders = [] for result in user_result: try: appointment_id = result['doc']['id_a'] orders = cloud_manager.get_query_by( my_db, appointment_id, 'id_a') for order in orders: try: order_id = order['doc']['id_o'] new_order = { 'id_o': order_id, 'id_a': appointment_id, 'diagnosis': order['doc']['diagnosis'] }