Пример #1
0
 def get(self):
     return {
         'tasks': [
             task.json() for task in TaskModel.find_by_user_id(
                 current_identity.first().id).all()
         ]
     }
Пример #2
0
 def get(self):
     return {
         'appointments': [
             appoint.json() for appoint in AppointmentModel.find_by_user_id(
                 current_identity.first().id).all()
         ]
     }
Пример #3
0
    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'}
Пример #4
0
    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'}
Пример #5
0
    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()
Пример #6
0
    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()
Пример #7
0
    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
Пример #8
0
    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
Пример #9
0
    def get(self):
        user = current_identity.first()
        if user is None:
            return {'user': None}

        return {'user': {'name': user.name, 'username': user.username}}