Ejemplo n.º 1
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.º 2
0
def updateTool(id):
    if not request.is_json:
        return "Bad Request", 403
    try:
        data = request.get_json()
        tft = ToolForTribulationDTO(**data)
        tribulation = TribulationDAO.dbGet(id)
        tft.tribulation_id = id
        tft.time_start = tribulation.time_start
        tft.time_end = tribulation.time_end
        result = ToolForTribulationDAO.dbUpdate(tft)
        if result > 0:
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="add actor into tribulation",
                         date_create=datetime.now())
            LogDAO.dbCreate(log)
            return jsonify(result), 200
        return "Can't update tool", 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.º 3
0
def delete(id):
    try:
        result = ToolDAO.dbDelete(id)
        if result > 0:
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="delete tool id: " + str(id),
                         date_create=datetime.now())
            LogDAO.dbCreate(log)
            return jsonify(result), 200
        return "Can't delete", 403
    except Exception as e:
        if "404 Not Found" in str(e):
            return "404 Not Found", 404
        else:
            return "Server error", 500
Ejemplo n.º 4
0
def getTool():
    try:
        result = None
        result = [log.serialize() for log in LogDAO.dbRead()]
        return jsonify(result), 200
    except Exception as e:
        print(e)
        return "Server error", 500
Ejemplo n.º 5
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.º 6
0
def removeTool(id):
    if not request.is_json:
        return "Bad Request", 403
    try:
        data = request.get_json()
        tool_id = int(data["tool_id"])
        if ToolForTribulationDAO.dbDelete(tool_id, id):
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="remove tool into tribulation",
                         date_create=datetime.now())
            LogDAO.dbCreate(log)
            return "Remove Success", 200
        return "Can't remove tool", 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.º 7
0
def update(id):
    if not request.is_json:
        return "Bad Request", 403
    try:

        data = request.get_json()
        result = ToolDAO.dbUpdate(id, ToolDTO(**data))
        if result > 0:
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="update tool tool id:" + str(id),
                         date_create=datetime.now())
            LogDAO.dbCreate(log)
            return jsonify(result), 200
        return "Can't delete", 403
    except Exception as e:
        if "404 Not Found" in str(e):
            return "404 Not Found", 404
        else:
            return "Server error", 500
Ejemplo n.º 8
0
def removeActor(id):
    if not request.is_json:
        return "Bad Request", 403
    try:
        data = request.get_json()
        character = CharacterDTO(**data)
        character.tribulation_id = id
        if CharacterDAO.dbDelete(character):
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="remove actor into tribulation",
                         date_create=datetime.now())
            LogDAO.dbCreate(log)
            return "Remove Success", 200
        return "Can't remove tool", 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.º 9
0
def update(id):
    if not request.is_json:
        return "Bad Request", 403
    try:
        data = request.get_json()
        result = TribulationDAO.dbUpdate(id, TribulationDTO(**data))

        if result > 0:
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="update tool into tribulation",
                         date_create=datetime.now())
            LogDAO.dbCreate(log)
            return jsonify(result), 200
        return "Can't update", 403
    except Exception as e:
        print(e)
        traceback.print_exc(file=sys.stdout)
        if "404 Not Found" in str(e):
            return "404 Not Found", 404
        else:
            return "Server error", 500
Ejemplo n.º 10
0
def addActor(id):
    if not request.is_json:
        return "Bad Request", 403
    try:
        data = request.get_json()
        character = CharacterDTO(**data)
        character.tribulation_id = id
        result = CharacterDAO.dbCreate(character)
        if result > 0:
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="add actor into tribulation",
                         date_create=datetime.now())
            LogDAO.dbCreate(log)
            return jsonify(result), 200
        return "Can't add tool", 403
    except Exception as e:
        print(e)
        if "404 Not Found" in str(e):
            return "404 Not Found", 404
        else:
            return "Server error", 500