Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
    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']
        })
Example #7
0
 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)
Example #8
0
    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)
Example #9
0
    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)
Example #10
0
    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)
Example #11
0
    def post(self):
        user = User().where('id', 21).first()
        user.update({'email': '[email protected]', 'name': 'Yavuz Koca'})

        return response({'user': user.data()})
Example #12
0
 def get(self):
     users = User().where().orderBy().get()
     return response({
         'users': users.data()
     })
Example #13
0
 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)