def post(self, note_id): args = parser.parse_args() title = args['title'] content = args['content'] lecturer = args['lecturer'] link = args['link'] course_id = args['course_id'] course_code = args['course_code'] english = args['english'] term_id = args['term_id'] user_id = get_jwt_identity()['id'] note = Note().where([['id', '=', note_id], ['user_id', '=', user_id]]).first() if note.exists() is False or note.validate() is False: return response({ 'message': 'That note does not exist or it does not belong to you' }, 401) note.update({ 'title': title, 'content': content, 'lecturer': lecturer, 'link': link, 'course_id': course_id, 'course_code': course_code, 'english': english, 'term_id': term_id, 'slug': note.generateSlug(name=title) }) return response({ 'message': 'Note successfully updated!' }, 200)
def post(self): args = parser.parse_args() title = args['title'] content = args['content'] lecturer = args['lecturer'] link = args['link'] course_id = args['course_id'] course_code = args['course_code'] english = args['english'] term_id = args['term_id'] user_id = get_jwt_identity()['id'] note = Note() note.create({ 'title': title, 'content': content, 'lecturer': lecturer, 'link': link, 'course_id': course_id, 'course_code': course_code, 'english': english, 'term_id': term_id, 'user_id': user_id, 'slug': note.generateSlug(name=title) }) if note.validate() is False: return response({ 'errors': note.getErrors() }, 401) user = User().where('id', user_id).first() note.save() return response({ 'note': note.plus('user', user.data()).data() }, 200)