Example #1
0
def delete_student(version, student_id):
    """
    Controller for API Function that deletes a student by ID
    @param student_id: student id
    @return: Response and HTTP code
    """

    # API Version 1.X
    if math.floor(version) == 1:

        student = Student.query.filter_by(id=student_id).first()

        if student is None:
            return jsonify(errors.error_object_not_found()), statuscodes.HTTP_NOT_FOUND

        db.session.delete(student)

        try:
            db.session.commit()
        except IntegrityError as ex:
            return jsonify(errors.error_commit_error(ex)), statuscodes.HTTP_INTERNAL_ERROR

        student_schema = StudentSchema()
        result = student_schema.dump(student)
        return jsonify(
            responses.create_single_object_response('success', result.data, "student")), statuscodes.HTTP_OK

    # Unsupported Versions
    else:
        return jsonify(errors.error_incorrect_version(version)), statuscodes.HTTP_VERSION_UNSUPPORTED
Example #2
0
def delete_cake(version, cake_id):
    """
    Controller for API Function that gets a cake by ID
    @param cake_id: cake id
    @return: Response and HTTP code
    """

    # API Version 1.X
    if math.floor(version) == 1:

        cake = Cake.query.filter_by(id=cake_id).first()

        if cake is None:
            return jsonify(
                errors.error_object_not_found()), statuscodes.HTTP_NOT_FOUND

        db.session.delete(cake)

        try:
            db.session.commit()
        except IntegrityError as ex:
            return jsonify(
                errors.error_commit_error(ex)), statuscodes.HTTP_INTERNAL_ERROR

        return jsonify(
            responses.create_single_object_response(
                'success',
                CakeSerializer(cake).data, "cake")), statuscodes.HTTP_OK

    # Unsupported Versions
    else:
        return jsonify(errors.error_incorrect_version(
            version)), statuscodes.HTTP_VERSION_UNSUPPORTED
Example #3
0
def yahoo_weather(version, woeid):
    """
    Controller for API Function that checks the weather from a woeid
    @param woeid: yahoo woeid
    @return: Response and HTTP code
    """

    # API Version 1.X
    if math.floor(version) == 1:

        url = create_api_url_forecastrss(woeid, True)
        http = httplib2.Http()
        response, content = http.request(url)
        parsed_content = xmltodict.parse(content)
        cleaned_parsed_content = parsed_content["rss"][
            "channel"]  # Clean out silly structure from yahoo.
        data_content = filters.filter_nested_dicts_values(
            cleaned_parsed_content, constants.REMOTE_META_KEYS)
        return jsonify(
            responses.create_single_object_response(
                "success", data_content, "weather")), statuscodes.HTTP_OK

    # Unsupported Versions
    else:
        return jsonify(errors.error_incorrect_version(
            version)), statuscodes.HTTP_VERSION_UNSUPPORTED
Example #4
0
def delete_org(version, org_id):
    """
    Controller for API Function that gets an organization by ID
    @param org_id: org id
    @return: Response and HTTP code
    """

    # API Version 1.X
    if math.floor(version) == 1:

        org = Organization.query.filter_by(id=org_id).first()

        if org is None:
            return jsonify(
                errors.error_object_not_found()), statuscodes.HTTP_NOT_FOUND

        db.session.delete(org)

        try:
            db.session.commit()
        except IntegrityError as ex:
            return jsonify(
                errors.error_commit_error(ex)), statuscodes.HTTP_INTERNAL_ERROR

        org_schema = OrganizationSchema()
        result = org_schema.dump(org)
        return jsonify(
            responses.create_single_object_response(
                'success', result.data, "organization")), statuscodes.HTTP_OK

    # Unsupported Versions
    else:
        return jsonify(errors.error_incorrect_version(
            version)), statuscodes.HTTP_VERSION_UNSUPPORTED
Example #5
0
def get_student(version, student_id):
    """
    Controller for API Function that gets a student by ID
    @param student_id: student id
    @return: Response and HTTP cod
    """

    if math.floor(version) == 1:
        student = Student.query.filter_by(id=student_id).first()

        if student is None:
            return jsonify(errors.error_object_not_found(), statuscodes.HTTP_NOT_FOUND)

        student_schema = StudentSchema()
        result = student_schema.dump(student)
        return jsonify(
            responses.create_single_object_response('success', result.data, "student")), statuscodes.HTTP_OK
    else:
        return jsonify(errors.error_incorrect_version(version)), statuscodes.HTTP_VERSION_UNSUPPORTED
def yahoo_weather(version, woeid):
    """
    Controller for API Function that checks the weather from a woeid
    @param woeid: yahoo woeid
    @return: Response and HTTP code
    """

    # API Version 1.X
    if math.floor(version) == 1:

        url = create_api_url_forecastrss(woeid, True)
        http = httplib2.Http()
        response, content = http.request(url)
        parsed_content = xmltodict.parse(content)
        cleaned_parsed_content = parsed_content["rss"]["channel"]  # Clean out silly structure from yahoo.
        data_content = filters.filter_nested_dicts_values(cleaned_parsed_content, constants.REMOTE_META_KEYS)
        return jsonify(
            responses.create_single_object_response("success", data_content, "weather")), statuscodes.HTTP_OK

    # Unsupported Versions
    else:
        return jsonify(errors.error_incorrect_version(version)), statuscodes.HTTP_VERSION_UNSUPPORTED
Example #7
0
def get_organization(version, org_id):
    """
    Controller for API Function that gets a organization by ID
    @param org_id: org id
    @return: Response and HTTP cod
    """

    if math.floor(version) == 1:
        org = Organization.query.filter_by(id=org_id).first()

        if org is None:
            return jsonify(errors.error_object_not_found(),
                           statuscodes.HTTP_NOT_FOUND)

        org_schema = OrganizationSchema()
        result = org_schema.dump(org)
        return jsonify(
            responses.create_single_object_response(
                'success', result.data, "organization")), statuscodes.HTTP_OK
    else:
        return jsonify(errors.error_incorrect_version(
            version)), statuscodes.HTTP_VERSION_UNSUPPORTED
def get_sapa_factor(version, team_id, student_id, self_score_id,
                    team_score_id):
    if math.floor(version) == 1:
        team = Team.query.filter_by(id=team_id).first()
        student = Student.query.filter_by(id=student_id).first()
        self_score = Score.query.filter_by(id=self_score_id).first()
        team_score = Score.query.filter_by(id=team_score_id).first()

        if self_score is None:
            return jsonify(errors.error_object_not_found(),
                           statuscodes.HTTP_NOT_FOUND)
        if team_score is None:
            return jsonify(errors.error_object_not_found(),
                           statuscodes.HTTP_NOT_FOUND)

        score_schema = ScoreSchema()
        result = sapa_factor(self_score=self_score, team_scores=team_score)
        return jsonify(
            responses.create_single_object_response(
                'success', result, "sapa factor")), statuscodes.HTTP_OK
    else:
        return jsonify(errors.error_incorrect_version(
            version)), statuscodes.HTTP_VERSION_UNSUPPORTED