from flask_restful import Resource, Api, reqparse
from flask import request
from bson import json_util, ObjectId
import json

import echo_db.database as EchoDB
import echo_api.auth as Auth

class DevicesAPI(Resource):
    
    def get(self):
        if not Auth.Auth.verify(request):
            return {'status': 'failed', 'message': 'Not Authenticated!'}, 401

        collection = EchoDB.EchoDB.database['Devices']
        devices = collection.find({})
        devices_json = json.loads(json_util.dumps(devices))
        return {'status': 'success', 'data': devices_json}, 200