file.py 3.5 KB
Newer Older
wanli's avatar
wanli committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
'''
Author: your name
Date: 2021-07-09 12:39:40
LastEditTime: 2021-07-09 12:40:18
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\build_out\views\file.py
'''
from flask import current_app, jsonify, request
from flask_restful import Resource
from flask_restful.reqparse import RequestParser
from flask_jwt_extended import ( jwt_required, get_jwt_identity )
from application.signal_manager import signalManager
from models.login import  postLoginSchema, getListLoginSchema, getListLoginsSchema, getLoginSchema
from webcreator.log import logger
from webcreator.response import ResponseCode, response_result

class FileResourceList(Resource):
    def __init__(self):
        pass
        # 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
        # self.parser = RequestParser()

    def get(self):
        # 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
        # self.parser.add_argument("page", type=int, location="args", default=1)
        # self.parser.add_argument("pageSize", type=int, location="args", default=15)
        # args = self.parser.parse_args()

        try:
            json_payload = request.json
            logger.warn(json_payload)
            data = getListLoginSchema.load(json_payload)
            result = signalManager.actionGetListLogin.emit(data)
            json_dumps = getListLoginSchema.dump(result)
            if result[0]:
                json_dumps = getListLoginsSchema.dump(result[1])
                logger.warn(json_dumps)
                return response_result(ResponseCode.OK, data=json_dumps, count=result[2])
            return response_result(ResponseCode.REQUEST_ERROR)
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.DB_ERROR)

    def post(self):
        try:
            json_payload = request.json
            data = postLoginSchema.load(json_payload)
            result = signalManager.actionPostLogin.emit(data)
            if result[0] == False:
                # json_dumps = postLoginSchema.dump(result)
                return response_result(ResponseCode.REQUEST_ERROR, msg=result[1])
            logger.warn(result)
            return response_result(ResponseCode.OK)
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.DB_ERROR)


class FileResource(Resource):
    def __init__(self):
        pass
        # 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
        # self.parser = RequestParser()

    @jwt_required(locations=["headers"])
    def get(self, uuid):
        # 特殊参数,即不是从json获取参数的接口,可以将这个注释打开
        # self.parser.add_argument("page", type=int, location="args", default=1)
        # self.parser.add_argument("pageSize", type=int, location="args", default=15)
        # args = self.parser.parse_args()

        try:
            json_payload = request.json
            print("========>", uuid, json_payload)
            data = getLoginSchema.load(json_payload)
            result = signalManager.actionGetLogin.emit(uuid, data)
            if result[0]:
                json_dumps = getLoginSchema.dump(result[1])
                return response_result(ResponseCode.OK, data=json_dumps)
            return response_result(ResponseCode.NO_DATA)
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.DB_ERROR)