Beispiel #1
0
    def post(self, name):
        if isUnique('name', name, 'groups', db):
            return errors.NoGroup()

        response = db.session.execute("SELECT groupId, name, className, watch, groupHealth, groupScore FROM groups t1 JOIN classes t2 ON t1.classID = t2.classID WHERE name = :n;", {'n':name}).fetchone()

        currVal = response['watch']

        if currVal == 0:
            # Toggle
            db.session.execute("UPDATE groups SET watch = :newVal WHERE name = :n;" , {
                'n' : name,
                'newVal' : 1
            })
            # TODO: Some function that will notifiy this team they are being watched
        else:
            # Toggle
            db.session.execute("UPDATE groups SET watch = :newVal WHERE name = :n;" , {
                'n' : name,
                'newVal' : 0
            })
            # TODO: Some function that will notifiy this they are no longer being watched

        db.session.commit()
        return make_response('',204)
Beispiel #2
0
    def delete(self, uid, name):
        if not uid.isnumeric():
            return errors.NotNumeric()

        if isUnique('uid', uid, 'students', db):
            return errors.NoStudent()
        if isUnique('name', name, 'groups', db):
            return errors.NoGroup()

        student = db.session.execute(
            """SELECT * FROM student_teams WHERE
                                studentId=(SELECT studentId FROM students WHERE uid=:uid) AND
                                groupId=(SELECT groupId FROM groups WHERE name=:n)""",
            {
                'uid': uid,
                "n": name
            }).fetchone()

        if student is None:
            return errors.NoStudent()
        else:
            studentId = student['studentId']

        db.session.execute(
            """DELETE FROM student_teams WHERE
                                studentId=(SELECT studentId FROM students WHERE uid=:uid) AND
                                groupId=(SELECT groupId FROM groups WHERE name=:n)""",
            {
                'uid': uid,
                "n": name
            })

        db.session.commit()

        return make_response('', 204)
Beispiel #3
0
    def get(self, name):
        if isUnique('name', name, 'groups', db):
            return errors.NoGroup()

        response = db.session.execute("SELECT * FROM groups WHERE name = :n;", {'n':name}).fetchone()

        return make_response(jsonify({'result':response['watch']}), 200)
Beispiel #4
0
    def get(self, name):
        if isUnique('name', name, 'groups', db):
            return errors.NoGroup()

        response = db.session.execute(
            "SELECT firstName, lastName, directoryId, uid FROM people INNER JOIN students ON people.personId = students.personID INNER JOIN student_teams ON students.studentId = student_teams.studentId INNER JOIN groups ON student_teams.groupId = groups.groupId WHERE name = :n;",
            {'n': name})
        result = [dict(r) for r in response]
        return make_response(json.dumps(result), 200)
Beispiel #5
0
    def get(self, name, table):
        if table not in groupTablesIgnorePopulate:
            return errors.NoTable()
        if isUnique('name', name, 'groups', db):
            return errors.NoGroup()

        response = db.session.execute('SELECT groupId FROM groups WHERE name = :name;', {'name':name})
        result = [dict(r) for r in response]
        groupId = result[0]['groupId']

        response = db.session.execute('SELECT * FROM {} WHERE groupId = :groupId;'.format(table), {'groupId':groupId})
        if response is None:
            return make_response(jsonify({'result' : ""}), 200)
        return make_response(jsonify([dict(r) for r in response]), 200)
Beispiel #6
0
    def put(self, name):
        if request.json is not None:
            return errors.InvalidBody()
        requiredArgs = ['groupHealth']
        parser = reqparse.RequestParser(bundle_errors=True)
        parser = addToParser(requiredArgs, parser, required = True)
        parser = addToParser(requiredArgs, parser)
        args = parser.parse_args()

        if isUnique('name', name, 'groups', db):
            return errors.NoGroup()

        if not args['groupHealth'].isnumeric() or int(args['groupHealth']) > 3 or int(args['groupHealth']) < 1:
            return errors.InvalidHealth()

        db.session.execute("UPDATE groups SET groupHealth = :newVal WHERE name = :n;" , {'n' : name, 'newVal' : args['groupHealth']})
        db.session.commit()

        return make_response('', 204)
Beispiel #7
0
    def post(self, name):
        if isUnique('name', name, 'groups', db):
            return errors.NoGroup()

        response = db.session.execute('SELECT groupId FROM groups WHERE name = :name;', {'name':name})
        result = [dict(r) for r in response]
        groupId = result[0]['groupId']

        query = ''' LOAD DATA INFILE 'slack.csv'
                    INTO TABLE slackData
                    FIELDS TERMINATED BY ','
                    IGNORE 1 LINES
                    (slackMsgId, channel, user, timestamp)
                    SET groupID=:gid
                ;'''

        db.session.execute(query , {'gid' : groupId})
        db.session.commit()

        return make_response('', 204)
Beispiel #8
0
    def delete(self, directoryId, name):
        if isUnique('directoryId', directoryId, 'people', db):
            return errors.NoPerson()
        if isUnique('name', name, 'groups', db):
            return errors.NoGroup()

        response = db.session.execute(
            'SELECT * FROM people WHERE directoryId = :d;', {'d': directoryId})
        result = [dict(r) for r in response]

        personId = result[0]['personId']

        if isUnique('personId', personId, 'students', db):
            return errors.NoStudent()

        student = db.session.execute(
            """SELECT studentId FROM student_teams WHERE
                                studentId=(SELECT studentId FROM students WHERE personId=(SELECT personId from people WHERE directoryId=:directoryId)) AND
                                groupId=(SELECT groupId FROM groups WHERE name=:n)""",
            {
                'directoryId': directoryId,
                "n": name
            }).fetchone()

        if student is None:
            return errors.NoStudent()
        else:
            studentId = student['studentId']

        db.session.execute(
            """DELETE FROM student_teams WHERE
                                studentId=(SELECT studentId FROM students WHERE personId=(SELECT personId from people WHERE directoryId=:directoryId)) AND
                                groupId=(SELECT groupId FROM groups WHERE name=:n)""",
            {
                'directoryId': directoryId,
                "n": name
            })

        db.session.commit()

        return make_response('', 204)
Beispiel #9
0
    def post(self, directoryId, name):
        if isUnique('directoryId', directoryId, 'people', db):
            return errors.NoPerson()
        if isUnique('name', name, 'groups', db):
            return errors.NoGroup()

        response = db.session.execute(
            'SELECT * FROM people WHERE directoryId = :d;', {'d': directoryId})
        result = [dict(r) for r in response]

        personId = result[0]['personId']
        if isUnique('personId', personId, 'students', db):
            return errors.NoStudent()

        getStudentGroupQuery = '''SELECT * FROM student_teams WHERE
                                    studentId=(SELECT studentId FROM students WHERE personId=(SELECT personId from people WHERE directoryId=:directoryId)) AND
                                    groupId=(SELECT groupId FROM groups WHERE name=:n)
                                '''

        resp = db.session.execute(getStudentGroupQuery, {
            'directoryId': directoryId,
            'n': name
        })
        if [dict(r) for r in resp]:
            return errors.AlreadyGrouped()

        query = """INSERT INTO student_teams (studentId, groupId)
                    SELECT
                        (SELECT studentId FROM students WHERE personId=(SELECT personId from people WHERE directoryId=:directoryId)),
                        (SELECT groupId FROM groups WHERE name=:n);"""

        db.session.execute(query, {'directoryId': directoryId, 'n': name})
        db.session.commit()
        resp = db.session.execute(getStudentGroupQuery, {
            'directoryId': directoryId,
            'n': name
        })
        return make_response(json.dumps([dict(r) for r in resp][0]), 200)
Beispiel #10
0
    def delete(self):
        if request.json is not None:
            return errors.InvalidBody()
         # Delete a class from the classes table
        requiredArgs = ['name']
        parser = reqparse.RequestParser(bundle_errors=True)
        parser = addToParser(requiredArgs, parser, required=True)
        args = parser.parse_args()

        if isUnique('name', args['name'], 'groups', db):
            return errors.NoGroup()

        query = "DELETE FROM slackData WHERE groupId IN (SELECT groupId FROM groups WHERE name = :name);"
        db.session.execute(query, {'name':args['name']})

        query = "DELETE FROM student_teams WHERE groupId IN (SELECT groupId FROM groups WHERE name = :name);"
        db.session.execute(query, {'name':args['name']})

        query= "DELETE FROM groups WHERE name = :name;"
        db.session.execute(query, {'name':args['name']})
        db.session.commit()

        return make_response('', 204)
Beispiel #11
0
    def post(self, uid, name):
        if not uid.isnumeric():
            return errors.NotNumeric()

        if isUnique('uid', uid, 'students', db):
            return errors.NoStudent()
        if isUnique('name', name, 'groups', db):
            return errors.NoGroup()

        # -- If student already part of group -- #
        getStudentGroupQuery = '''SELECT * FROM student_teams WHERE
                                    studentId=(SELECT studentId FROM students WHERE uid=:uid) AND
                                    groupId=(SELECT groupId FROM groups WHERE name=:n)
                                '''
        resp = db.session.execute(getStudentGroupQuery, {
            'uid': uid,
            'n': name
        })

        if [dict(r) for r in resp]:
            return errors.AlreadyGrouped()

        # -- Insert -- #
        query = """INSERT INTO student_teams (studentId, groupId)
                    SELECT
                        (SELECT studentId FROM students WHERE uid=:uid),
                        (SELECT groupId FROM groups WHERE name=:n);"""

        db.session.execute(query, {'uid': uid, 'n': name})

        db.session.commit()
        resp = db.session.execute(getStudentGroupQuery, {
            'uid': uid,
            'n': name
        })
        return make_response(json.dumps([dict(r) for r in resp][0]), 200)