Ejemplo n.º 1
0
def getactor():
    try:
        actors = [actor.serialize() for actor in ActorDAO.dbRead()]
        return jsonify(actors), 200
    except Exception as e:
        print(e)
        return "Server error", 500
Ejemplo n.º 2
0
def update(id):
    if not request.is_json:
        return "Bad Request", 403
    try:
        data = request.get_json()
        result = ActorDAO.dbUpdate(id, ActorDTO(**data))
        if result > 0:
            user_id = request.headers['UserID']
            print('in if')
            log = LogDTO(user_id=user_id,
                         action="update actor id: " + str(id),
                         date_create=datetime.now())
            print('after log')
            LogDAO.dbCreate(log)
            print('after add log')
            return jsonify(result), 200
        return "Can't delete", 403
    except Exception as e:
        print(e)
        print('exct')
        if "404 Not Found" in str(e):
            return "404 Not Found", 404
        else:
            print('in else')
            return "Server error", 500
Ejemplo n.º 3
0
def getactorById(id):
    try:
        actor = ActorDAO.dbGet(id)
        if actor:
            return jsonify(actor.serialize()), 200
        else:
            return jsonify(actor), 200
    except Exception as e:
        print(e)
        return "Server error", 500
Ejemplo n.º 4
0
def getActorByTribulationID(id):
    try:
        result = None
        result = [
            actor.serialize() for actor in ActorDAO.dbGetByTribulationID(id)
        ]
        return jsonify(result), 200
    except Exception as e:
        print(e)
        return "Server error", 500
Ejemplo n.º 5
0
def delete(id):
    try:
        result = ActorDAO.dbDelete(id)
        if result > 0:
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="delete actor id: " + str(id),
                         date_create=datetime.now())
            LogDAO.dbCreate(log)
            return jsonify(result), 200

        return "Can't delete", 403
    except Exception as e:
        print(e)
        if "404 Not Found" in str(e):
            return "404 Not Found", 404
        else:
            return "Server error", 500
Ejemplo n.º 6
0
def create():
    if not request.is_json:
        return "Bad Request", 403
    try:
        data = request.get_json()
        new_actor = ActorDTO(**data)
        result = ActorDAO.dbCreate(new_actor)
        if result > 0:
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="create actor ",
                         date_create=datetime.now())
            LogDAO.dbCreate(log)
            return jsonify(result), 201
        return "Can't create", 403
    except Exception as e:
        print(e)
        return "Server error", 500
Ejemplo n.º 7
0
def login():
    if not request.is_json:
        return "Bad Request", 403
    try:
        data = request.get_json()
        email = data["email"]
        password = data["password"]
        user = ActorDAO.dbLogin(email, password)
        if not user:
            return "Don't have user", 401

        # payload = {
        #     "email":email,
        #     "role": user.role,
        #     "exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=10)
        # }
        # token = jwt.encode(payload, secret_key, algorithm='HS256')
        return jsonify({"Role": user.role, "UserID": user.actor_id}), 200
    except Exception as e:
        traceback.print_exc(file=sys.stdout)
    return "Server error internal", 500