def stop_timer(self, task: TaskModel): if not self._stop_timer(task): return response(status_code=status.HTTP_200_OK, message='timer already stopped') return response(status_code=status.HTTP_202_ACCEPTED, message='Session stopped')
def put(self): body = get_task_info() user = token_auth.current_user() if TaskModel.query.filter_by(name=body.name, user_id=user.id).first(): return response(status_code=status.HTTP_409_CONFLICT, message='Task with this name already exists') task = TaskModel(name=body.name, color=body.color, user=user) db.session.add(task) db.session.commit() return response(status_code=status.HTTP_201_CREATED, data=task.as_dict())
def get(self): user = token_auth.current_user() # type: UserModel tasks = TaskModel.query.filter_by(user_id=user.id) return response( status_code=status.HTTP_200_OK, data=[t.as_dict() for t in tasks])
def post(): body = get_user_info() if UserModel.query.filter_by(username=body.username).first(): return response(status_code=status.HTTP_409_CONFLICT, message='User with this name already exists') user = UserModel(name=body.username, password=body.password) db.session.add(user) db.session.commit() data = user.as_dict() data[TOKEN] = encode_token(user.as_dict()) return response(status_code=status.HTTP_200_OK, data=data, message='Successfully registered')
def delete(self, task_id): user = token_auth.current_user() # type: UserModel task = self.try_find_task(task_id, user) db.session.delete(task) db.session.commit() return response(status_code=status.HTTP_200_OK, message='Task: {} deleted'.format(task.name))
def start_timer(self, task: TaskModel): self._stop_timer(task) session = SessionModel(task_id=task.id) db.session.add(session) db.session.commit() return response(status_code=status.HTTP_200_OK, data=session.as_dict())
def delete(self, session_id): user = token_auth.current_user() # type: UserModel session = self.try_find_session(session_id, user) db.session.delete(session) db.session.commit() return response(status_code=status.HTTP_200_OK, message='Session: {} deleted'.format(session.name))
def patch(self, session_id): user = token_auth.current_user() # type: UserModel session = self.try_find_session(session_id, user) if not session.active(): raise_error_response(status_code=status.HTTP_403_FORBIDDEN, message='session already stopped') session.end = datetime.now() db.session.commit() return response(status_code=status.HTTP_202_ACCEPTED, message='Session stopped'.format(session))
def get(self): user = token_auth.current_user() # type: UserModel body = get_session_request() end_date = dateparser.parse(body.end_date) or date.max start_date = dateparser.parse(body.begin_date) or date.min sessions = db.session.query(SessionModel).join(TaskModel)\ .filter( TaskModel.user_id == user.id, SessionModel.start >= start_date.strftime('%Y-%m-%d'), SessionModel.start <= end_date.strftime('%Y-%m-%d')).all() return response(status_code=status.HTTP_200_OK, data=[s.as_dict() for s in sessions])
def delete(self): user = token_auth.current_user() db.session.delete(user) db.session.commit() return response(status_code=status.HTTP_200_OK, message='User: {} deleted'.format(user.username))
def get(self): user = token_auth.current_user() return response(status_code=status.HTTP_200_OK, data=user.as_dict())
def post(self): usr = basic_auth.current_user() return response(status_code=status.HTTP_202_ACCEPTED, data={TOKEN: encode_token(usr.as_dict())})