Example #1
0
 def delete(self, note_id):
     '''Remove a note for a certain book'''
     note = NoteModel.find_by_id(note_id)
     if not note:
         return {'message': 'no note found in this id'}, 404
     NoteModel.delete_from_db(note)
     return {'message': 'note {} has been removed.'.format(note_id)}, 200
Example #2
0
    def put(self, title):

        note = NoteModel.filter_by_title(title)
        data = Note.parser.parse_args()
        author = AuthorModel.filter_by_name(data['author'])

        if author is None:
            return {'message': 'This author is not registered yet'}, 404

        if note is None:
            note = NoteModel(title, **data)
        else:
            Note.parser.add_argument('new_title', dest='title')
            data = Note.parser.parse_args()
            note.title = data['title']
            note.author_id = author.id
            note.note = data['note']
            note.updated_date = datetime.datetime.now()

        try:
            note.save_to_db()
        except Exception:
            return {'message': 'can not save the note'}, 500

        return note.json(), 200
Example #3
0
    def post(self):
        data = parser.parse_args()
        note = NoteModel(**data)

        try:
            note.save_to_db()
        except:
            return {"message": "An error occurred saving the item."}, 500

        return note.json(), 201
Example #4
0
    def post(self):
        data = NoteList.parser.parse_args()
        y, m, d = data['date_created'].split('-')
        note = NoteModel(data['title'], data['article_text'],
                         datetime.datetime(int(y), int(m), int(d)),
                         data['project_id'])

        try:
            note.save_to_db()
        except:
            return {'message': 'An error occured inserting the note'}, 500

        return note.json(), 201
Example #5
0
 def put(self, note_id, new_content):
     '''Update a note for a certain book'''
     try:
         note = NoteModel.update_note(note_id, new_content)
     except Exception as e:
         return {'message': 'no note found in this id'}, 404
     return note.json(), 200
Example #6
0
 def get(self, book_id):
     '''Get the notes for a certain book'''
     try:
         notes = NoteModel.get_all_notes_for_book(book_id)
     except Exception as e:
         return {'message': 'no book found in this id'}, 404
     return [note.json() for note in notes], 200
Example #7
0
 def post(self, book_id, content):
     '''Add a note to a certain book'''
     try:
         note = NoteModel.create_note_for_book(book_id, content)
     except Exception as e:
         return {'message': 'no book found in this id'}, 404
     return note.json(), 201
Example #8
0
    def put(self, note_id):
        data = parser.parse_args()
        note = NoteModel.find_by_note_id(note_id)

        if note is None:
            note = NoteModel(**data)
        else:
            note.title = data["title"]
            note.note = data["note"]
            note.priority = data["priority"]
            note.updated_at = data["updated_at"]

        try:
            note.save_to_db()
        except:
            return {"message": "An error occurred saving the item."}, 500

        return note.json()
Example #9
0
    def post(self, title):
        if NoteModel.filter_by_title(title):
            return {"message": "note with that title already exists"}, 409

        data = Note.parser.parse_args()
        author = AuthorModel.filter_by_name(data['author'])

        if author.id is None:
            return {'message': 'This author is not registered yet'}, 404

        note = NoteModel(title, author.id, data['note'])

        try:
            note.save_to_db()
        except Exception:
            return {'message': 'can not save the note'}, 500

        return note.json(), 201
Example #10
0
    def post(self, username):
        user = UserModel.find_by_username(username)
        my_dict = user.item_json()
        data = sync_parser.parse_args()

        client_note_list = data["notes"]
        server_note_list = my_dict["notes"]

        client_note_id_list = [x["note_id"] for x in client_note_list]
        server_note_id_list = [x["note_id"] for x in server_note_list]

        a = set(client_note_id_list)
        b = set(server_note_id_list)

        add_list = [x for x in client_note_list if x["note_id"] not in b]
        delete_list = [x for x in server_note_list if x["note_id"] not in a]
        intersection_list = [x for x in client_note_list if x["note_id"] in b]

        for add_note in add_list:
            note = NoteModel(**add_note)
            note.save_to_db()

        for delete_note in delete_list:
            note = NoteModel.find_by_note_id(delete_note["note_id"])
            note.delete_from_db()

        for intersection_note in intersection_list:
            note = NoteModel.find_by_note_id(intersection_note["note_id"])
            note.title = intersection_note["title"]
            note.note = intersection_note["note"]
            note.priority = intersection_note["priority"]
            note.updated_at = intersection_note["updated_at"]


        return {"notes": add_list}
Example #11
0
    def delete(self, note_id):
        note = NoteModel.find_by_note_id(note_id)
        if note:
            note.delete_from_db()

        return {"message": "note deleted"}
Example #12
0
 def get(self, note_id):
     note = NoteModel.find_by_note_id(note_id)
     if note:
         return note.json()
     return {"message": "note not found"}, 404
Example #13
0
    def delete(self, title):
        note = NoteModel.filter_by_title(title)
        if note:
            note.delete_from_db()

        return {"message": "Note:{} was deleted".format(title)}, 200