Beispiel #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
Beispiel #2
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}