Ejemplo n.º 1
0
def join_event(**options):
    db = DB()
    user_id, status, error = db.auth(options['username'], options['password'])
    if status:
        return response_error(status, error)

    participants, status, error = db.get_event_participants(options['event_id'])
    if status:
        return response_error(status, error)

    event_info, status, error = db.get_event_info(options['event_id'])
    if status:
        return response_error(status, error)

    if options['username'] in participants:
        return response_error(1, 'you are already registered')

    if len(participants) == event_info['participants_number_max']:
        return response_error(1, 'event is full')

    status, error = db.join_event(user_id, options['event_id'])
    if status:
        return response_error(status, error)

    return response_ok()
Ejemplo n.º 2
0
def get_event(**options):
    db = DB()
    event_info, status, error = db.get_event_info(options['event_id'])
    if status:
        return response_error(status, error)

    # dt = datetime.strptime(event_info['timestamp'], '%Y-%m-%d %H:%M:%S')
    dt = event_info['timestamp']
    event_info['timestamp'] = int(dt.timestamp())

    participants, status, error = db.get_event_participants(options['event_id'])
    if status:
        return response_error(status, error)

    return response_ok({'event_info': event_info, 'participants': participants})