Ejemplo n.º 1
0
 def post(self, event_id):
     event = Event().where('id', '=', event_id).first()
     if event.exists():
         event.delete()
         return response({
             'message': 'Event deleted successfully'
         }, 202)
     return response({
         'message': 'Event does not exist'
     }, 404)
Ejemplo n.º 2
0
 def post(self, event_id):
     user_id = get_jwt_identity()['id']
     event = Event().where([['id', '=', event_id],
                            ['user_id', '=', user_id]]).first()
     if event.exists():
         event.delete()
         return response({'message': 'Event deleted successfully'}, 202)
     return response(
         {'message': 'Event does not exist or it is not yours to delete'},
         404)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def post(self, event_id):
        args = parser.parse_args()
        title = args['title']
        description = args['description']
        max_participant = args['max_participant']
        started_at = args['started_at']

        event = Event().where('id', '=', event_id).first()

        if event.exists() is False:
            return response({
                'message': 'That event does not exist'
            }, 401)
        event.update({
            'title': title,
            'description': description,
            'max_participant': max_participant,
            'started_at': started_at
        })
        return response({
            'message': 'Event successfully updated!'
        }, 200)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 def post(self, user_id):
     user = User().where('id', '=', user_id).first()
     print(user_id, file=sys.stderr)
     if user.exists():
         Comment().where('user_id', user_id).get().delete()
         Event().where('user_id', user_id).get().delete()
         GradeDistribution().where('user_id', user_id).get().delete()
         lecturers = Lecturer().where('user_id', user_id).get()
         for lecturer in lecturers.data():
             Comment().where([['type', '=', 'lecturers'], ['type_id', '=', lecturer['id']]]).get().delete()
             GradeDistribution().where('lecturer_id', '=', lecturer['id']).get().delete()
         lecturers.delete()
         notes = Note().where('user_id', user_id).get()
         for note in notes.data():
             Comment().where([['type', '=', 'notes'], ['type_id', '=', note['id']]]).get().delete()
         notes.delete()
         user.delete()
         return response({
             'message': 'User deleted successfully'
         }, 202)
     return response({
         'message': 'User does not exist'
     }, 404)
Ejemplo n.º 7
0
    def post(self, event_id):
        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().where([['id', '=', event_id],
                               ['user_id', '=', user_id]]).first()

        if event.exists() is False or event.validate() is False:
            return response(
                {
                    'message':
                    'That event does not exist or it does not belong to you'
                }, 401)
        event.update({
            'title': title,
            'description': description,
            'max_participant': max_participant,
            'started_at': started_at
        })
        return response({'message': 'Event successfully updated!'}, 200)
Ejemplo n.º 8
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)