def post(self): args = parser.parse_args() user_id = get_jwt_identity()['id'] # Check if passwords are the same if args['password'] is not None and args['passwordConfirm'] != args[ 'password']: return response( {'errors': ['Password and Confirm Password must be same']}, 400) # Check if the email is already taken or not email = args['email'] user = User().where('email', email).first() if user.exists() and user.ATTRIBUTES['id'] != user_id: return response({'errors': ['This email is already taken']}, 400) # Update user user = User().where('id', '=', user_id).first() if user.exists() is True: user.update({ 'name': args['name'], 'email': args['email'], 'slug': user.generateSlug(name=args['name']), 'password': bcrypt.generate_password_hash(args['password']).decode('utf-8') }) return response({'user': user.data()}) return response({'errors': ['User could not found']}, 404)
def get(self): events = Event().where().orderBy().get().data() for event in events: user = User().where('id', event['user_id']).first() event['user'] = user.data() return response({'events': events}, 200)
def post(self, user_id): args = parser.parse_args() # Check if the email is already taken or not email = args['email'] user = User().where('email', email).first() if user.exists() and user.ATTRIBUTES['id'] != user_id: return response({ 'errors': 'This email is already taken' }, 400) # Update user user = User().where('id', '=', user_id).first() if user.exists() is True: user.update({ 'name': args['name'], 'email': args['email'], 'slug': user.generateSlug(name=args['name']), }) return response({ 'user': user.data() }) return response({ 'errors': [ 'User could not found' ] }, 404)
def get(self, type_id): comments = Comment().where([['type', '=', 'notes'], ['type_id', '=', type_id]]).orderBy().get().data() for comment in comments: user = User().where('id', comment['user_id']).first() comment['user'] = user.data() return response({'comments': comments}, 200)
def get(self): notes = Note().where().orderBy().get().data() for note in notes: user = User().where('id', note['user_id']).first() note['user'] = user.data() return response({ 'notes': notes }, 200)
def get(self, slug): user = User().where('slug', slug).first() if user.exists() is True: return response({ 'user': user.data() }) return response({ 'errors': ['User could not found'] })
def get(self, note_slug): note = Note().where('slug', note_slug).first().data() user = User().where('id', note['user_id']).first() note['user'] = user.data() comments = Comment().where([['type', '=', 'notes'], ['type_id', '=', note['id']]]).get() for comment in comments.data(): comment['user'] = User().where('id', comment['user_id']).first().data() note['comments'] = comments.data() return response({ 'notes': note }, 200)
def post(self, type_id): args = parser.parse_args() type = 'notes' type_id = type_id commentText = args['comment'] user_id = get_jwt_identity()['id'] comment = Comment() comment.create({ 'type': type, 'type_id': type_id, 'comment': commentText, 'user_id': user_id }) if comment.validate() is False: return response({'errors': comment.getErrors()}, 401) user = User().where('id', user_id).first() comment.save() return response({'comment': comment.plus('user', user.data()).data()}, 200)
def post(self): args = parser.parse_args() title = args['title'] description = args['description'] max_participant = args['max_participant'] started_at = args['started_at'] user_id = get_jwt_identity()['id'] event = Event() event.create({ 'title': title, 'description': description, 'max_participant': max_participant, 'started_at': started_at, 'user_id': user_id }) if event.validate() is False: return response({'errors': event.getErrors()}, 401) user = User().where('id', user_id).first() event.save() return response({'event': event.plus('user', user.data()).data()}, 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)
def post(self): user = User().where('id', 21).first() user.update({'email': '[email protected]', 'name': 'Yavuz Koca'}) return response({'user': user.data()})
def get(self): users = User().where().orderBy().get() return response({ 'users': users.data() })
def get(self, event_id): event = Event().where('id', event_id).first().data() user = User().where('id', event['user_id']).first() event['user'] = user.data() return response({'event': event}, 200)