예제 #1
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
예제 #2
0
def gettribulation():
    try:
        tribulations = [
            tribulation.serialize() for tribulation in TribulationDAO.dbRead()
        ]
        return jsonify(tribulations), 200
    except Exception as e:
        print(e)
        return "Server error", 500
예제 #3
0
def gettribulationById(id):
    try:
        tribulation = TribulationDAO.dbGet(id)
        if tribulation:
            return jsonify(tribulation.serialize()), 200
        else:
            return jsonify(tribulation), 200
    except Exception as e:

        return "Server error", 500
예제 #4
0
def gettribulationByActorID(id):
    try:
        tribulations = [
            tribulation.serialize()
            for tribulation in TribulationDAO.dbGetByActorID(id)
        ]
        return jsonify(tribulations), 200
    except Exception as e:
        print(e)
        return "Server error", 500
예제 #5
0
def delete(id):
    try:
        result = TribulationDAO.dbDelete(id)
        if result > 0:
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="delete tribulation" + 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
예제 #6
0
def create():
    if not request.is_json:
        return "Bad Request", 403
    try:
        data = request.get_json()
        new_tribulation = TribulationDTO(**data)
        result = TribulationDAO.dbCreate(new_tribulation)
        if result > 0:
            user_id = request.headers['UserID']
            log = LogDTO(user_id=user_id,
                         action="create tribulation",
                         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
예제 #7
0
def enoughQuantity(tool_id, tribulation_id, quantity):
    tribulation = TribulationDAO.dbGet(tribulation_id)
    tool_quantity = ToolDAO.dbGet(tool_id).quantity
    result = False
    try:
        list_tool = tft.query.filter(
            tft.tool_id == tool_id, tft.time_start >= tribulation.time_start,
            tft.time_end <= tribulation.time_end).all()
        #sum quantity
        sum = 0
        for tool in list_tool:
            sum += tool.quantity
        print('tool quantity = ', tool_quantity)
        print('sum           = ', sum)
        print('quantity      = ', quantity)
        result = (tool_quantity >= (sum + quantity))
    except Exception as e:
        raise e
    return result
예제 #8
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