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'})
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'})
def getHistoryTo(): currentId = token.checkAuth(request) if not currentId: abort(401) return jsonify({ 'status': 200, 'message': 'Ok', 'data': redis.getHistory(currentId) })
def test(): currentId = token.checkAuth(request) if not currentId: abort(401) return jsonify({ 'status': 200, 'message': 'test Ok - CPR MP 2021', 'currentId': currentId })
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'})
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'})
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'})
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})
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'})
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})