예제 #1
0
def setUndoneOne(task_id):
    currentId = token.checkAuth(request)
    if not currentId:
        abort(401)
    setting_task = Task.query.get(task_id)
    setting_task.isDone = False
    db.session.commit()
    return jsonify({'status': 200, 'message': 'Ok'})
예제 #2
0
def deleteOne(task_id):
    currentId = token.checkAuth(request)
    if not currentId:
        abort(401)
    deleting_task = Task.query.get(task_id)
    db.session.delete(deleting_task)
    db.session.commit()
    return jsonify({'status': 200, 'message': 'Ok'})
예제 #3
0
def getHistoryTo():
    currentId = token.checkAuth(request)
    if not currentId:
        abort(401)
    return jsonify({
        'status': 200,
        'message': 'Ok',
        'data': redis.getHistory(currentId)
    })
예제 #4
0
def test():
    currentId = token.checkAuth(request)
    if not currentId:
        abort(401)
    return jsonify({
        'status': 200,
        'message': 'test Ok - CPR MP 2021',
        'currentId': currentId
    })
예제 #5
0
def deleteAll():
    currentId = token.checkAuth(request)
    if not currentId:
        abort(401)
    tasks = Task.query.filter_by(userId=currentId).all()
    for task in tasks:
        db.session.delete(task)
        db.session.commit()
    return jsonify({'status': 200, 'message': 'Ok'})
예제 #6
0
def setUndoneAll():
    currentId = token.checkAuth(request)
    if not currentId:
        abort(401)
    tasks = Task.query.filter(
        and_(Task.userId == currentId, Task.isDone == True)).all()
    for task in tasks:
        task.isDone = False
        db.session.commit()
    return jsonify({'status': 200, 'message': 'Ok'})
예제 #7
0
def deleteUnfin():
    currentId = token.checkAuth(request)
    if not currentId:
        abort(401)
    tasks = Task.query.filter(
        and_(Task.userId == currentId, Task.isDone == False)).all()
    for task in tasks:
        db.session.delete(task)
        db.session.commit()
    return jsonify({'status': 200, 'message': 'Ok'})
예제 #8
0
def getAll():
    currentId = token.checkAuth(request)
    if not currentId:
        abort(401)
    tasks = Task.query.filter_by(userId=currentId).all()
    listToOutput = [{
        "id": task.id,
        "title": task.title,
        "time": task.timestamp,
        "isDone": task.isDone
    } for task in tasks]
    return jsonify({'status': 200, 'message': 'Ok', 'data': listToOutput})
예제 #9
0
def add():
    if not request.json or not 'title' in request.json:
        abort(400)
    currentId = token.checkAuth(request)
    if not currentId:
        abort(401)
    newTask = Task(
        userId=currentId,
        title=request.json['title'],
        isDone=False,
        ddl=datetime(request.json['ddl']['y'], request.json['ddl']['m'],
                     request.json['ddl']['d'], request.json['ddl']['h'],
                     request.json['ddl']['min'], request.json['ddl']['s']))
    db.session.add(newTask)
    db.session.commit()
    return jsonify({'status': 200, 'message': 'Ok'})
예제 #10
0
def search():
    if not request.json or not 'keyWord' in request.json:
        abort(400)
    currentId = token.checkAuth(request)
    if not currentId:
        abort(401)
    tasks = db.session.query(Task).filter(
        and_(Task.title.like('%' + request.json['keyWord'] + '%'),
             Task.userId == currentId)).all()
    listToOutput = [{
        "id": task.id,
        "title": task.title,
        "time": task.timestamp,
        "isDone": task.isDone
    } for task in tasks]
    redis.saveHistory(currentId, request.json['keyWord'])
    return jsonify({'status': 200, 'message': 'Ok', 'data': listToOutput})