示例#1
0
def update_note(notebook_id, note_id):
    '''
    This endpoint updates note
    '''
    try:

        # get json request data
        json_data =  request.get_json()

        print json_data

        # gets note from notebook
        note = Note.query.filter(Note.notebook_id==notebook_id, Note.id==note_id).first()

        # if note is not found
        if note is None:
            return jsonify({'message': 'Note could not be found.'}), 400
        else:

            # update note
            note.title   = json_data['title']
            note.content = json_data['content']
            note.color   = json_data['color']

            db.session.commit()

             # serialize sqlalchemy data
            serializer =  NoteSchema()
            result = serializer.dump(note)

            # return json result
            return jsonify({'note': result.data})
    except Exception:
        # return json result
        return jsonify({'status' : 'error while update content of note'}), 400
示例#2
0
def create_new_note(notebook_id):
    '''
    This endpoint creates a new note in a notebook
    '''
    try:
        # get json request data
        json_data =  request.get_json()

        # get notebook
        notebook = Notebook.query.get(notebook_id)

        # create new note
        new_note = Note(json_data['title'], json_data['content'], 'red', notebook)

        # store new note into dbase
        db.session.add(new_note)
        db.session.commit()

         # serialize sqlalchemy data
        serializer =  NoteSchema()
        result = serializer.dump(new_note)

        # return json result
        return jsonify({'note' : result.data})
    except Exception as ex:
        print ex
        # return json result
        return jsonify({'status' : 'error while creating a new note'}), 400
示例#3
0
def list_notes_notebook(notebook_id):
    '''
    This endpoint returns all notes within a notebook
    '''
    try:
        # gets all notes from notebook
        notes = Note.query.filter(Note.notebook_id==notebook_id).order_by(Note.title)

        # serialize sqlalchemy data
        serializer = NoteSchema(many=True)
        result = serializer.dump(notes)

        # return json result
        return jsonify({'notes': result.data})
    except Exception:
        # return json result
        return jsonify({'status' : 'error while listing notes'}), 400
示例#4
0
def get_note(notebook_id, note_id):
    '''
    This endpoint gets the note information
    '''
    try:
        # gets  note from notebook
        note = Note.query.filter(Note.notebook_id==notebook_id, Note.id==note_id).first()

        # if note is not found
        if note is None:
            return jsonify({'message': 'Note could not be found.'}), 400
        else:
             # serialize sqlalchemy data
            serializer =  NoteSchema()
            result = serializer.dump(note)

            # return json result
            return jsonify({'note': result.data})
    except Exception:
        # return json result
        return jsonify({'status' : 'error while getting content of note'}), 400