def get(self): return { 'tasks': [ task.json() for task in TaskModel.find_by_user_id( current_identity.first().id).all() ] }
def get(self): return { 'appointments': [ appoint.json() for appoint in AppointmentModel.find_by_user_id( current_identity.first().id).all() ] }
def delete(self): data = Appointment.parser.parse_args() appointment = AppointmentModel.find_by_app_id_and_user_id( data['id'], current_identity.first().id).first() if appointment is not None: appointment.delete_from_db() return {'message': 'appointment is deleted'}
def delete(self): data = Task.parser.parse_args() task = TaskModel.find_by_task_id_and_user_id( data['id'], current_identity.first().id).first() if task is not None: task.delete_from_db() return {'message': 'task is deleted'}
def put(self): data = Appointment.parser.parse_args() appoint = AppointmentModel.find_by_app_id_and_user_id( data['id'], current_identity.first().id).first() if 'name' not in data or 'description' not in data or 'start' not in data or 'end' not in data: return {'message': 'invalid json sent in body'}, 400 if appoint is None: appoint = AppointmentModel(data['name'], data['description'], data['start'], data['end'], current_identity.first().id) else: appoint.update(data['name'], data['description'], data['start'], data['end']) try: appoint.save_to_db() except: return {'message': 'error occurred while saving appointment'}, 500 return appoint.json()
def put(self): data = Task.parser.parse_args() task = TaskModel.find_by_task_id_and_user_id( data['id'], current_identity.first().id).first() if 'name' not in data or 'description' not in data or 'deadline' not in data or 'done' not in data: return {'message': 'invalid json sent in body'}, 400 if task is None: task = TaskModel(data['name'], data['description'], data['deadline'], current_identity.first().id) task.done = data['done'] else: task.update(data['name'], data['description'], data['deadline'], data['done']) try: task.save_to_db() except: return {'message': 'error occurred while saving task'}, 500 return task.json()
def post(self): data = Task.parser.parse_args() if 'name' not in data or 'description' not in data or 'deadline' not in data: return {'message': 'invalid json sent in body'}, 400 task = TaskModel(data['name'], data['description'], data['deadline'], current_identity.first().id) try: task.save_to_db() except: return {'message': 'error occurred while inserting task'}, 500 return task.json(), 201
def post(self): data = Appointment.parser.parse_args() logging.debug('name is in is {}'.format('name' in data)) if ('name' not in data) or ('description' not in data) or ( 'start' not in data) or ('end' not in data): return {'message': 'invalid json sent in body'}, 400 appoint = AppointmentModel(data['name'], data['description'], data['start'], data['end'], current_identity.first().id) try: appoint.save_to_db() except: return { 'message': 'error occurred while inserting appointment' }, 500 return appoint.json(), 201
def get(self): user = current_identity.first() if user is None: return {'user': None} return {'user': {'name': user.name, 'username': user.username}}